The Claude Code prompt cache: how it works and what resets it / What breaks it
What /compact costs while the cache is active and after it has expired
/compact costs a fraction of what the conversation size suggests while the prompt cache is still active, and it costs the most after the cache has expired. Anthropic's documentation, read on 4 October 2026, explains why: to write the summary, Claude Code sends a separate request with the same system prompt, tools and history as your conversation, plus one instruction at the end. While the cache is still within its lifetime, that request reads the stored start from the cache. After a break longer than the cache lifetime, it reprocesses the full history as uncached input. In both cases the turn after compaction stores only the shorter history. This page compares the two cases and the alternatives.
Published October 4, 2026. Editorial.
Key takeaways
- To write a summary, Claude Code sends a separate request with the same system prompt, tools and history as your conversation, plus one summarisation instruction, by Anthropic's documentation read on 4 October 2026.
- While the cache is still within its lifetime, the summary request reads the stored start from the cache, and Anthropic says /compact then costs a fraction of what the context size suggests.
- After a break longer than the cache lifetime, the summary request reprocesses the full history as uncached input, which is why /compact costs the most on a resumed old session.
- On a Pro or Max plan, resuming a session over 100,000 tokens after a long break opens a dialog, and the next request processes the full history once whichever option you pick.
- /rewind returns to an earlier turn whose start is already stored, so the next request reads the earlier cache entry.
Claude Code is Anthropic's coding tool: you type a request in a terminal, and an AI model reads files, runs commands and edits code. Each message becomes a new request that contains the whole conversation again, counted in tokens, the pieces of text that the model processes. The context window is the largest amount of text the model can read in one request.
Compaction is the step that replaces your conversation history with a summary, so that later requests are smaller. You start it with the /compact command, and Claude Code also runs it automatically when the context window is close to full.
The prompt cache is a store of request text that the service has already processed. When the start of a new request matches the stored text exactly, the service reads that part from the store at a lower price. Anthropic's name for the start of a request is the prefix.
Compaction has its own cost, and the cache decides how large that cost is. This page explains the two cases. It belongs to the guide to the Claude Code prompt cache. The general question of which command to use is answered on the related guide's page about /clear, /compact and /rewind.
What /compact sends to the model
A summary has to be written by the model, and the model can only summarise text that it receives. Anthropic's documentation, read on 4 October 2026, describes the request: "To produce the summary, Claude Code sends a separate request with the same system prompt, tools, and history as your conversation, plus a summarization instruction appended as a final user message." [1]
Two facts follow from that sentence.
First, the request contains the whole conversation. Anthropic's page on costs says the same thing from the point of view of usage: "/compact reads the conversation it summarizes, so compacting a large context is itself a large request." [5]
Second, the request has the same start as your normal turns. The system prompt (Anthropic's instructions), the tool definitions and the history are identical, and the only new text is one instruction at the end. A request with the same start can read the stored copy, if a stored copy still exists.
One more detail affects the output side. As of v2.1.198, the summary request uses your session's extended thinking setting, so the model reasons before it writes the summary when your session has thinking enabled. Your session settings are unchanged afterward [3]. Extended thinking is the reasoning the model writes before it answers.
Compacting while the cache is still active
Anthropic uses the word warm for a cache that is still within its lifetime, and cold for one whose stored copy has expired. The lifetime restarts each time a request reads the stored copy, so the cache stays warm while you keep working [1].
For the warm case, the documentation says: "While the cache is warm, that request reads your prefix from the cache, so a mid-session /compact costs a fraction of what the context size suggests and spends most of its time generating the summary." [1]
In plain words: the whole conversation is sent, and the stored start is billed as cache reads. The new work is the instruction at the end and the summary itself, which is output.
Compacting after the cache has expired
The cold case is the opposite. Anthropic's page says: "After a break longer than the cache lifetime, there is no cache left to read, so the summarization request reprocesses the full history as uncached input. This is why /compact costs the most when you resume an old session." [1] Uncached input is text that is processed without any part of it being read from the store.
The length of "a break longer than the cache lifetime" depends on how you are billed. For the main conversation, Anthropic's default is one hour on a Claude subscription within the plan's included usage, and five minutes with usage credits, an API key or a cloud provider [1]. The page on how long the cache lasts covers those defaults and how to change them.
Warm and cold compaction compared
The first four rows of the table are our summary of Anthropic's caching page, read on 4 October 2026 [1].
| Cache still active (warm) | Cache expired (cold) | |
|---|---|---|
| When it happens | In the middle of a session, while you keep working | After a break longer than the cache lifetime, for example when you resume an old session |
| What the summary request reads from the cache | The stored start: the system prompt, the tools and the history | Nothing. Anthropic's words: "there is no cache left to read" |
| What is processed in full | The summarisation instruction at the end | The full history, as uncached input, and the instruction |
| The turn after compaction | Stores the new, shorter history | Stores the new, shorter history |
| Invented example: 300,000 tokens of history on Claude Sonnet 5.5 | $0.06 as cache reads | $0.60 as base input |
The last row is an invented example with our own arithmetic. Anthropic's pricing page, read on 4 October 2026, lists Claude Sonnet 5.5 at $2 per million base input tokens and $0.20 per million cache read tokens [7]. At those prices, 300,000 tokens cost $0.06 as cache reads and $0.60 as base input, which is ten times as much. Both figures leave out the output tokens of the summary. They are API list prices. Anthropic's pages give no statement of how cache tokens count against the usage limits of a subscription plan.
The turn after compaction stores only the shorter history
A reasonable worry is that the first message after /compact will be slow, because the old stored copy no longer matches. Anthropic answers this directly: "In both the warm and cold cases, the turn after compaction rebuilds the conversation cache for only the much shorter summary, so that turn is not the slow part." [1]
The same page describes what compaction does to each of the three parts of a request [1]. The page on the three layers of a request explains the parts.
- The conversation. Compaction invalidates it by design, which means the stored copy of the old history can no longer be used. The next request "has a new, shorter history that doesn't share a prefix with the old one".
- The system prompt. Claude Code reuses it. There is one exception: a conversation that was resumed while it kept a system prompt that would otherwise have changed. In that case the first compaction changes to the current prompt, and that part is rebuilt once.
- The project context. This is your CLAUDE.md, the file of instructions you write for Claude, and auto memory, the notes Claude saved for itself. Claude Code reloads both from disk, and the reloaded text is read from the cache "only if CLAUDE.md and memory are unchanged since the session started".
The new history is short, and it is more than the summary alone. Anthropic's context window page says that after compaction Claude Code reads again up to five of the files Claude read or edited, most recently modified first, and adds back the body of each skill you used, with a limit of 5,000 tokens per skill and 25,000 tokens in total [3]. A skill is a packaged set of instructions for one task. The related guide's page on /clear, /compact and /rewind lists what is kept.
Two smaller effects are documented. Fast mode, the setting for faster Opus responses at a higher price, has a one-time cache cost per conversation, and /clear and /compact reset that state [1]. And the /usage screen counts a compaction separately: on Claude Code v2.1.251 or later, its Prompt cache (main) line reports a cache miss caused by compaction as an "expected rebuild" [5]. A cache miss is a request that finds no stored copy for some or all of its start. The page on how to check your cache hit rate reads that line.
Resuming an old session: the cost that comes first
The cold case is the one you get when you return to an old session. Anthropic's sessions page, read on 4 October 2026, describes a dialog for this moment. On a Pro or Max plan, when you resume a session that is over 100,000 tokens and has been inactive for what Anthropic calls "more than about an hour", Claude Code opens a dialog before you send your first message [2].
The sentence that matters for cost is about the cache: "The session's prompt cache has expired by then, so the next request processes the full history once no matter which of the dialog's options you pick." [2]
The dialog offers three options [2]:
- Resume from summary runs
/compactimmediately. Claude Code sends one summary request over the full history, then replaces the history with the summary, your most recent exchanges and up to five recently read files. - Resume full session as-is loads the conversation unchanged. After your first message, Claude Code reprocesses the full history and stores it again, then reads it from the cache on later requests while the cache stays warm.
- Don't ask me again resumes the full session and stops showing the dialog.
So the first cost is the same size in both cases: the full history, processed once. The difference is in every request after that. With the summary, later requests contain the summary. With the full session, later requests contain the full history, read from the cache. Anthropic describes the second choice as "a per-request cost that scales with the conversation's size" and the first as costing less on each later request, with the limit that "whatever the summary leaves out is no longer in Claude's context" [2].
/rewind returns to a stored start, and /recap adds to the end
Two commands look similar to /compact and have a different effect on the cache.
/rewind goes back to an earlier turn of the conversation. A turn is one message from you plus the work Claude does in reply. Anthropic's page explains why the cache is kept: "The remaining history is the same content the cache was built from at that point, and the system prompt and project context layers are unchanged, so the next request hits the earlier cache entry." [1] The earlier stored copy is still usable even when that turn was long ago, because each later turn read through it and restarted its lifetime [1].
Anthropic's tip compares the two commands. If you have followed an approach that you want to abandon entirely, use /rewind to return to an earlier turn. Rewinding goes back to a start that is already stored, and compaction builds a new one [1].
You open the rewind menu with /rewind, or by pressing Esc twice when the prompt input is empty. The menu lists the prompts you sent, and for each one it offers to restore the conversation, the code or both [4]. Restoring files together with the conversation "has no separate effect on the cache" [1]. The same menu has two summarise options, which Anthropic's checkpointing page describes as "like a targeted /compact" [4].
/recap writes a short summary for you to read. Anthropic's page says: "Unlike /compact, it appends the summary as command output", and the history stays in place, "so the cached prefix stays intact" [1].
When automatic compaction runs
Claude Code compacts by itself when the conversation is close to the limit of the context window. Anthropic's context window page says the automatic step "works the same way as the /compact step" [3].
The point where it runs depends on the model. Anthropic's model configuration page, read on 4 October 2026, says that if you have not set a window yourself, Claude Code compacts when the conversation reaches the model's context limit, with listed exceptions. One exception is models that run with a 1 million token window: they compact before the window is full, and Anthropic puts the default point at 967K tokens [6]. You can set your own point with the /autocompact command, for example /autocompact 500k [6].
The problem with the automatic step is its timing. Anthropic's tip says: "To choose when its overhead happens, run /compact at a natural break in your work, such as between tasks, instead of waiting for auto-compaction to trigger mid-task." [1]
Our position
Run /compact yourself, at a break between tasks, while the cache is still warm. That is the case Anthropic describes as costing "a fraction of what the context size suggests" [1]. Reveneau recommends four rules, each taken from the facts above.
- If you will continue a long conversation after a long break, compact before the break. The summary request then reads the stored start. After a break longer than the cache lifetime, the same request processes the full history as uncached input.
- To abandon an approach, use
/rewind. It returns to a start that is already stored. - To start unrelated work, use
/clear, the command that starts a new conversation. Anthropic's page on costs says that when you want to start again instead of continuing,/clearcosts nothing [5]. - When the resume dialog appears, choose by what comes next. The first request processes the full history in both cases. The summary makes each later request smaller, and the full session keeps each detail.
Reveneau is an AI software development consultancy. All of its code is written by AI, so token use is a running cost of every Reveneau build, and compaction is part of that cost on a long task. Reveneau is independent of Anthropic. Every statement about the product on this page is Anthropic's own, read on 4 October 2026, and the dollar example is our arithmetic on Anthropic's list prices.
Common questions
What does Claude Code send to the model when it compacts a conversation?
When it compacts a conversation, Claude Code sends a separate request with the same system prompt, tools and history as your conversation, plus a summarisation instruction added as a final user message. That is Anthropic's documentation, read on 4 October 2026. Anthropic's page on costs adds that `/compact` reads the conversation it summarises, so compacting a large context is itself a large request.
Why does /compact cost less while the prompt cache is still active?
`/compact` costs less while the prompt cache is still active because the summary request has the same start as your normal turns and reads it from the cache. Anthropic's documentation, read on 4 October 2026, says a `/compact` in the middle of a session costs a fraction of what the context size suggests and spends most of its time generating the summary. In our invented example, 300,000 tokens cost $0.06 as cache reads on Claude Sonnet 5.5.
Why does /compact cost the most on an old session?
`/compact` costs the most on an old session because the stored copy of the conversation has expired. Anthropic's documentation, read on 4 October 2026, says that after a break longer than the cache lifetime there is no cache left to read, so the summary request reprocesses the full history as uncached input. For the main conversation, the default lifetime is one hour on a Claude subscription within plan usage and five minutes with an API key.
Is the first message after /compact slow?
No. The first message after `/compact` stores only the new, shorter history. Anthropic's documentation, read on 4 October 2026, says that the turn after compaction rebuilds the conversation cache for only the much shorter summary, whether the cache was still active or had expired when you compacted. The cost of compaction is in the summary request itself, which contains the whole conversation.
Does /compact reset the system prompt part of the cache?
No, in the normal case. Anthropic's documentation, read on 4 October 2026, says compaction invalidates the conversation part by design and that Claude Code reuses the system prompt part. The exception is a conversation that was resumed while it kept a system prompt that would otherwise have changed. There, the first compaction changes to the current prompt, and the system prompt part is rebuilt once.
Is CLAUDE.md read from the cache after /compact?
CLAUDE.md is read from the cache after `/compact` only when the file has stayed the same during the session. Anthropic's documentation, read on 4 October 2026, says compaction reloads the project context from disk, and that the reloaded text is a cache hit only if CLAUDE.md and memory are unchanged since the session started. Project context here means your CLAUDE.md instruction file and auto memory, the notes Claude saved for itself.
Why does /rewind keep the cache when /compact builds a new one?
`/rewind` keeps the cache because it returns to an earlier turn whose start is already stored. Anthropic's documentation, read on 4 October 2026, says the remaining history is the same content the cache was built from at that point, so the next request reads the earlier cache entry. Compaction creates a new, shorter history that shares no start with the old one. Anthropic's tip is to use `/rewind` when you want to abandon an approach entirely.
Does running /recap reset the prompt cache?
No. Running `/recap` keeps the prompt cache. Anthropic's documentation, read on 4 October 2026, says `/recap` adds its summary to the conversation as command output and the message history stays in place, so the cached prefix stays intact. `/compact` is the command that replaces the history with a summary, and that replacement is what invalidates the conversation part of the cache.
How does the /usage screen count a compaction?
The `/usage` screen counts a compaction as an expected rebuild, separately from other cache misses. Anthropic's page on costs, read on 4 October 2026, says the `Prompt cache (main)` line reports a miss caused by compaction under that name. The line requires Claude Code v2.1.251 or later. A cache miss is a request that finds no stored copy for some or all of its start.
Does the summary request use extended thinking?
Yes, when your session has extended thinking enabled. Anthropic's context window page, read on 4 October 2026, says that as of v2.1.198 the summary request for compaction uses your session's extended thinking setting. Extended thinking is the reasoning the model writes before it answers. The model therefore reasons before it writes the summary when thinking is on in your session, and your session settings are unchanged afterward.
Does automatic compaction work differently from /compact?
No. Automatic compaction works the same way as the `/compact` step, by Anthropic's context window page, read on 4 October 2026. Claude Code runs it by itself when the conversation is close to the limit of the context window. What differs is the timing, which Claude Code chooses. Anthropic's tip is to run `/compact` yourself at a natural break in your work, such as between tasks, so that you choose when its cost happens.
Does resuming from a summary avoid processing the full history?
No. Resuming from a summary still processes the full history once. Anthropic's sessions page, read on 4 October 2026, says the session's prompt cache has expired by the time the resume dialog appears, so the next request processes the full history once whichever option you pick. The saving comes afterward: later requests contain the summary, while a session resumed in full sends the full history on each request, read from the cache.
References
- Anthropic, How Claude Code uses prompt caching (code.claude.com), read 4 October 2026
- Anthropic, Manage sessions (code.claude.com), read 4 October 2026
- Anthropic, Explore the context window (code.claude.com), read 4 October 2026
- Anthropic, Checkpointing (code.claude.com), read 4 October 2026
- Anthropic, Manage costs effectively (code.claude.com), read 4 October 2026
- Anthropic, Model configuration (code.claude.com), read 4 October 2026
- Anthropic, Pricing (platform.claude.com), read 4 October 2026
More in What breaks it
The nine actions that reset the Claude Code prompt cache
Nine actions reset the Claude Code prompt cache, by Anthropic's documentation read on 4 October 2026: switching models, changing effort level, turning on fast mode, connecting or removing an MCP server, enabling or disabling a plugin, denying an entire tool, compacting the conversation, accumulating many images, and upgrading Claude Code. Each one can make the next request miss part or all of the stored text, which Anthropic describes as a one-time slower, more expensive turn. A model switch recomputes the whole request. An MCP server change and a tool deny rule keep the cache while tool search is on. This page lists what each action recomputes, the version notes, and how to avoid the cost.
What switching model or effort level in the middle of a task costs
Switching the model in the middle of a Claude Code task makes the next request read the entire conversation history with no cache hits, because each model has its own cache. That is Anthropic's documentation, read on 4 October 2026. Changing the effort level has the same result on most models, and keeps the cache on Opus 5.5, Sonnet 5.5 and Fable 5.1 with an API key or a Claude subscription. In Anthropic's own sample, a switch from Sonnet 5 to Opus 5 with 182,340 tokens of context has an estimated cache write cost of $1.1396. This page covers the confirmation prompt, the PreModelSwitch hook, the switches that happen without /model, and fast mode.