Skip to content

About

Where did my Claude Code tokens go? Offline audit of local transcripts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

token-ledger

Where did my Claude Code tokens actually go?

token-ledger reads the session transcripts Claude Code already keeps on your machine (~/.claude/projects/**/*.jsonl) and builds a ledger: what each session cost at API list prices, and which tool results, files, harness context and model output used that money.

It uses only the Python standard library, makes no network calls and writes nothing outside the report path you choose. Your transcripts never leave your machine.

Why "lifetime cost"

Every request re-sends the whole conversation. A 12K-token Bash output isn't paid for once. It's paid for again, usually as a cache read, on every later turn until a compaction clears it. So token-ledger charges each item for its whole lifetime:

cost of request k  →  spread over everything resident in the context at request k,
                      in proportion to its size

Summed over a session, those per-item costs add up exactly to the session's total cost. The tests check this.

Usage

python -m token_ledger report                      # terminal report
python -m token_ledger report --html ledger.html   # plus a charted HTML page
python -m token_ledger report --since 2026-10-01 --project my-app
python -m token_ledger report --no-subagents
python -m token_ledger report --json > ledger.json # everything, machine-readable
python -m token_ledger report --redact --html share.html  # tool names only, safe to screenshot

Or pip install -e . to get a token-ledger command.

What it reports

Question How
What did each session cost, and on what? usage on every API request: uncached input, 5m/1h cache writes, cache reads, output
What filled the context? Context growth between requests, split across the tool results, prompts and attachments appended in between
Which single tool results were most expensive? Size × number of turns carried
How much do subagents cost compared with the main thread? Transcripts under <session>/subagents/
When did the cache break? A request that rewrote most of a large cached prefix, with the idle gap before it
How much is fixed overhead? The first request's prompt: system prompt, tool definitions, skill and agent listings
Where did compaction happen? compact_boundary entries, with tokens before and after

Example: my last 4 weeks

From my own logs (Oct 8 to Nov 3, 2026, all on Claude Opus 5.5): 4 sessions, 6 subagents and 954 API requests, $81.81 at API list prices.

  • 199 tokens read for every token written. Output was 22% of cost. The other 78% was re-sending context.
  • 97% cache hit rate, but cache writes were still 36% of the cost. 11 cache breaks account for about $14. Most came from one moment: resuming a 6-subagent research session after ~10 hours away. All 7 contexts rewrote ~1.15M tokens of expired cache (about $9) at the same time.
  • Tool results were the largest category, at 37%. Bash alone was 22% of all spend across 610 calls. One 6K-token process listing was carried for 223 turns.
  • The six subagents cost $30, compared with $22 for the main thread that started them.
  • About 30K tokens of baseline (system prompt, tools, skills) before typing anything.

Limits, stated plainly

  • Costs are API-equivalent estimates, not a bill. Subscription plans aren't charged per token. Prices are in token_ledger/price.py. Check them against Anthropic's pricing page.
  • Attribution is approximate. It splits growth by character count, and the harness injects text that doesn't appear in the transcript.
  • The transcript format is undocumented and changes between Claude Code versions. The parser skips unknown or malformed entries instead of failing.
  • History is short by default. Claude Code deletes transcripts after cleanupPeriodDays (default 30). To keep more, set it higher in ~/.claude/settings.json: { "cleanupPeriodDays": 365 }.

Tests

python -m unittest -v

The tests use synthetic transcripts (tests/make_fixture.py). Never commit real ones.

License

MIT

About

Where did my Claude Code tokens go? Offline audit of local transcripts.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages