Skip to content

cost

Token usage and approximate cost, aggregated per project or per session.

Usage

bash
claudex cost [-p/--project <substr>] [--per-session]
             [-l/--limit <n>] [--json] [--no-index]

Flags

FlagDefaultDescription
-p, --project <substr>Filter by substring match on the project path.
--per-sessionoffBreak down per session instead of aggregating by project.
-l, --limit <n>20Maximum number of rows.
--jsonoffEmit JSON.
--no-indexoffScan JSONL files directly.

Example

bash
# Top 10 projects by cost
claudex cost --limit 10

# Per-session breakdown for one project
claudex cost --project claudex --per-session --limit 20

# Total cost across everything, as a single number
claudex cost --json --limit 1000 | jq '[.[].cost_usd] | add'

Columns (aggregated)

ColumnSource
ProjectDecoded project name.
SessionsNumber of sessions counted.
InputTotal input tokens.
OutputTotal output tokens.
Cache WriteCache-write tokens.
Cache ReadCache-read tokens.
Model(s)Model families seen (Opus/Sonnet/Haiku).
Cost (USD)Sum of per-message costs.

Columns (per-session)

ColumnSource
ProjectDecoded project name.
Session8-character session ID prefix.
DateFirst timestamp.
Model(s)One model family, or Mixed.
InputInput tokens for the session.
OutputOutput tokens for the session.
Cache WriteCache-write tokens.
Cache ReadCache-read tokens.
Cost (USD)Cost for the session.

JSON shape

Aggregated (default)

json
[
  {
    "project": "/Users/you/projects/claudex",
    "sessions": 123,
    "input_tokens": 326297,
    "output_tokens": 6679149,
    "cache_creation_tokens": 80583078,
    "cache_read_tokens": 7157509259,
    "avg_cost_per_session_usd": 103.54,
    "models": ["Opus", "Sonnet"],
    "cost_usd": 12735.6563118
  }
]

Note: models is an array of model-family names (Opus / Sonnet / Haiku) for any model that contributed to the project's cost. Sorted by cost_usd descending.

Per-session (--per-session)

json
[
  {
    "project": "/Users/you/projects/claudex",
    "session_id": "f69d4985-f914-4968-81c0-009ea004fbc5",
    "date": "2026-04-01T16:36:41.451+00:00",
    "model": null,
    "models": ["claude-opus-4-6", "claude-sonnet-4-6"],
    "input_tokens": 34960,
    "output_tokens": 483151,
    "cache_creation_tokens": 4027298,
    "cache_read_tokens": 893758965,
    "cost_usd": 1452.91101
  }
]

model is populated only when the session used exactly one model. Mixed-model sessions expose their full set under models.

Notes

  • Per-message pricing. Each message is priced by its own model. A session that mixes Opus and Sonnet messages is priced correctly.
  • Cache reads dominate long sessions. Don't be surprised to see huge cache_read_tokens — prompt caching means the same context is read from cache repeatedly.
  • Sub-cent values. Costs below one cent render with four decimals so they don't round to $0.00.
  • See also: Pricing model, models.

Released under the MIT License.