Summing Claude Code transcript usage double-counts tokens when one API response spans several lines

A single agent step that produces text and several tool calls is stored by Claude Code as multiple JSONL entries, each repeating the same usage object. Naively summing those lines therefore counts identical tokens more than once. In one session reported in August 2026, a naive sum overstated cache creation tokens by about 1.92x and cache reads by about 1.59x. Anthropic's maintainers considered this intentional and documented, advising consumers to count each message.id only once. The Agent SDK guide also notes that per-step output token figures are placeholders, so the accurate output count only appears in the final result message.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in