Home › Blog › Why Claude Code Burns API Tokens So Fast
Agents & Token MathWhy Claude Code Burns API Tokens So Fast (And How Billing Works Across Tool Loops)
“I only typed three prompts—why does my Anthropic usage dashboard say 2.4 million tokens?” Almost every developer switching Claude Code onto an API key asks this in week one. Nothing is broken in your meter: you are seeing stateless tool-loop compounding, cache-write premiums, and extended-thinking output in action.
Claude Code is an agent loop built on a stateless POST /v1/messages API. Three human messages commonly trigger 20–30 internal Grep, Read, Edit, and Bash round-trips, and every round-trip resends the entire conversation prefix so far. Even when warm prompt-cache hits discount repeated context by 95% (0.05x on Sonnet 5.5 and Opus 5.5), cumulative tokens grow quadratically—and a single 7-minute coffee break expires an API key's default 5-minute cache, forcing a full 1.25x cache rewrite (25x more expensive on that prefix).
Worked trace: how 3 human prompts bill 2,400,000 tokens
Illustrative 25-turn trace using verified standard Anthropic API list rates as of November 14, 2026 for Claude Sonnet 5.5 ($2.00 base input, $2.50 5m cache write [1.25x], $0.10 cache read [0.05x], $10.00 output) and Claude Opus 5.5 ($4.00 input, $5.00 5m write, $0.20 cache read, $20.00 output; see all Claude API pricing).
Suppose you open Claude Code to fix a flaky webhook retry worker. You type three short sentences over 35 minutes while Claude runs 22 internal tool steps (25 total POST /v1/messages calls):
- Startup + Prompt 1 (Turns 1–10): Claude loads its system prompt, tool schemas, and your repo's
CLAUDE.md(14,000startup tokens) plus your first prompt and initial search results (+6,000tokens →P_1 = 20,000). Across 9 follow-upGrep,Read, andEditsteps adding an average of6,000net tokens per turn, the prompt grows to74,000tokens by Turn 10, generating4,000output + thinking tokens per turn. - Prompt 2 + test/fix loop (Turns 11–20): You ask Claude to update the worker timeout test. Ten more
Bash pytestandEditcalls grow the prompt from80,000to134,000tokens while staying inside the warm 5-minute cache window. - 7-minute coffee break → Prompt 3 at Turn 21 (
140,000-token cold miss!): You step away for 7 minutes to grab coffee while CI runs. Because API keys default to a 5-minute prompt cache TTL, the cached134,000-token prefix expires. When you type your third prompt (+6,000tokens →140,000total prompt), Anthropic re-writes all140,000tokens at1.25x($2.50/MTok). - Final cleanup & test run (Turns 22–25): Four warm tool turns finish verification as context reaches
164,000tokens.
| Session phase | API calls | Prompt window | cache_read (0.05x) | cache_write 5m (1.25x) | output + thinking | Billed tokens | Sonnet 5.5 (Opus 5.5) |
|---|---|---|---|---|---|---|---|
| 1. Prompt 1 + discovery loop (Turns 1–10) | 10 | 20k → 74k | 396,000 | 74,000 | 40,000 | 510,000 | $0.6246 ($1.2492) |
| 2. Prompt 2 + pytest loop (Turns 11–20) | 10 | 80k → 134k | 1,010,000 | 60,000 | 40,000 | 1,110,000 | $0.6510 ($1.3020) |
| 3. Turn 21 after 7-min break (5m TTL expired) | 1 | 140k (cold) | 0 | 140,000 | 4,000 | 144,000 | $0.3900 ($0.7800) |
| 4. Final check loop (Turns 22–25) | 4 | 146k → 164k | 596,000 | 24,000 | 16,000 | 636,000 | $0.2796 ($0.5592) |
| Total across 3 human prompts | 25 | 164k peak | 2,002,000 | 298,000 | 100,000 | 2,400,000 | $1.9452 ($3.8904) |
Notice two numbers in that table: first, summing a context that grows linearly from 20k to 164k across 25 calls produces 2,300,000 input-side tokens plus 100,000 output tokens = 2,400,000 total tokens. Second, 83.4% of those tokens (2,002,000) were cheap $0.10/MTok cache reads (costing just $0.2002 total!), while 5m cache writes ($0.7450) and output + thinking ($1.0000) drove 89.7% of the dollar bill. You can replay this exact 25-turn curve—or plug in your own turns and pause count—in our Claude Code API Cost & Token-Burn Calculator.
How Anthropic's four token counters actually bill each turn
A common mistake when reading raw /v1/messages logs or usage CSVs is assuming input_tokens equals the total prompt size. In Anthropic's Messages API, input tokens are split into disjoint buckets:
{
"usage": {
"input_tokens": 0,
"cache_creation_input_tokens": 6000,
"cache_creation": {
"ephemeral_5m_input_tokens": 6000,
"ephemeral_1h_input_tokens": 0
},
"cache_read_input_tokens": 128000,
"output_tokens": 4000
}
}| Usage field | What it counts | Sonnet 5.5 rate | Opus 5.5 rate |
|---|---|---|---|
input_tokens | Uncached tail only—tokens appearing after the final cache_control breakpoint (or the entire prompt if caching is disabled). Total prompt sent is input + cache_read + cache_creation. | $2.00 / MTok (1.0x) | $4.00 / MTok (1.0x) |
cache_creation_input_tokens | New prefix tokens written to cache on this turn: billed at 1.25x for the default 5m TTL, or 2.0x when 1h TTL is enabled. | $2.50 (5m) / $4.00 (1h) | $5.00 (5m) / $8.00 (1h) |
cache_read_input_tokens | Prefix tokens matched in warm cache (also refreshes the TTL countdown at no extra fee). Discounted 95% (0.05x) on Sonnet/Opus 5.5 (0.025x on Fable 5.2; 0.10x on Haiku 5.5 & 4.6). | $0.10 / MTok (0.05x) | $0.20 / MTok (0.05x) |
output_tokens | Generated text, tool_use JSON arguments, and extended-thinking tokens combined. Thinking is already inside output_tokens—never billed twice. | $10.00 / MTok | $20.00 / MTok |
Two 2026 model details compound output spend: on Claude Sonnet 5.5, Opus 5.5, Haiku 5.5, and Fable 5.2, extended thinking is always on (tuned via /effort low|medium|high|max rather than an off switch), and Anthropic's updated 4.7+/5.x tokenizer produces roughly 30% more tokens for the exact same source code than Claude 4.6 and earlier.
The 7-minute coffee break trap (5m API TTL vs. 1h subscription TTL)
Why do developers moving from a claude.ai Pro/Max seat to an API key get surprised by cache-write spikes? Because Claude Code assigns different default cache lifetimes depending on how you authenticate:
claude.aisubscriptions (within plan allowance): 1-hour cache TTL on the main conversation.- API keys, cloud providers, and LLM gateways: 5-minute cache TTL by default on both the main session and subagents (unless you explicitly opt into
CLAUDE_CODE_PROMPT_CACHE_TTL=1h/promptCacheTtl: "1h").
Look closely at Turn 21 in our worked trace above (134,000 prior tokens + 6,000 new turn tokens = 140,000 prompt tokens, plus 4,000 output tokens):
- If you replied within 4 minutes (warm cache):
134,000 × $0.10/MTok($0.0134) +6,000 × $2.50/MTok($0.0150) +4,000 × $10.00/MTok($0.0400) = $0.0684. - Because you paused 7 minutes (expired 5m cache):
140,000 × $2.50/MTok($0.3500) +4,000 × $10.00/MTok($0.0400) = $0.3900.
Re-caching that 134,000-token prefix jumped from $0.0134 to $0.3350—25x more expensive on the historical prefix, adding $0.3216 on Sonnet 5.5 (or $0.6432 on Opus 5.5) from a single 7-minute break. Mid-session cache invalidation also happens without waiting 5 minutes if you switch models with /model (including opusplan toggling between Opus and Sonnet), toggle /fast, or change upfront MCP tool definitions.
Why crossing 200k+ context hurts twice (plus subagent fanout)
Long coding sessions that drift past 150k–200k tokens penalize your budget through two compounding mechanisms:
- 1M default windows removed the old ~190k safety stop. Claude Sonnet 5.5, Opus 5.5, Haiku 5.5, and Fable 5.2 include a 1M-token context window at flat
1.0xstandard per-token pricing on Anthropic's first-party API, and Claude Code no longer auto-compacts until ~967k tokens unlessCLAUDE_CODE_AUTO_COMPACT_WINDOWis set. That sounds purely helpful until a single debugging thread silently snowballs to 320,000 tokens: every minorBashcommand re-reads 320k tokens, noisy stale diffs trigger extra reasoning retries, and a single >5-minute meeting break triggers an$0.80Sonnet 5.5 (or$1.60Opus 5.5) cold-cache rewrite on the very next message. - Prompt-length rate cliffs and subagent multiplication. Anthropic evaluates prompt-length pricing tiers per request across all input tokens (
input + cache_read + cache_write), even on cache hits. While first-party Sonnet 5.5 and Opus 5.5 stay flat at1.0xacross 1M tokens, Claude Haiku 5.5 jumps 5.0x across every token category above 100,000 total prompt tokens ($0.10 → $0.50input,$0.01 → $0.05cache read,$0.50 → $2.50output; legacy 1M beta models and custom cloud contracts can also step up above 200k). Meanwhile, every spawned subagent opens an isolated context window with its own separate 5m cache on the inherited parent model unless pinned—meaning three unpinned exploration subagents inside an Opus 5.5 session pay three separate$5.00/MTokcold-cache startup writes.
Five fixes that stop token waste without rationing Claude Code
You do not need to slow down how your engineers work to cut wasted token burn:
- Run
/clearbetween unrelated tickets (instant reset, zero summarization API cost) and setCLAUDE_CODE_AUTO_COMPACT_WINDOW=180000so marathon features compact before snowballing past 200k tokens. - Keep root
CLAUDE.mdunder 200 lines and move specialized workflows into on-demand.claude/skills/so every session start and subagent begins with a lean prefix. - Deny lockfiles,
dist/, and verbose test dumps in.claude/settings.jsonso a single accidental read never pollutes 20 remaining turns. - Pin search subagents to
model: haiku(under 100k context) orsonnetand match/effortto task complexity instead of switching/modelmid-thread (see controlling reasoning token costs). - Route native
/v1/messagesthrough a prepaid workspace wallet (ANTHROPIC_BASE_URL="https://apicuts.ai", create a workspace or inspect the live demo) with separateack_...keys per squad or repo so you can auditcache_readvscache_writeratios in/app/overviewand/app/requestswithout storing code—and stop runaway loops cleanly with402 insufficient_walletinstead of an uncapped month-end bill.
Get the complete repo templates and worked team numbers in our Claude Code Team Cost Playbook, see connection details in Coding tools, or compare non-CLI production levers in how to cut your Anthropic API costs and how to cap AI agent costs.
Frequently asked questions
Why did 3 prompts in Claude Code bill over 2 million tokens?
Each human prompt triggers multiple internal Read, Grep, Edit, and Bash tool calls. Because Anthropic's /v1/messages endpoint is stateless, every tool step sends a separate API request containing your system prompt, CLAUDE.md, and all accumulated conversation and tool history. Across 25 total steps growing from 20k to 164k tokens, cumulative tokens processed easily reach 2.4M.
Are extended thinking tokens billed separately from output_tokens?
No. In Anthropic's Messages API, usage.output_tokens already includes extended-thinking tokens alongside visible text and tool-call JSON. Both are billed once at the model's output rate ($10.00/MTok on Claude Sonnet 5.5 and $20.00/MTok on Claude Opus 5.5).
Why does a 7-minute break spike Claude Code API costs?
When running on an API key, cloud provider, or gateway, Claude Code defaults to a 5-minute prompt cache TTL unless 1-hour caching is configured. Pausing for 7 minutes expires that cache, turning your next turn on a 134k-token history from a $0.10/MTok cache read (0.05x) into a $2.50/MTok 5-minute cache write (1.25x) on Claude Sonnet 5.5—a 25x jump on that prefix.
Sources: Anthropic API pricing reference, Claude Code prompt caching docs, Claude Code context window docs, and Claude Code cost management docs. Verified November 14, 2026.
Simulate your own Claude Code session turns and cache misses
Adjust turns per task, 5m vs 1h cache TTLs, compaction thresholds, thinking tokens, and team size in our interactive browser calculator.
Try the Claude Code Cost Calculator