Coding agent prompt cache miss cost: what breaks the prefix and how to find it A prompt cache miss on Claude Sonnet 5.5 or Opus 5.5 costs 25 times a cache hit and 1.25 times sending the same prefix uncached, at Anthropic's 19 October 2026 prices, according to an analysis of Anthropic's prompt-caching documentation. The analysis recomputed Rajesh Beri's 30-turn agent loop with a 20k-token prefix growing 1,500 tokens per turn at Sonnet 5.5 prices with five-minute writes: $2.72 uncached versus $0.41 cached, an 85% saving, while changing a tool description every turn raised the session to $3.36, 24% more than not caching. Anthropic cut Sonnet 5.5 cache reads from $0.20 to $0.10 per million tokens on 7 October 2026 with writes unchanged, doubling the miss-to-hit ratio from 12.5 to 25 and making a stable prefix more valuable. Coding agent prompt cache miss cost: what breaks the prefix and how to find it A prompt cache miss on Claude Sonnet 5.5 or Opus 5.5 costs 25 times what a cache hit costs on the same prefix, and 1.25 times what sending it uncached would have cost, at Anthropic's October 2026 prices. The first cause to rule out is a pause longer than the cache lifetime, which is five minutes on an API key. If your misses come within that window, something changed the prefix: the tool list, the model, the effort setting, a value in the system prompt, or an edit to earlier turns. Each leaves its own trace, and Claude Code now names most of them. A cache miss shows up as reads near zero and writes near the whole prompt A prompt cache miss is a request that re-processes, at the write price, a prefix it could have read from cache. In the Anthropic API response, cache read input tokens drops to zero or to the part before the change, and cache creation input tokens jumps to roughly the whole prompt. On a healthy turn it is the other way round: reads cover the previous request and writes cover only the newest exchange. The prompt caching docs https://platform.claude.com/docs/en/build-with-claude/prompt-caching add a third field, input tokens , which counts only what comes after the last cache breakpoint. Claude Code https://stackness.dev/tools/claude-code 's caching page https://code.claude.com/docs/en/prompt-caching gives the rule of thumb: "If creation stays high turn after turn, something is changing in your prefix." Its status line counts a miss when a request re-processed "more than 5% and at least 2,000 tokens" it could have read, and counts compaction separately, as an expected rebuild. What does a prompt cache miss cost? A prompt cache miss costs the write price on the whole prefix: 1.25 times the base input price with the five-minute lifetime, 2 times with the one-hour lifetime. A hit costs 0.05 times base on Sonnet 5.5 and Opus 5.5, and 0.1 times on Haiku 5.5. So a miss on those two models costs 25 to 40 times a hit, and more than not caching at all. Prices are from Anthropic's pricing page https://platform.claude.com/docs/en/about-claude/pricing on 19 October 2026, for the prefix alone on one request: | Prefix | Model | Hit | Uncached | Miss, 5-minute write | Miss, 1-hour write | |---|---|---|---|---|---| | 50k tokens | Sonnet 5.5 | $0.005 | $0.10 | $0.125 | $0.20 | | 100k tokens | Sonnet 5.5 | $0.01 | $0.20 | $0.25 | $0.40 | | 100k tokens | Opus 5.5 | $0.02 | $0.40 | $0.50 | $0.80 | | 50k tokens | Haiku 5.5 | $0.0005 | $0.005 | $0.00625 | $0.01 | One miss is cents. A session that misses on every turn is not. Rajesh Beri modelled https://www.beri.net/article/prompt-caching-savings-cost-per-provider-hit-rate-agent-loop-2026 a 30-turn agent loop with a 20k-token prefix that grows by 1,500 tokens a turn. I recomputed it at today's Sonnet 5.5 prices with five-minute writes: $2.72 uncached, $0.41 cached, an 85% saving. Put a timestamp in the system prompt, so only the tool block is ever read back, and the session costs $2.53, a 7% saving. Change a tool description every turn and it costs $3.36, 24% more than not caching. Sonnet 5.5's cache read cut made each miss relatively dearer Anthropic lowered Sonnet 5.5 cache reads from $0.20 to $0.10 per million tokens on 7 October 2026, and its release notes https://platform.claude.com/docs/en/release-notes/overview say "Cache writes and all other prices are unchanged." A miss costs the same dollars as before; a hit costs half. The ratio between them doubled, from 12.5 to 25 with five-minute writes, so a stable prefix is worth more than it was. Anthropic said https://x.com/claudeai/status/2107894060229034197 the cut makes Sonnet 5.5 "around 20% cheaper to run on most long-running work", without a published method. Opus 5.5 has charged 0.05 times base since it launched on 22 September; Haiku 5.5 stays at 0.1 times. Claude Code's /cost , status line and --max-budget-usd kept pricing Sonnet 5.5 reads at $0.20 until version 2.1.296 on 9 October, as MIXED News https://mixed-news.com/en/anthropic-sonnet-5-5-cache-reads-halved-claude-code-2-1-296-cost/ reported: a display error, not a billing one. The Sonnet and Opus comparison https://stackness.dev/blog/sonnet-5-5-vs-opus-5-5-which-slot-each-one-takes-in-a-coding-agent-stack has the full price table, and the language models developers pick for their agents https://stackness.dev/categories/llms are listed by category. A pause longer than the cache lifetime is the first cause to rule out Cache expiry is the first cause to rule out because it needs no mistake: step away longer than the lifetime and the next message re-writes the whole context, as Claude Code's costs page https://code.claude.com/docs/en/costs says. The main conversation gets a one-hour lifetime on a subscription within plan usage, and five minutes on an API key, usage credits or a cloud provider. Subagents and compaction get five minutes. Each hit refreshes the lifetime for free. Boris Cherny of the Claude Code team described https://news.ycombinator.com/item?id=47880089 the worst case in April: 900k tokens in context, an hour idle, then one message, is " 900k tokens written to cache all at once". A subscriber who runs into usage credits drops to five minutes mid-session, which looks like a bill that jumped for no reason. Test: /usage shows the main conversation's cache as warm or cold and when it was last active; the status line's last miss cause reports ttl expired 5m . Through the API, cache diagnostics https://platform.claude.com/docs/en/build-with-claude/cache-diagnostics return no change reason while reads drop, or previous message not found once the gap outlasts their short retention. Fix: set promptCacheTtl: "1h" or CLAUDE CODE PROMPT CACHE TTL=1h when your gaps run 5 to 60 minutes, and /clear rather than resume a large stale session. Since 2.1.299 Claude Code compacts a conversation of 200k tokens or more that has sat idle for about 54 minutes, before the one-hour cache expires. Compaction rebuilds the conversation layer by design Compaction is an expected rebuild, not a bug. Claude Code's caching page says of compaction: "By design, this invalidates the conversation layer": the system prompt and tools are reused, CLAUDE.md is reloaded from disk, and the summarised history is written fresh. With a warm cache, /compact "costs a fraction of what the context size suggests"; with a cold one it re-processes the full history as uncached input. Each later turn re-reads a much smaller prefix, so a long session usually comes out ahead. Thariq Shihipar of Anthropic wrote https://claude.com/blog/lessons-from-building-claude-code-prompt-caching-is-everything that Claude Code forks the compaction call with the same system prompt, tools and history so the summary request itself reads the cache. The compaction explainer https://stackness.dev/blog/what-is-context-compaction-in-coding-agents-and-what-does-it-quietly-lose covers what the summary drops. Test: /usage counts compactions as expected rebuilds; OpenTelemetry emits a claude code.compaction event with tokens before and after. Fix: compact at task boundaries while the cache is warm. /clear costs nothing, and /rewind returns to a prefix that is already cached. Switching the model or the effort setting starts over Every model has its own cache, so switching models mid-session re-writes everything, including through opusplan or a skill whose frontmatter names another model. Thariq's example: 100k tokens into an Opus session, switching to Haiku "would actually be more expensive" than staying. Effort and thinking settings are rendered into the prompt too, though Claude Code keeps the cache across effort changes on Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1 with an API key or a Claude subscription, not on Bedrock, Google Cloud or a Claude apps gateway. Turning on fast mode costs one miss per conversation. Test: diagnostics report model changed , or unavailable for thinking and effort changes. Claude Code asks for confirmation before a model switch while the cache is warm. Fix: pick the model at the start, and give cheap work to a subagent instead of switching the main conversation. A changed tool list invalidates everything after it Tool definitions sit at the very top of the prompt, so any change to them invalidates everything after: system prompt and messages. In Neuralwatt's production traffic, turns where the number of tools changed broke the cache 67% of the time, against 2.8% when nothing visible changed. Tool changes happened on about 0.5% of turns and caused 19% of the re-read tokens, though three accounts made up about two thirds of that share. Figure from Why harnesses matter for energy efficiency https://neuralwatt.com/news/why-harnesses-matter-for-energy-efficiency by Chad Gibson, Neuralwatt, 2026. Measured on Neuralwatt's cloud for open models, 6-13 October 2026, turns of 8k+ tokens, top three accounts excluded. Neuralwatt measured open models on its own cloud, not Anthropic's, and frames the cost as energy: "A cache miss roughly doubles a request's energy." The mechanism is the same everywhere. In Claude Code, connecting an MCP server mid-session or toggling a plugin that ships one breaks the cache, but only when tools load upfront. With tool search on, the default, Claude Code "keeps the tool list from the conversation's first request for the whole conversation". Test: diagnostics report tools changed ; Claude Code's last miss cause reports tools changed with counts of the tools added and removed. Fix: keep tool search on, change MCP servers between sessions, and in your own harness serialise tools and schema keys in a fixed order. Anthropic's docs warn that some languages, Go and Swift among them, randomise key order when converting to JSON, which breaks the cache when it reorders the keys in tool use blocks; diagnostics flag a non-deterministically serialised input schema as tools changed . A timestamp or a git status in the system prompt wipes out the saving Any value that changes per request in the system prompt invalidates the system block and every message after it. Timestamps, request IDs, the current date and git status are the usual culprits. Claude Code moved the date out of its own system prompt in version 2.1.42 in February 2026. Neuralwatt's lab found OpenCode 1.x and Kilo Code putting the date about 2,000 tokens in, so crossing midnight forced a near-full re-read. Test: diagnostics report system changed , which the docs gloss as "Typically a timestamp, request ID, or other per-request value". In Claude Code, last miss cause reports system prompt changed . OTEL LOG RAW API BODIES=file: