ByteCosts
prompt-cache-invalidation-causes.mdx

AI Coding Agents

Silent prompt cache busters and how to find them

Silent prompt cache busters are changes inside the cached prefix of the model’s rendered input that cause cache reads to shrink or disappear while requests still succeed. Find the first changed tool, instruction, setting, or history block, then check whether the provider could still find a live cache entry ending before that change.

Find the first difference in the prefix

A cached prefix starts at the beginning of the rendered prompt and ends at a particular boundary. If you replace an early instruction and send the same tool results and messages afterward, those later blocks still belong to a different prefix. An eligible entry ending before the edit can still match if the provider finds it. This is why one request can have a large cache read and still pay to process the rest of a history it sent before.

On the Claude API, Anthropic documents a rendering hierarchy of tools, then system, then messages. A change to a loaded tool definition can cut off reuse across all three layers. A timestamp embedded in system leaves the earlier tools eligible. Editing a message can leave both earlier layers eligible. Anthropic writes at breakpoints, so a surviving stretch of stable content can only be read if an earlier request wrote a matching entry and the lookup reaches it. Anthropic prompt caching

OpenAI describes matching against the rendered prefix as well, with cache boundaries that depend on the model and mode. Its current guide includes tool definitions, developer messages and multimodal history in the rendered context. It also lists settings such as reasoning.effort that can change what the model sees even when your visible messages stay the same. Compare the settings with the messages when you investigate. Provider behavior throughout this guide is as of November 30, 2026. OpenAI prompt caching

DeepSeek documents a different storage and lookup mechanism. Its cache needs a full match on a previously stored prefix unit. If two independent questions share a leading reference document, the system can detect that shared prefix and store it for a later request, even if the second request did not get a hit. When testing a DeepSeek integration, compare prompt_cache_hit_tokens and prompt_cache_miss_tokens across several calls with the same leading material. The provider describes matching as best effort, so a single miss provides limited evidence of a client-side change. DeepSeek context caching

Map common changes to the affected layer

The layer column uses Anthropic’s hierarchy where applicable and names OpenAI separately. A layer change tells you where to look for the first lost match. The cost depends on which earlier boundary still hits and whether the changed portion is billed as a new write or as ordinary input.

CauseLayer or boundary affectedHow to detect itFix
Timestamp or per-request UUID injected into fixed instructionsClaude system and later content. Early OpenAI developer instructions can have the same problem.Compare the actual instruction text between adjacent calls. Look for request IDs, clocks and per-turn template variables.Keep trace IDs in application telemetry. Put changing facts the model needs after the reusable prefix.
Same tools in a new order, or different JSON key order in a schemaClaude tools and following layers. OpenAI also lists tool order as a prefix-affecting change.Compare ordered tool names, then compare serialized schemas. A set of tool names hides order drift.Resolve duplicate names consistently, sort the final tool list and serialize application-owned schemas deterministically.
Tool added or removed mid-sessionLoaded tool definitions. Claude Code can keep its initial tool list when tool search is active.Compare tool names around an MCP connection, removal or permission change.Keep tool membership fixed or use supported deferred tool loading. On OpenAI, keep the definitions and set tool_choice to "none" to disable tools for a request.
Claude tool choice or parallel tool use changesClaude messages cache.Compare tool_choice and disable_parallel_tool_use during replay.Keep both settings fixed across the loop when possible. If tool choice must vary, use a breakpoint before the affected messages to preserve an eligible earlier prefix.
Model switch or router fallbackModel-specific cache.Log the model each request actually uses and check Claude diagnostics for model_changed.Pin the model where the workflow allows and measure fallback calls separately.
Thinking or effort switchClaude message layer and, depending on model and setting, earlier layers. OpenAI reasoning effort can change rendered instructions.Diff thinking, output_config.effort or the OpenAI reasoning.effort value before diffing text.Keep thinking configuration stable. On supported GPT-6 and later Responses API models, keep request-level reasoning.effort fixed and append a configuration_update input item. On Claude models that support per-message effort, send the change in a role: "system" message inside messages. If a request-level effort change is required, test which earlier boundaries still match.
Claude fast mode toggleClaude system and message caches.Compare speed and correlate the miss with a speed change, including a Claude Code fallback to standard speed.Keep speed stable during a run you want to compare.
Images added, removed or evictedClaude messages. Image input can also be part of OpenAI’s rendered prefix.Compare which image blocks are present and where the first changed image occurs.Replay retained images unchanged. If an old image must be removed, measure the rebuild from the affected history.
Rewind, truncation or compactionMessage history from the first changed block. An unchanged rewind can still hit an earlier entry.Compare replayed blocks before and after the action and see whether an earlier entry was written.Use append-only history between planned edits. Measure compaction as a separate event.
Dropped thinking blocks or replayed tool results with different serializationClaude messages from the first changed block.Compare prior assistant content and tool results, including block order and keys in tool_use.Replay provider-returned history unchanged and account for the chosen model’s thinking preservation behavior.
Gateway strips cache_control or flattens marked system contentCache placement in the forwarded Claude request.Check the provider-bound request shape and compare reads and writes on consecutive calls.Preserve top-level and block-level markers where used, and preserve marked content blocks through conversion.

The distinction between a tool list change and a schema encoding change is useful when the tool count stays fixed. Anthropic’s diagnostics docs explicitly call out nondeterministic input_schema serialization. Its prompt caching guide also calls out unstable key order inside tool_use blocks. The first problem starts at tool definitions. The second can first appear after many turns, when a client replays an existing tool call differently. Sorting discovery output addresses the former ordering problem. Preserving recorded assistant blocks through replay addresses the latter. Anthropic cache diagnostics · Tool use with prompt caching

There are important exceptions for intentional changes. Claude Code’s /rewind keeps the earlier history unchanged and can reuse the entry at that point while it is warm. Compaction replaces the conversation with a summary and rebuilds the shorter conversation cache afterward. Likewise, Anthropic documents model-specific effort behavior, and setting the model’s default effort explicitly is equivalent to omitting it for cache invalidation. Measure these paths separately so a deliberate rebuild does not obscure a cache miss on an ordinary turn. Claude Code prompt caching · Anthropic prompt caching

Read issue reports as request-level evidence

Claude Code issue #112901 was opened November 28, 2026 and was open as of November 30, 2026. The reporter describes a first deferred MCP tool load that reordered the sent tool array, moving a non-deferred tool and producing a tools_changed diagnostic. The same report describes media eviction rewriting earlier history and dropping later thinking. Those observations point to different inspection points. One starts with the provider-bound tool list, while the other starts at the first rewritten history block. The report is useful alongside the documented deferred-loading mechanism, where tool search normally appends a reference in the conversation and leaves the prefix intact. Claude Code issue #112901 · Anthropic tool search

OpenCode issue #67040 was opened November 28, 2026 and was closed as of November 30, 2026. Its author reports that a plan-mode reminder moved from before the first user message on the initial request to after it on the next request. Using a logging proxy in front of a local llama-server, the reporter found that the second plan-mode request matched only through the system prompt, covering 25,690 of 26,257 characters. Requests 3 to 5 matched again. When a spike occurs only on the second request, compare the transition from session initialization to ordinary replay. A repeated miss on every request calls for examining values that change on each send. OpenCode issue #67040

Reproduce the miss with a controlled request pair

Suppose a coding agent puts its tool list and project instructions before a cache breakpoint. It then appends the new user request. On the next call, the visible workflow is the same but cache reads collapse. Start with a replay fixture close enough to the original that the tool list, instructions and prior content go through the same serializer and adapter.

  1. Establish a warm control. Start with a fresh test prefix. On Claude, put a single explicit breakpoint at the end of the stable system instructions and make sure the marked prefix meets the model minimum. Then append a message and send the second request within the configured lifetime. Keep model, connection and prompt-affecting options fixed. Record cache_read_input_tokens, cache_creation_input_tokens and input_tokens together.
  2. Change one thing. Insert a per-request ID into the existing system text and compare again. Expect zero cache reads and a fresh write of the whole marked prefix. The lookback can find only previously written entries, and this control wrote none at the tools boundary. To test a surviving tools read, repeat from the warm-up with a second breakpoint at the end of the tools and confirm an eligible write there before editing system. Move the ID into telemetry, or append it in fresh content if the model needs it, and re-run the control.
  3. Check the API’s view. Where Anthropic cache diagnostics are available, send diagnostics.previous_message_id as null on the first call and pass the preceding response’s id on the next. The comparison reports the earliest divergence. Fix that first and repeat because later changes can be hidden behind it. On OpenAI, compare reported cached_tokens alongside the rendered inputs you can inspect and the eligible boundaries for that model.
  4. Trace the gateway if the stable control fails. Compare marker positions and content block shapes on both sides. A successful response alone says little about caching. If marker placement survives, check the model minimum, expiry, platform scope and whether the old write is within reach of the current lookup.

In this test, a cache creation spike suggests the provider has something new to write, while low reads with no writes can point to an ineligible prefix or missing cache controls. Check the combined usage first. A diagnostic estimate of tokens after a divergence indicates the size of the affected portion. Use returned usage for billing. Anthropic cache diagnostics · OpenAI prompt caching

Choose the next fix from the evidence

  • If ordered tool names or schema bytes changed, apply deterministic prompt serialization at the request boundary and replay a discovery-order permutation.
  • If the prefix matches but the old write is out of reach, inspect Anthropic breakpoint placement and check which endpoints earlier calls actually wrote.
  • If you see a model, system, tools or messages divergence, use the Claude cache diagnostics guide to narrow the failing pair before changing multiple inputs.
  • If markers disappear during conversion, follow the gateway caching guide and verify a second request’s usage after repairing the forwarded body.
  • If the loss starts at a planned summary or history replacement, compare the cost of rebuilding with the savings from fewer subsequent input tokens. Context compaction and prompt cache cost

Sources

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.

Silent prompt cache busters and how to find them. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/prompt-cache-invalidation-causes/

Sources