Claude Code

Claude Code token usage report

Build a Claude Code token usage report from local JSONL logs: input, output, cache read, cache write, and cost per session.

Quick answer

Claude Code writes a JSONL log per session under `~/.claude/projects`, containing message records with input, output, cache read, and cache write tokens. A usage report groups those records by session, model, and day. UsageAtlas builds the report locally and shows 7, 30, or 90-day ranges.

The fields that matter

FieldMeaningWhy
input_tokensFresh contextMain cost driver
cache_read_input_tokensCached context reusedDiscount
cache_creation_input_tokensContext written to cacheFirst-turn cost
output_tokensGenerated tokensAnswer size
modelModel IDPer-model split
sessionIdSession groupingPer-task cost

Build the report

  1. Locate the project folder under ~/.claude/projects.
  2. Parse each JSONL line and keep assistant message records.
  3. Sum the four token fields per session.
  4. Group by day and model.
  5. Apply current rates only if you need a cost figure.
ls ~/.claude/projects
# each directory maps to a project path
head -n 1 ~/.claude/projects/<project>/<session>.jsonl

Caveats

  • Logs are per machine; other devices are not included.
  • Deleted sessions disappear from the report.
  • Cost is an estimate unless the log records it.
  • Cache fields are absent in older logs.

UsageAtlas handles the parsing and keeps the raw files untouched.

Produce a token report

  1. Collect the local session files for the period.
  2. Sum input, cached input, output, and cache-write tokens separately.
  3. Group by day and by model.
  4. Apply current rates to get an estimated cost.
  5. State the period and the source in the report header.
total = input + cache_read + cache_write + output\ncost = sum(tokens * rate_for_type)

Keep cached tokens separate or the report will overstate cost badly. The cache read guide explains the rate, and UsageAtlas produces the same breakdown from the same files.

Questions, answered

Where does Claude Code store token data?

In JSONL session logs under ~/.claude/projects, with an alternate location under ~/.config/claude/projects on some installs.

Does Claude Code report cost?

It can show a session cost estimate with the cost command. Historic logs contain tokens, so cost is usually recomputed.

Can I export the report?

Yes, as CSV from a script or a tracker. The export guide covers the column set.

Browse by topic