Claude Code token usage: what counts and how to measure it

What counts toward Claude Code token usage (input, output, cache reads and writes), where it's logged, and scripts to add it up by day, model and project.

· 7 min read

"How many tokens did I use today?" sounds like a simple question, and Claude Code doesn't answer it in one place. /usage shows the current session and plan bars, your plan page shows percentages, and neither tells you which project or which habit ate the most. The full answer is on your disk: every request Claude Code makes is logged with its token counts. Once you know what the counters mean and how to add them up without counting twice, you can answer any usage question in a few seconds.

#What counts as a token in Claude Code?

Everything sent to the model and everything it sends back. That's more than your prompts:

  • Sent every request: the system prompt, the tool definitions (MCP servers included), your CLAUDE.md files, the whole conversation so far, every file Claude read and every command output.
  • Sent back: Claude's replies, its tool calls, and its thinking.

The key fact is that Claude Code re-sends the conversation with every request, and one prompt from you can trigger dozens of requests, one per tool call. Usage grows with the length of the conversation times the number of requests in it.

Each request is reported in four counters:

CounterWhat it is
input_tokensNew input that wasn't read from the prompt cache
cache_creation_input_tokensInput written to the prompt cache for the next requests
cache_read_input_tokensInput read back from the prompt cache
output_tokensEverything generated, thinking included

Prompt caching is why the first three exist. The start of the conversation doesn't change between requests, so it's stored once (a cache write) and read back cheaply afterwards (cache reads). Only the new part at the end is plain input.

#Where does Claude Code record token usage?

In the session transcripts:

~/.claude/projects/<project>/<session-id>.jsonl
~/.claude/projects/<project>/<session-id>/subagents/agent-<id>.jsonl

<project> is the working directory with every character that isn't a letter or a digit replaced by -. If you set CLAUDE_CONFIG_DIR, look under that directory instead. Transcripts are deleted after cleanupPeriodDays (30 by default), so raise it if you want a longer history.

Each line is one JSON entry. The ones that answer from the model have "type": "assistant" and carry a usage object. Trimmed, with illustrative numbers:

{
  "type": "assistant",
  "timestamp": "2026-11-25T14:02:11.415Z",
  "requestId": "req_011C…",
  "isSidechain": false,
  "message": {
    "model": "claude-sonnet-5-5",
    "usage": {
      "input_tokens": 3,
      "cache_creation_input_tokens": 2140,
      "cache_read_input_tokens": 48210,
      "output_tokens": 412,
      "cache_creation": { "ephemeral_5m_input_tokens": 0, "ephemeral_1h_input_tokens": 2140 }
    }
  }
}

timestamp is in UTC. message.model is the full model name, not the alias you typed. cache_creation splits cache writes by how long the cache is kept (5 minutes or 1 hour), which matters for prices.

Anthropic describes this format as internal: it changes between versions. The fields above have been stable for a long time, but check your script after an update.

#How do you add up your tokens from the transcripts?

There's one trap first. A single request produces one line per block of the reply (a thinking block, a text block, each tool call), and every one of those lines repeats the same usage. Add every line and you count most requests two or three times. De-duplicate by requestId.

With jq, tokens per day for the last week:

find ~/.claude/projects -name '*.jsonl' -mtime -7 -print0 |
  xargs -0 jq -c 'select(.type == "assistant" and .message.usage != null
                         and .message.model != "<synthetic>")
    | {id: .requestId, day: .timestamp[0:10], model: .message.model, session: .sessionId,
       project: (input_filename | split("/projects/")[1] | split("/")[0]),
       u: .message.usage}' > /tmp/claude-usage.jsonl

jq -s -r 'unique_by(.id) | group_by(.day)[]
  | [ .[0].day,
      (map(.u.input_tokens) | add),
      (map(.u.cache_creation_input_tokens // 0) | add),
      (map(.u.cache_read_input_tokens // 0) | add),
      (map(.u.output_tokens) | add) ] | @tsv' /tmp/claude-usage.jsonl

The columns are day, input, cache write, cache read, output. The first command collects one small record per logged reply into a temporary file; the second de-duplicates and sums. <synthetic> entries are messages Claude Code writes itself, such as errors, with no tokens behind them. find goes into the subagents folders too, so subagent work is included; filter on isSidechain or skip those folders if you want the main conversations only.

Dates are UTC days. If you're far from UTC and want local days, convert the timestamp before grouping.

#How do you see usage per model or per project?

Same file, different grouping. Per model, with the number of requests and the total:

jq -s -r 'unique_by(.id) | group_by(.model)[]
  | [ .[0].model, length,
      (map(.u.input_tokens + (.u.cache_creation_input_tokens // 0)
           + (.u.cache_read_input_tokens // 0) + .u.output_tokens) | add) ] | @tsv' \
  /tmp/claude-usage.jsonl

Per project, sorted by output:

jq -s -r 'unique_by(.id) | group_by(.project)
  | map({project: .[0].project, output: (map(.u.output_tokens) | add)})
  | sort_by(-.output)[] | [.project, .output] | @tsv' /tmp/claude-usage.jsonl

Per project answers the question people actually have: "where did my week go?" It's often one long-running session nobody cleared.

#Why is cache read the biggest number?

Because the conversation is re-sent with every request. A session at 80,000 tokens of context that makes 50 tool calls reads around four million cached tokens, while you typed maybe 200 words. In a long interactive session, it's normal for cache reads to be well over 90% of all input.

That ratio is worth watching:

jq -s -r 'unique_by(.id)
  | (map(.u.cache_read_input_tokens // 0) | add) as $read
  | (map(.u.input_tokens + (.u.cache_creation_input_tokens // 0)) | add) as $new
  | "cache hit: \($read * 100 / ($read + $new) | floor)%"' /tmp/claude-usage.jsonl

A low hit rate means the cache keeps being rebuilt: long breaks between messages in a big session, frequent model switches, or a context that changes at the start. A high hit rate with a huge cache-read total means long contexts: /clear between tasks and /compact in long ones. Claude Code's context window covers both.

#How do you turn tokens into an API-price equivalent?

Multiply each counter by its price per million tokens, per model, and add. On Anthropic's API, prices are set against the model's base input price:

CounterPrice
InputBase input price
Cache write, 5 minutes1.25 × base input
Cache write, 1 hour2 × base input
Cache read0.1 × base input
OutputThe model's output price, several times the input price

Take the base prices from Anthropic's pricing page for the exact models in your transcripts. Cache reads are cheap per token but so numerous that they're a large share of the total; output is the opposite. What your usage would cost at API prices walks through the estimate and what it leaves out, and API key or subscription shows what to do with the number.

#What do /usage and /status show instead?

/usage in a session shows the same four counters by model for the current session, with a dollar estimate at list price. On a subscription it adds plan usage bars, activity over the last day or week, and what counted against your limits. Two limits to keep in mind: the figures come from this machine's history, so another computer or claude.ai isn't in the breakdown, and totals restart when /clear starts a new session. /status tells you which account and credential the tokens are going to.

#Which numbers are worth tracking?

Four are enough:

  1. Tokens per day, by model. Your baseline. A day at three times the usual is worth a look.
  2. Output tokens. The closest thing to "work done". A day with huge input and little output was spent re-reading context.
  3. Cache hit rate. Usually above 90% in long sessions; a drop points to breaks or model switches in big ones.
  4. Your three biggest sessions. Group by .session instead of .day. They're usually the ones that should have been cleared or split.

Check them weekly, not hourly. Usage is lumpy, and the useful signal is the trend.

#In Relais

Relais has a Token burn plugin that does this counting for you. Turn it on in Settings › Plugins: it records the tokens each turn read and wrote, by model, and what they would cost at API prices. Today's total sits in the status bar, and a page shows every day and model. If you like, it makes a public page of your burn at getrelais.app/u/your-name, and puts you on the leaderboard, ranked this week, this month or all time, with a league set by your last 30 days of tokens (what a page shows and what stays on your Mac). The Session budget plugin sets a budget per session at API prices and tells you when one goes past it. Your Claude plan is still what you pay; these are estimates to understand your usage. See Token burn.

Your AI team,
on your Claude plan.

$14.99 a month, everything included. On your Mac or on Linux, on your Claude Pro or Max plan. Cancel any time.