AI Coding Agents
Anthropic Cache Invalidation Rules: Every Trigger and What It Costs
Anthropic builds cache prefixes in a fixed order: tools, then system, then messages. Editing a tool definition invalidates all three layers, while changing tool_choice invalidates only the messages layer and can still leave an earlier entry reusable. On the Claude API, tokens written to a new cache entry cost 1.25x base input for five minutes or 2x for one hour.
Anthropic matches cached prefixes in the order tools, system, then messages. Editing a tool description invalidates all three layers. Changing tool_choice affects only the messages layer, so the API can still read an eligible tools or system entry. Check usage.cache_creation_input_tokens for the tokens actually written and usage.cache_read_input_tokens for the tokens reused. These rules reflect Anthropic’s documentation as of November 30, 2026. For the mechanics of caching itself, start with what prompt caching is.
How the prefix hierarchy decides what gets rewritten
Three documented mechanics decide what an invalidation costs:
- Writes happen only at breakpoints. A
cache_controlmarker identifies the cumulative prefix ending at that block. A miss can write an entry there if the prefix is eligible. Changing any block at or before the breakpoint produces a different hash on the next request. You can define up to 4 breakpoints, including one for top-levelcache_controlwhen automatic caching adds a marker. If the last block already has an explicit marker with the same TTL, automatic caching leaves it in place without adding another. For Amazon Bedrock, check the model’s automatic caching support and use explicit checkpoints for models that reject top-levelcache_control. - Reads look backward at most 20 positions. The system checks at most 20 positions for each breakpoint, counting the breakpoint itself as the first, and it can only find entries that earlier requests wrote. On the Claude API, a run of consecutive
tool_useblocks counts as one position, and so does a run of consecutivetool_resultblocks. - Matching is exact. A cache hit requires a 100 percent identical prompt segment, including text and images, up to and including the marked block. Anthropic’s troubleshooting notes even call out
tool_useblocks whose JSON keys arrive in a different order, because languages like Swift and Go randomize key order during conversion.
An earlier change can force more of the prefix to be processed again. The last usable hit and the eligible breakpoints determine how many tokens are read or written. Tokens left outside those reads and writes are billed as regular input. Cache reads cost 0.1x the base input price on most models. The documented exceptions include 0.025x on Claude Fable 5.2, Mythos 5.2, Fable 5.1 and Mythos 5.1, and 0.05x on Claude Opus 5.5 and Sonnet 5.5.
The invalidation table, row by row
This table combines Anthropic’s prompt caching and tool-use rules. A check means that layer can still match an entry if one was written and is still warm. A cross means the change invalidates that layer.
| What changes | Tools cache | System cache | Messages cache | Documented effect |
|---|---|---|---|---|
| Tool definitions (names, descriptions, parameters) | ✘ | ✘ | ✘ | Invalidates the entire cache |
| Web search toggle | ✓ | ✘ | ✘ | Enabling or disabling modifies the system prompt |
| Citations toggle | ✓ | ✘ | ✘ | Enabling or disabling modifies the system prompt |
| Web fetch toggle | ✓ | ✘ | ✘ | Enabling or disabling web fetch invalidates system and message caches |
| Speed setting | ✓ | ✘ | ✘ | Switching between speed: "fast" and standard speed invalidates system and message caches |
tool_choice | ✓ | ✓ | ✘ | Only affects message blocks |
disable_parallel_tool_use | ✓ | ✓ | ✘ | Only affects message blocks |
| Images | ✓ | ✓ | ✘ | Adding or removing images anywhere in the prompt |
| Thinking parameters | Model-specific | Model-specific | ✘ | The thinking mode and, in extended thinking mode, budget_tokens are rendered into the prompt. Tools and system also miss on models that render the configuration ahead of them. |
Top-level output_config.effort | Model-specific | Model-specific | Can invalidate | Sending the model’s default is equivalent to omitting it. On supported models, per-message effort preserves the earlier cached prefix. |
| Non-tool results sent with thinking | ✓ | ✓ | Model-specific | Thinking blocks preserved on Opus 4.5 and later Opus, Sonnet 4.6 and later Sonnet, Haiku 5.5, and every Fable and Mythos model; other models strip cached thinking blocks and everything after them |
| Dropped thinking blocks | ✓ | ✓ | ✘ | A dropped block changes the cached prefix from that block’s position onward |
Design moves for each level, working down the hierarchy:
Tools level. Freeze the tools array across the conversation and serialize input_schema deterministically so the JSON is byte-identical each turn. Put cache_control on the last non-deferred tool. For an eligible mcp_toolset, mark the toolset entry to place the breakpoint on its final expanded tool. A marker on a deferred tool returns HTTP 400. With tool search, keep sending the full tool definitions in tools on each request. When Claude discovers a deferred tool, the API appends a tool_reference to the conversation and expands the definition there. To add or change a definition mid-conversation on supported models, use a tool_addition block in a mid-conversation system message with the inline-tools-2026-09-15 beta header, keeping the original tools array intact. If that array has no non-deferred tool, the first inline definition causes a full cache miss on that request.
System level. Choose web search, citations, web fetch, and speed before starting a cached conversation. Toggling any of them invalidates the system and messages caches. If you need a new instruction mid-conversation on Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Fable 5, Mythos 5, Opus 5.5, Opus 5, Opus 4.8, Sonnet 5.5 or Haiku 5.5, append a {"role": "system"} message to messages to keep the earlier prefix intact. On Claude Sonnet 5, use the top-level system field.
Messages level. Keep tool_choice and disable_parallel_tool_use constant across turns. If you must vary tool_choice, Anthropic advises placing a breakpoint before the variation point. Keep image presence consistent because adding or removing images anywhere affects message blocks. Use the same thinking configuration and effective output_config.effort for pre-warming and live requests. A mismatch can prevent the warmed prefix from being reused. On models that support per-message effort, an effort change carried in a role: "system" message inside messages leaves the cached prefix intact. Pass back thinking blocks unchanged when the receiving model can read them. On models that strip earlier thinking blocks when you append non-tool-result user content, the prefix changes from the first dropped block onward.
What an invalidation costs on committed rates
Estimate the write cost as tokens_written ÷ 1,000,000 × write_rate_per_million. On the Claude API, the write rate is 1.25x base input at the 5-minute TTL and 2x at the 1-hour TTL. The table uses committed first-party rates from the ByteCosts pricing dataset as of November 30, 2026, with 1-hour rates derived by doubling the base input rate.
| Model | Base input / 1M | 5m write / 1M | 1h write / 1M | Cache read / 1M |
|---|---|---|---|---|
| Claude Sonnet 5.5 | $2.00 | $2.50 | $4.00 (derived from 2x) | $0.10 (0.05x) |
| Claude Opus 5.5 | $4.00 | $5.00 | $8.00 | $0.20 (0.05x) |
| Claude Haiku 5.5, prompts up to 100k | $0.10 | $0.125 | $0.20 | $0.01 |
Check current rates on the provider pricing index.
Worked example (estimate). Assume a 150,000-token Claude Sonnet 5.5 prefix with 40,000 tool tokens, 10,000 system tokens, and 100,000 message tokens. Assume the previous request wrote an entry at each boundary, all entries are still warm, and each scenario uses the same TTL at every breakpoint. Each row changes only the feature named, with the same eligible breakpoints in the follow-up request.
| Trigger | Layers rewritten | Tokens written | Estimated write cost at 5m | Estimated write cost at 1h |
|---|---|---|---|---|
| Tool definition edit | All three | 150,000 | $0.375 | $0.600 |
| Web search toggle | System + messages | 110,000 | $0.275 | $0.440 |
tool_choice change | Messages only | 100,000 | $0.250 | $0.400 |
At $0.10 per million read tokens, the 40,000-token hit after a web search toggle adds an estimated $0.004, and the 50,000-token hit after a tool_choice change adds $0.005. The estimated cache input subtotals in table order are $0.375, $0.279, and $0.255 at five minutes, or $0.600, $0.444, and $0.405 at one hour. A later full-prefix hit costs an estimated 150,000 ÷ 1,000,000 × $0.10 = $0.015. These estimates exclude uncached input and output.
If you had written only the final breakpoint, the stable tools and system text in this example would have no earlier entries to hit. When measuring a real request, use usage.cache_read_input_tokens to locate the end of the reused prefix in token terms. With mixed TTLs, price the counts in usage.cache_creation.ephemeral_5m_input_tokens and usage.cache_creation.ephemeral_1h_input_tokens separately, then add the charge for regular usage.input_tokens if you want the full input subtotal.
Invalidation sources the table does not spell out
A few documented behaviors produce rewrites or misses that never appear as a row:
- Server-tool auto breakpoints. When your request has prompt caching enabled and Claude uses a server tool such as web search, web fetch or code execution, the API places an automatic cache breakpoint on the server tool result before the next iteration of the agentic loop. That breakpoint always uses the 5-minute TTL regardless of your own
ttl, socache_creation.ephemeral_5m_input_tokenscan appear even when every marker you set says"1h". Requests with nocache_controlmarker get no automatic breakpoint. - Below the minimum length. On the Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Google managed) and Microsoft Foundry, the minimum cacheable prompt length runs from 512 tokens (Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Opus 5.5, Opus 5, Sonnet 5.5, Fable 5, Mythos 5, Haiku 5.5) up through 1,024, 2,048 and 4,096 on older models. Measure the prefix through the breakpoint. A prefix below the model’s minimum produces no cache entry or validation error. If both
cache_creation_input_tokensandcache_read_input_tokensare zero, check the breakpoint and minimum length first. - Lookback misses. If a growing conversation pushes your breakpoint 20 or more positions past the last write, the window misses it; add a second breakpoint closer to that position from the start.
- Scope. Different organizations never share caches. On the Claude API, Claude Platform on AWS and Microsoft Foundry, identical prompts in different workspaces build separate entries. On Google-managed Claude Models on Google Cloud and Amazon Bedrock, isolation is by organization only.
- Mixed TTL ordering. Longer-TTL entries must appear before shorter ones: a 1-hour
cache_controlblock must precede any 5-minute blocks. A hit on a 5-minute entry does not count if a 1-hour block after it misses, and reading a 5-minute entry restarts its 5-minute lifetime even if the request now sets"ttl": "1h".
What to do next
- Keep the
toolsarray,systemprompt,tool_choice, thinking configuration, effort and speed constant for the lifetime of a cached conversation, and put per-request values in the newest user message instead of the prefix. - Estimate the write from the tokens between the last usable hit and the final eligible breakpoint. Use the 5-minute vs 1-hour TTL comparison to decide whether avoiding expiry is worth the higher write rate.
- Place breakpoints with the hierarchy in mind: the cache_control breakpoints guide covers the 4-breakpoint limit and the 20-position lookback in detail.
- For an unexplained miss, use the cache diagnostics guide to compare consecutive requests and check for a reported divergence.
Sources
- Prompt caching (Anthropic, accessed 2026-11-30)
- Tool use with prompt caching (Anthropic, accessed 2026-11-30)
- Tool search tool (Anthropic, accessed 2026-11-30)
- Prompt caching for faster model inference (AWS, accessed 2026-11-30)
Interactive report
- The Cache Breakers: The agent sends another ordinary-looking request. A timestamp, a shuffled tool list, or a model switch just changed what the API can reuse. See what each edit puts on the invoice.
How this note was produced
Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.
Anthropic Cache Invalidation Rules: Every Trigger and What It Costs. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/anthropic-prompt-cache-invalidation-rules/