What Is Claude Prompt Caching and How Does It Save Tokens?
Claude prompt caching reuses processed conversation context at a fraction of the cost. Here's how prefix matching and cache expiry actually work.

What is Claude prompt caching?
Claude prompt caching is a mechanism that lets Claude reuse parts of a conversation it has already processed instead of reprocessing the entire chat history on every single message. Normally, every time you send Claude a new message, the model has to reread your full conversation from the start: system instructions, connected tools, every file you’ve shared, and every prior exchange. Caching stores that processed context so only the new part of the conversation needs full attention, and Anthropic charges a steep discount, roughly a tenth of the normal input price, for anything served from cache.
TL;DR
- Claude reprocesses your entire conversation on every message by default, which is why long sessions burn through usage limits far faster than the length of your actual questions would suggest.
- Prompt caching stores already-processed context so Claude only has to work through what’s new, and that cached input is billed at a fraction of the standard token price.
- Prefix matching means the cache only works if the start of your conversation stays identical, so changing a model, a tool, or an early instruction mid-session invalidates everything cached after that point.
- Switching to a cheaper model mid-task can cost more overall, not less, because the new model has no cache of its own and has to rebuild the entire context from scratch.
- Cached context expires, staying warm for about an hour on a Claude subscription session and for a much shorter window (minutes) via the API, after which the next message pays full price again.
- Anthropic’s own Claude Code team monitors cache hit rate as an operational metric, treating frequent cache misses as a problem worth fixing because high hit rates let them offer more generous usage limits.
- Keeping sessions clean and models fixed for the duration of a task is the main lever developers have for keeping cache hit rates high and costs low.
How does prompt caching actually work?
Large language models like Claude don’t retain memory between messages the way a person does. Each time you hit enter, the entire conversation (your instructions, any files, every prior turn) gets sent back to the model and reprocessed as if for the first time. For short chats this barely matters. For long sessions involving large files or many back-and-forth turns, the model ends up reading tens of thousands or even hundreds of thousands of tokens on every single message, even if your new question is one sentence long.
Prompt caching addresses this by letting Claude store the computed representation of a chunk of conversation rather than redoing that work each time. On your next message, Claude checks whether the beginning of the conversation matches what’s already in its cache. If it does, that portion is billed and processed as “cached input” instead of fresh input, at a steep discount versus the standard rate.
This is why the ratio of tokens read to tokens written in a typical coding session can be extremely lopsided. Read-heavy workflows, where Claude is reasoning over a large codebase or document and producing a comparatively short answer, are exactly the kind of workload caching was designed to make affordable.
What is prefix matching and why does it matter?
The cache only applies to what’s called the prefix: the portion of the conversation that comes first and stays fixed, including system instructions, connected tools, and earlier messages in a session. Claude can only reuse a cached prefix if everything from the top of the conversation down to that point is byte-for-byte identical to what was cached before.
That constraint has a practical consequence: change anything near the start of the conversation, such as the model you’re using, an added tool, or an edited instruction, and every token after that change has to be reprocessed at full price. It doesn’t matter if the actual content you’re asking about is near the end of the chat. The cache breaks at the first point of difference, and everything downstream of that point loses its discount.
This also explains why each model keeps its own separate cache. Claude Opus and Claude Haiku don’t share a cached context, so switching models mid-session means the new model has to process the entire prior conversation from zero. An engineer on the Claude Code team has pointed out that this makes mid-session model switching counterintuitive: swapping to a cheaper model to save money on one answer can end up costing more overall, because you lose the cache discount on everything that came before.
Why does switching models or tools mid-session cost more?
Because of prefix matching, any change to the fixed early part of a conversation forces a full cache rebuild. Two habits trigger this most often:

Remy.
Switching models partway through a session. Each model has its own cache. Moving from one model to another mid-task, even to a smaller and cheaper one, means that cheaper model has to read the full prior conversation uncached before it can answer. The per-token savings on the new model’s output rarely offsets the cost of reprocessing everything that came before.
Adding a tool or connected app mid-session. Tools get loaded into the context up front, as part of the prefix. Connecting a new tool partway through a task changes that prefix and invalidates the cache from that point forward, even if the rest of the conversation is untouched.
The practical fix for both is the same: decide on your model and your tools before you start a task, and don’t change either until the task is done. If a smaller task genuinely calls for a cheaper or different model, handing it to a subagent or a fresh session preserves the cache in the main conversation, since a subagent runs its own separate context and cache rather than disturbing the one you’ve already built.
How long does a cached prompt stay valid?
Cached context isn’t permanent. It expires after a period of inactivity, and the expiry window differs depending on how you’re accessing Claude. On a Claude subscription, the cache generally stays warm for about an hour after your last message. Through the API, the window is much shorter, on the order of minutes. Once the cache expires, the next message has to reprocess the full conversation from scratch and pay full price for it, even if nothing in the conversation actually changed.
This matters most for long working sessions where you step away. A session left idle past the expiry window effectively “goes cold,” and the next message you send pays the full reprocessing cost, which on a large session (hundreds of thousands of tokens) can be a noticeable jump compared to the cost of sending a quick message to keep the cache warm.
Is prompt caching something developers need to manage manually?
To an extent, yes, though the mechanism itself is automatic. Claude checks for a matching prefix on every request and applies the cached-input discount whenever one exists; there’s no separate caching API call required for basic use. What requires attention is behavior: keeping the start of a conversation stable, not swapping models or tools mid-task, and being aware that idle time eventually invalidates the cache.
Anthropic’s Claude Code team treats cache hit rate as a metric worth watching closely, reportedly setting up internal alerts for when cache misses spike, because consistently high hit rates are part of what allows them to offer more generous usage limits on subscription plans. For anyone building on the API or running long Claude Code sessions, the same logic applies at a smaller scale: a high cache hit rate translates directly into lower cost and more headroom before hitting a usage limit.
Frequently Asked Questions
What counts as “cached input” in Claude’s pricing?
Cached input refers to tokens from a prior part of the conversation that Claude can reuse from cache rather than reprocess from scratch. It’s billed at a fraction of the standard input token rate, since the model doesn’t have to do fresh computation on that portion of the context.
Everyone else built a construction worker.
We built the contractor.
One file at a time.
UI, API, database, deploy.
Does prompt caching work the same way on the API and on Claude subscriptions?
The underlying prefix-matching mechanism is the same, but the cache expiry window differs: subscription sessions tend to stay cached for roughly an hour of inactivity, while API caches expire much faster, typically within a few minutes.
Why does changing one instruction early in a conversation break the whole cache?
Because the cache is matched as a prefix, meaning everything from the start of the conversation up to a given point has to be identical to what was cached before. Editing an early instruction changes that prefix, so everything after the edit point loses its cached status and gets reprocessed at full price.
Does every Claude model share the same cache?
No. Each model maintains its own cache. Switching models mid-session means the new model has no cached version of the prior conversation and has to process it in full before continuing.
Is it better to use subagents instead of switching models mid-task?
Generally yes, because a subagent runs in its own session with its own cache, so handing off a smaller or cheaper task to a subagent avoids disturbing the cache built up in the main conversation.
