A tiny, dependency-free localhost dashboard that shows the usage object from every
Claude Code turn — live, as you type.
Point it at a session transcript and it renders one card per API call: fresh input tokens, cache writes, cache reads, output tokens, per-turn cost, and the raw JSON.
python3 usage_watch.py ~/.claude/projects/<project>/<session>.jsonl 8791
# → http://127.0.0.1:8791Stdlib only. No pip install, no hooks, no config changes. It reads one file and serves one page. Kill the process and every trace is gone.
Claude Code writes a JSONL transcript for every session, and each assistant turn carries the billing record the API returned. It's all there — but buried, duplicated across content blocks, and mixed in with UI bookkeeping. This surfaces just the part that tells you what a conversation actually costs.
~/.claude/projects/
└── -Users-you-some-project/ # your cwd, "/" replaced with "-"
├── <session-uuid>.jsonl # the transcript
└── <session-uuid>/
└── subagents/*.jsonl # spawned agents get their own files
Only records with type == "assistant" carry usage, at .message.usage. Everything
else — attachment, mode, last-prompt, file-history-snapshot, system — is
local state with no billing data.
There is no type: "usage" record. That's the thing that trips people up.
# every usage object in a session
jq 'select(.type=="assistant") | .message.usage' <transcript>.jsonlRecords repeat once per content block, so dedupe by .message.id or you'll
double-count.
The API is stateless. Every message re-sends the entire conversation — system prompt, tool schemas, all prior turns. Prompt caching is what makes that affordable, and these fields describe how each slice of the prompt got billed.
| Field | What it is | Rate |
|---|---|---|
input_tokens |
Prompt tokens processed fresh | 1× |
cache_creation_input_tokens |
Tokens written into cache | 2× (1h TTL) / 1.25× (5m) |
cache_read_input_tokens |
Tokens served from cache | 0.1× |
output_tokens |
What the model generated | 5× the input rate |
Your real prompt size is the sum of the first three. input_tokens alone is only
the uncached remainder — it routinely reads as single digits on a 200k-token prompt.
Caching is a prefix match. The server compares your prompt to what it saved, starting at token one, and stops at the first differing byte. Everything before that is a cheap read; everything after must be reprocessed and rewritten at 2×.
Two consecutive turns from a real session — "hello" then "bop":
| turn | fresh | write | read | out | cost |
|---|---|---|---|---|---|
| 1 | 2 | 16,361 | 20,801 | 13 | $0.174 |
| 2 | 2 | 17 | 37,162 | 40 | $0.020 |
Note 20,801 + 16,361 = 37,162. Turn 2's cache read is exactly what turn 1 read plus
what it wrote. The write became a read — which is why turn 2 cost 9× less despite
sending a larger prompt.
Also note turn 1 read 20,801 tokens on the very first message of a brand-new session. Cache entries are keyed by content, not by session — an earlier session had already processed that identical prefix, and it was still within TTL.
The pattern to watch for: small write + steadily growing read means caching is
working. A sudden write spike means something changed near the front of the prompt
and invalidated everything behind it. Those spikes are where the money goes.
Defaults to Claude Opus 5 list rates ($5/M input, $25/M output) with multipliers applied
per field. It reads the nested cache_creation.ephemeral_{1h,5m}_input_tokens split so
the two TTLs bill correctly — a flat cache_creation_input_tokens can't distinguish
2× from 1.25×.
Edit BASE_IN / BASE_OUT at the top of the script for other models.
Estimates only — not a billing source of truth.
Instead of a fixed path, pass auto to track whichever transcript was written most
recently, with an optional comma-separated exclude list of session-id fragments:
python3 usage_watch.py auto 8791 5ba1235cUseful when you don't know which session you'll be typing in — but exclude the window you're using to run the tool, or it'll just watch itself.
- Binds to
127.0.0.1only. - Read-only. Never writes to
~/.claude. - Polls every 1.5s; new turns appear automatically and flash once.
- Subagents write to a separate
subagents/directory, so a parent session's totals exclude any agents it spawned. Walk that directory too if you want true totals.
MIT