cost-report — Claude Code¶
Analyze historical Claude Code usage from local transcripts — spend by model, most expensive sessions, and sessions where a cheaper model would have sufficed. Use when the user asks what they've spent, which model they've been using, or where they could save.
- Source: skills/cost-report/SKILL.md
- Also available on: this harness only — see the parity matrix
In practice¶
What it does¶
Walks your local Claude Code transcripts and turns raw usage into a spend report: total cost over a window, which model dominated it, and — the part worth acting on — sessions where a cheaper model would plainly have sufficed. It reads only what's already on disk; nothing is sent anywhere and nothing is dispatched.
When to reach for it¶
- You want to know what you've actually spent, not what you assume you spent.
- Deciding whether your daily-driver default is costing more than the work needs.
- Comparing a period after a routing change against one before it.
- Not a live estimate for a task you haven't run yet — that's route; this only reads history.
Worked example¶
python3 bin/cost_report.py --days 30
Read it top to bottom: a headline total and dominant model, a by-model table, then
downgrade-candidate sessions — small-footprint runs on Fable or Opus that a lighter model
likely would have handled — ending on one recommendation drawn from what the data actually
shows. The framing of that delta depends on billing mode: in api mode it's savings; in
subscription mode the same number is rate-limit burn share, never money spent. Add
--mode api|subscription to force a framing, --top N for more or fewer sessions listed,
--json for the payload instead of markdown, and --projects-dir DIR to point the walk at
a non-default transcript directory.
Failure modes & fallbacks¶
- An empty report on a fresh machine. A present-but-empty transcript directory still
renders the full report labeled
no transcripts in window: <dir>— a zero-row report is honest output, not a broken tool, and its zeros are not measured spend. - A missing transcript directory entirely prints
No transcript directory at <path>and renders nothing — a distinct, more specific outcome than the empty case above. - An unexpected transcript format. The script surfaces the error and the file it choked on rather than silently skipping it — relay both, don't paper over either.
Cost & safety¶
Reading transcripts is free and read-only; nothing is dispatched and nothing is written.
Every dollar is priced from
data/pricing.json
at run time, including any dated intro-pricing window the file defines — never a number
hardcoded here.
Related¶
- route — the forward-looking sibling: estimate a task before running it.
- execute — its own scorecard covers dollars for one kit run instead of a rolling window.
- Deep dive: how it works — the billing-mode framing this report's two readings come from.
The skill card — what the model reads¶
This is the SKILL.md body the model reads, transformed for this page: the source's own leading title, if it had one, is removed; every remaining heading is demoted one level to nest under this section; and relative links are rewritten to site or GitHub URLs. ${CLAUDE_PLUGIN_ROOT} and {{POLYTROPOS_ROOT}} are install-time path variables, left intact exactly as the model sees them. The unmodified original is skills/cost-report/SKILL.md.
Run the analyzer script that ships with this plugin. Use the ${CLAUDE_PLUGIN_ROOT} env var
Claude Code sets for plugin-executed content; if it is unset, fall back to resolving
../../bin/cost_report.py relative to this SKILL.md to an absolute path:
python3 "${CLAUDE_PLUGIN_ROOT}/bin/cost_report.py" --days 30
Flags:
- --days N — lookback window (default 30)
- --mode api|subscription — framing (default: billing_mode from ${CLAUDE_PLUGIN_ROOT}/data/pricing.json)
- --top N — how many top sessions to list (default 10)
- --json — print the report payload as JSON instead of markdown
- --projects-dir DIR — point the walk at a non-default transcript directory (the only way to run this against anything but the live ~/.claude/projects)
The script walks ~/.claude/projects/**/*.jsonl, extracts per-message model + usage (input/output/cache tokens), dedupes by message id, and prices everything from data/pricing.json (any intro_pricing window a row carries is applied by date).
Presenting the results¶
The script emits markdown. Summarize it for the user rather than dumping raw output:
- Headline: total API-equivalent cost over the window and which model dominated.
- By-model table: as emitted.
- Downgrade candidates (sessions on Fable/Opus with a small footprint — under ~50K tokens and few tool calls):
- In
apimode: present the dollar delta as savings ("these sessions would have cost $X.XX less on the Sonnet tier"). - In
subscriptionmode: present it as burn share ("these sessions spent rate-limit budget on Fable for Sonnet-sized work") — dollars are API-equivalent, not spend. - One actionable recommendation, e.g. a default-model or effort-level change, based on what the data shows.
If the script errors on unexpected transcript formats, show the error and the file it choked on — don't silently skip everything.
Two no-data outcomes are distinct, not both "broken": a missing projects directory exits
with No transcript directory at <path> and renders nothing; a present-but-empty directory
still renders the full report with a no transcripts in window: <dir> label — a zero-row report
is honest output, not a failure. Don't tell the user the tool is broken on either outcome, and
don't present the empty case's zeros as measured spend.