← ~/pillars / cost-engineering / prompt-cache-economics

Prompt cache economics

The write premium, the read discount, and the break-even arithmetic; what actually invalidates an agent's prefix cache; and how to measure your real hit rate at all three cost layers.

updated 2026-09-07 ~5 min read pattern 04/07 Cost Engineering

on this page

Context. An agentic session resends its entire history (system prompt, tool definitions, every prior turn) on every request. Prompt caching is the only reason that is affordable: Claude Code applies it automatically (costs), and a healthy session bills the vast bulk of its input at the cached rate. Which means cache behaviour is not an optimisation detail; it is the dominant term in what an agent costs, and most teams have never looked at theirs.

Forces. Caching is a priced bet, not a free lunch: writes cost more than uncached input, reads dramatically less, so the economics hinge on reuse you do not directly control. The cache dies by TTL and by invalidation, and the invalidating actions look innocent: toggling a setting, a long pause, an edited early message. And the discourse runs on asserted hit rates nobody can trace, so teams assume savings instead of measuring them.

Resolution. Learn the four numbers (write premiums, read discount, break-even reuse counts, TTL), treat invalidation as a priced event with a catalogue, and read your actual ratio at whichever layer you pay at.

The pricing, precisely

From the prompt caching documentation, against base input price: a 5-minute-TTL cache write costs 1.25×, a 1-hour write 2×, and a cache read 0.1× on either. On Opus 4.8 at $5/MTok that is $6.25/MTok or $10/MTok to write and $0.50/MTok to read.

The break-even arithmetic falls straight out. Sending the same prefix N times uncached costs N; cached, it costs the write plus N−1 reads:

  • 5-minute cache: 1.25 + 0.1(N−1) beats N from N = 2. One reuse and you are ahead; by N = 10 you are paying ~21% of the uncached price.
  • 1-hour cache: 2 + 0.1(N−1) needs N = 3. A doubled premium for the longer window; it pays only when reuse is real but slow.

Two mechanics matter as much as the multipliers. Reads refresh the TTL at no cost, so an actively used 5-minute cache lives indefinitely. And the reported input_tokens field counts only tokens after the last cache breakpoint: the true input is the sum of that plus cache_read_input_tokens plus cache_creation_input_tokens, which is why naive token maths misprices cached workloads in both directions.

The TTL is about think time, not session length

Free refresh-on-read changes what the 5-minute TTL means for interactive work: the clock only wins when you stop. A two-hour session with steady turns never expires its cache; a ten-minute coffee break expires all of it, and the next turn rewrites the whole prefix at 1.25×. On a 200k-token context, a pause costs real money. That reframes the 1-hour option: it is not for long sessions, it is for gappy ones: review workflows, long test runs between turns, agents that wait on CI. If your telemetry shows cache writes clustering after pauses longer than five minutes, the 2× write is cheaper than the rewrite pattern it prevents.

The same mechanics gate parallelism: a cache entry only becomes available after the first response begins, so several agents fanned out simultaneously on the same prefix all miss and all pay write premiums. Stagger the first call, or pre-warm the prefix, before fanning out.

The invalidation catalogue

Caching is prefix-hashed and hierarchical (tools, then system, then messages), and a change invalidates its level and everything after it (prompt caching). In agentic terms:

ActionLevel hitWhat you repay
Enabling/disabling an MCP server or plugin mid-sessionTool definitionsEverything: the full prefix rewrites
Toggling web search or fast modeSystemSystem and all messages
Switching /modelIts own cacheThe new model starts cold
Editing an early message, /rewindMessages from that pointThe tail of the conversation
Compaction (auto or /compact)MessagesThe rewritten history is a new prefix
A pause past the TTLEverythingFull rewrite at the write premium

The catalogue is why session hygiene is a cost practice, not a tidiness one: the expensive actions are precisely the mid-session configuration changes that feel free. Front-load them (pick the model, the MCP servers, and the thinking settings before the long work starts), and take compaction as a deliberate trade (it repays its write premium by shrinking every subsequent turn; the next pattern page prices that trade properly).

Measure it at the layer you pay at

Every layer of the three-layer model reports cache behaviour, in its own currency:

  • Local telemetry: claude_code.token.usage splits by type (cacheRead, cacheCreation, input, output), and each api_request event carries per-request cache token counts (monitoring usage). The statusline-cost artifact shows the live per-request read share; the OTel kit’s dashboard tracks the fleet’s read share over time.
  • Provider accounting: the API usage block itemises cache_creation_input_tokens and cache_read_input_tokens per response; sum them before comparing anything to a bill.
  • Billing truth: the CUR carries cache reads and writes as their own usage types with their own unit prices (CUR data); the Bedrock attribution artifact ships the cache-read-share query.

The healthy signature at any layer: reads growing turn on turn, writes flat. Writes tracking reads means the prefix is being rebuilt repeatedly: go back to the catalogue and find which row you are paying for.

Since Claude Code v2.1.251 you no longer have to infer that row locally. The prompt_cache object, surfaced in /cost and to status line scripts, reports the session’s hit_ratio and a misses count, and from v2.1.260 also a last_miss_cause and a miss_causes tally naming the likely reason (changed tool definitions, a rewritten conversation, an idle past the TTL) (status line). Read the definition before you act on the count: a request is scored a miss when it “re-processed more than 5% and at least 2,000 tokens of what it could have read from cache”, and rebuilds that follow a compaction or a clear are tallied separately as expected_rebuilds (costs). The number worth an alarm is therefore misses that are not expected rebuilds: those are the catalogue rows above, now named for you rather than derived.

About that 92%

A hit-rate figure for Claude Code, usually 92%, circulates widely. We tried to trace it for this page and found only secondary blog posts citing each other, none with a disclosed methodology, sample, or date. So it is not cited here as fact, and the honest position is stronger anyway: your hit rate is a property of your sessions (their pause structure, their mid-session config churn, their compaction cadence), and the previous section measures it in an afternoon. Published, methodology-disclosed distributions of real cache ratios are on this site’s measurement roadmap; until then, distrust any precise-sounding number that arrives without a denominator, including this one’s ghost.

// sources