Claude Code Token Logs Overcount Usage by 2.5x. Here Is How to Count Them Correctly
Updated November 3, 2026 · first published November 3, 2026
Claude Code writes the same assistant message to its log several times as the reply streams. Summing every usage line in October gave us 21.3 billion tokens and $12,438 of list-price value. Counting each message once gave 8.4 billion tokens and $4,323. The raw sum overcounts by about 2.5x in tokens and 2.9x in dollars.
Published 3 November 2026 · Claude Code transcripts, 1 October to 3 November 2026 (UTC; 1 to 3 November partial)
Why does one message appear several times?
Each assistant entry in a Claude Code transcript (~/.claude/projects/.../*.jsonl) carries a usage object with input, output, cache-write and cache-read token counts. In our logs the same pair of message.id and requestId shows up on several lines, and later lines carry larger output counts than earlier ones. We did not trace every cause; the pattern is consistent with a reply being written as it streams. Whatever the cause, summing all lines counts the same request more than once. Of 175,884 usage lines in the window, only 70,592 were distinct messages.
How wrong is the raw sum?
The raw sum is 2.5x too high in tokens and 2.9x too high in dollars. Dollars inflate more than tokens, which means the repeated lines were weighted toward the more expensive token types; we did not break that down further.
Why keeping the first line is also wrong
The obvious fix is to keep the first line of each message. That undercounts output, because the first line is a partial snapshot. We keep the largest value of each field across all lines that share the same message id and request id.
The gap varies by model: Claude Haiku 4.5 lost 100% of its output tokens, while Claude Fable 5.1 lost 0.0%. In dollars the effect was small here ($4,297 against $4,323, about 0.6%) because output was a small share of our token volume. A workload that writes more and reads less would feel it more.
Three more ways agent logs mislead
- A zero cost column. OpenCode recorded 4,938 assistant messages in the same period, 82.4 million input tokens and 279.7 million cache-read tokens, and every message shows cost 0 because it ran on free model routes. Zero recorded cost does not mean zero use: the tokens and the free quota behind them are still real.
- Counts that are not for your window. Antigravity's conversation files hold model-call counts for the whole life of each conversation, not just October. A conversation you touched on 30 October contributes its history from September too.
- Logs that keep moving. Our own session was writing to the logs while we measured. Two runs minutes apart differed by about 0.1% in message counts. Fix the window and say when you took the snapshot.
How we counted
- Read assistant entries that have a
usageobject, between 1 October and 3 November 2026 (UTC). Skip synthetic placeholder messages. - Key each entry by
message.idplusrequestId. If neither exists, key by file and entry id. - For each key keep the maximum of every usage field across its lines. Include sub-agent (sidechain) messages, which are logged in the same files.
- Price tokens at Anthropic's list prices (checked 3 November 2026): for example Opus 5.5 at $4 input, $0.20 cache read and $20 output per million tokens, and Sonnet 5.5 at $2, $0.10 and $10. Cache writes use the logged 5-minute and 1-hour split. Haiku 5.5 uses its higher rate for prompts over 100,000 tokens, which we estimate per message from its input-side tokens.
What this does not tell you
- It is not your invoice. On a flat subscription the figure is an API-equivalent value, and the logs hold no dollar amounts.
- We did not compare against provider billing. Do that before you rely on any log-derived total.
- The mechanism behind the repeats is our reading of the pattern, not a statement from Anthropic.
What to do with this
- Deduplicate before you sum. Any dashboard that adds up log lines is probably overcounting. Ask what its key is.
- Use the maximum, not the first line, per message.
- Reconcile to a bill from the provider or gateway once a month. See LLM token tracking and AI observability for what a ledger needs.
- Do not trust a zero. Track tokens even where the price is free.
For the usage view this feeds, see Claude Code in October: tokens, cache and list-price value and how to check and reduce Claude Code token usage.
Frequently asked questions
How do I count Claude Code tokens correctly?
Read the assistant entries in the transcript files, key each by message id plus request id, and keep the maximum of each usage field across the lines that share the key. Summing every line counted our October usage 2.5 times too high.
Why do Claude Code logs show the same message more than once?
In our transcripts the same message id and request id appeared on several lines (175,884 lines for 70,592 unique messages), with later lines carrying larger output counts. That pattern is consistent with a reply being logged as it streams; we did not confirm the cause with Anthropic.
Is keeping the first line per message good enough?
It undercounts output tokens, because the first line is a partial snapshot. We missed 14% of output tokens overall, and up to 100% for one model, though the dollar effect was only about 0.6% on our mix.
Does the list-price value equal what I paid?
No. It is the cost of the same tokens at Anthropic's published API prices. A subscription or a gateway discount changes what you actually pay, and the logs contain no dollar amounts.
Related
- Claude Code in October: tokens, cache and list-price value
- How to check and reduce Claude Code token usage
- LLM token tracking
- We used Codex Pro $100 for 30 days: 14 resets
Want this applied to your stack? Bring the provider bills, gateway logs, and top workflows; we will map the cost drivers and savings path. Book a free audit →