prompt caching · 8 min read · 2026-07-10

Anthropic prompt caching, explained: TTLs, pricing, and the prefix rule

Prompt caching is the single biggest cost and latency lever on the Claude API: up to ~90% cheaper input and dramatically faster long-prompt responses. It's also easy to silently get zero benefit from. This is a compact, engineer-oriented reference: the one invariant, the pricing, the break-even math, and the mistakes that zero your hit rate.

The one invariant: exact prefix match

Everything about prompt caching follows from one rule: the cache is a prefix match on the exact bytes of your rendered prompt. The request is rendered in a fixed order, toolssystemmessages, and the cache key is derived from those bytes up to each cache_control breakpoint. One byte changed at position N invalidates everything at and after N.

That's why appending a new message to a conversation is cheap (the prefix is untouched; only the tail is new), while editing your system prompt or reordering a tool is expensive (the change happens early, so everything downstream re-processes). And because the cached artifact is the model's internal state, the key also includes the model itself. See why switching models mid-session breaks the cache.

Pricing: writes cost extra, reads are 90% off

From Anthropic's prompt caching documentation:

OperationMultiplierExample @ $3/M input (Sonnet)
Uncached input$3.00 / M tokens
Cache write, 5-min TTL1.25×$3.75 / M
Cache write, 1-hour TTL$6.00 / M
Cache read~0.1×$0.30 / M

Break-even math

The TTL is refreshed every time the cache is read, so an active coding session keeps itself warm indefinitely. The 5-minute clock only matters when you walk away.

Mechanics worth memorizing

Not all changes are equal: the invalidation hierarchy

The API caches in tiers (tools, system, messages). A change only invalidates its own tier and everything after it:

You changed…What survives
Message content (appended a turn)Tools + system + all prior turns
tool_choice, images, thinking toggleTools + system
System prompt textTools only
Tool definitions (add/remove/reorder)Nothing
The modelNothing

Silent cache killers (the audit list)

If cache_read_input_tokens is zero on repeated, seemingly-identical requests, one of these is almost always the culprit:

The fix is always the same: keep stable content first, make it byte-deterministic, and push volatile content (timestamps, the user's actual question) after the last breakpoint.

Verifying: read the usage block

"usage": {
  "input_tokens": 512,                    // uncached remainder, full price
  "cache_creation_input_tokens": 2048,    // written this request (1.25x)
  "cache_read_input_tokens": 145600       // served from cache (0.1x)
}

Total prompt size is the sum of all three. A healthy long-running agent shows a large cache_read_input_tokens, a small write, and a tiny uncached remainder. In Claude Code, this is why marathon sessions are affordable at all. Anthropic's team calls prompt caching "everything" for agentic products, and Claude Code enables it by default.

What this means for day-to-day agent use

Multiple models, every cache warm

Model Shift runs each Claude/Codex model in its own persistent tab. Shift between them like gears without ever rebuilding a cache.

Get Model Shift for Mac ⇣

Further reading: Why switching models mid-session breaks your prompt cache · A cache-safe multi-model workflow