⚡ Your AI bill is eating your Q4 margin.Protect Your Margin. Get a FREE 360° Cost ReportFree 360° Cost Report

Home › Blog › Why Claude Code Burns API Tokens So Fast

Agents & Token Math

Why 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.

Quick answer

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):

  1. Startup + Prompt 1 (Turns 1–10): Claude loads its system prompt, tool schemas, and your repo's CLAUDE.md (14,000 startup tokens) plus your first prompt and initial search results (+6,000 tokens → P_1 = 20,000). Across 9 follow-up Grep, Read, and Edit steps adding an average of 6,000 net tokens per turn, the prompt grows to 74,000 tokens by Turn 10, generating 4,000 output + thinking tokens per turn.
  2. Prompt 2 + test/fix loop (Turns 11–20): You ask Claude to update the worker timeout test. Ten more Bash pytest and Edit calls grow the prompt from 80,000 to 134,000 tokens while staying inside the warm 5-minute cache window.
  3. 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 cached 134,000-token prefix expires. When you type your third prompt (+6,000 tokens → 140,000 total prompt), Anthropic re-writes all 140,000 tokens at 1.25x ($2.50/MTok).
  4. Final cleanup & test run (Turns 22–25): Four warm tool turns finish verification as context reaches 164,000 tokens.
Session phaseAPI callsPrompt windowcache_read (0.05x)cache_write 5m (1.25x)output + thinkingBilled tokensSonnet 5.5 (Opus 5.5)
1. Prompt 1 + discovery loop (Turns 1–10)1020k → 74k396,00074,00040,000510,000$0.6246 ($1.2492)
2. Prompt 2 + pytest loop (Turns 11–20)1080k → 134k1,010,00060,00040,0001,110,000$0.6510 ($1.3020)
3. Turn 21 after 7-min break (5m TTL expired)1140k (cold)0140,0004,000144,000$0.3900 ($0.7800)
4. Final check loop (Turns 22–25)4146k → 164k596,00024,00016,000636,000$0.2796 ($0.5592)
Total across 3 human prompts25164k peak2,002,000298,000100,0002,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:

JSON — Anthropic /v1/messages usage payload on warm Turn 20
{
  "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 fieldWhat it countsSonnet 5.5 rateOpus 5.5 rate
input_tokensUncached 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_tokensNew 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_tokensPrefix 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_tokensGenerated 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:

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):

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:

  1. 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.0x standard per-token pricing on Anthropic's first-party API, and Claude Code no longer auto-compacts until ~967k tokens unless CLAUDE_CODE_AUTO_COMPACT_WINDOW is set. That sounds purely helpful until a single debugging thread silently snowballs to 320,000 tokens: every minor Bash command re-reads 320k tokens, noisy stale diffs trigger extra reasoning retries, and a single >5-minute meeting break triggers an $0.80 Sonnet 5.5 (or $1.60 Opus 5.5) cold-cache rewrite on the very next message.
  2. 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 at 1.0x across 1M tokens, Claude Haiku 5.5 jumps 5.0x across every token category above 100,000 total prompt tokens ($0.10 → $0.50 input, $0.01 → $0.05 cache read, $0.50 → $2.50 output; 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/MTok cold-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:

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

Related