How Claude Code uses prompt caching
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -65,7 +65,7 @@
[Fast mode](</docs/en/fast-mode>) and standard speed keep separate caches, so after you turn fast mode on or off, the next request can’t use what the other speed cached. The first time you turn fast mode on in a conversation, the next request reads the whole conversation so far uncached at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>). To keep that cost small, turn it on at the start of a session.
* If you turn it on while Claude is working, that turn finishes at standard speed, and you pay for any uncached read on your next turn’s first request.
- * If your current model doesn’t support fast mode, running `/fast` also [switches your model](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
+ * If running `/fast` also [switches your model](</docs/en/fast-mode#toggle-fast-mode>), that model switch starts a fresh cache on its own from the next request in the running turn.
Each later toggle reads uncached whatever the speed you switch to doesn’t have cached. Speed changes Claude Code makes on its own, such as the [fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit and the return to fast mode later, count as toggles too.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -50,7 +50,11 @@
### Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model and Claude Code re-runs the request on that model, the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model and Claude Code re-runs the request on that model, the session continues there.
+
+#### Skills and commands that set a model
+
+When a skill or command’s [`model` value applies](</docs/en/skills#frontmatter-reference>) and differs from the session’s current model, that turn is a model switch. The next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. With `context: fork`, the value goes to a [subagent](</docs/en/skills#run-skills-in-a-subagent>) with its own cache instead.
### Changing effort level
@@ -174,7 +178,7 @@
### Invoking skills and commands
-[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes. A skill or command whose frontmatter names a `model` can be a model switch for that turn.
+[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes. A skill or command whose [`model` value applies](</docs/en/skills#frontmatter-reference>) can be a model switch for that turn.
### Running `/recap`
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -122,7 +122,7 @@
### Compacting the conversation
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one.
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. This invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one.
* **System prompt** : when the conversation’s prompt is current, the next request reads this layer from the cache. If that prompt is out of date, such as after you resume the conversation, Claude Code switches to the current prompt and the next request rebuilds this layer’s cache once.
* **Project context** : Claude Code reloads this layer from disk. It’s cached together with the conversation, so after `/compact` or automatic compaction its cache is rebuilt even if its files are unchanged.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -79,7 +79,7 @@
Mid-session change| Cache| Tool definitions in the next request
---|---|---
A server connects, or a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) adds tools| Invalidated| The new definitions are added
-A server drops out with no action on your part, such as a stdio server’s process exiting| Kept| The server’s definitions stay unchanged. A call to one of its tools returns an error instead of running, unless Claude Code [starts the server again](</docs/en/mcp#stdio-servers-that-exit-or-fail-to-start>) for that call
+A server drops out with no action on your part, such as a stdio server’s process exiting| Kept| The server’s definitions stay unchanged
A remote server [reconnects automatically](</docs/en/mcp#automatic-reconnection>) after its connection drops| Kept, unless a request sent while the server reconnects adds the `WaitForMcpServers` tool, which invalidates the cache once| The server’s definitions stay unchanged. A request sent while the server reconnects can add `WaitForMcpServers` when the conversation hasn’t listed it yet, and the tool then stays listed for the rest of the conversation
You remove a tool on purpose, such as with a deny rule or by disabling its server in `/mcp`| Invalidated| The definition is removed
@@ -124,7 +124,7 @@
[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one.
- * **System prompt** : the next request reads this layer from the cache, unless a resumed conversation kept a system prompt that is now out of date. The first time that conversation is compacted, Claude Code switches it to the current prompt, and the next request rebuilds this layer’s cache once.
+ * **System prompt** : when the conversation’s prompt is current, the next request reads this layer from the cache. If that prompt is out of date, such as after you resume the conversation, Claude Code switches to the current prompt and the next request rebuilds this layer’s cache once.
* **Project context** : Claude Code reloads this layer from disk. It’s cached together with the conversation, so after `/compact` or automatic compaction its cache is rebuilt even if its files are unchanged.
To produce the summary, Claude Code sends a separate request. The request repeats your conversation’s system prompt, tools, and the history being summarized. It ends with a summarization instruction. While the cache is warm, that request reads your prefix from the cache. A mid-session `/compact` then costs a fraction of what the context size suggests and spends most of its time generating the summary. After a break longer than the cache lifetime, there is no cache left to read, so the summarization request reprocesses that history as uncached input. This is why `/compact` costs the most when you [resume an old session](</docs/en/sessions#resume-a-session>). In both the warm and cold cases, the turn after compaction rebuilds the conversation cache for only the much shorter history, so that turn isn’t the slow part.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -145,7 +145,7 @@
## Actions that keep the cache
-These actions either append to the end of the conversation or don’t touch the request at all. Some of them, such as editing CLAUDE.md, keep the cache for the same reason the change doesn’t reach the running session until `/clear`, `/compact`, or a restart.
+These actions either append to the end of the conversation or don’t touch the request at all.
* Editing files in your repository
* Editing CLAUDE.md mid-session
@@ -158,11 +158,11 @@
### Editing files in your repository
-File contents enter context only when Claude reads them, and reads append to the conversation. Editing a file Claude previously read does not retroactively change the earlier read in history. Instead, Claude Code appends a [`<system-reminder>`](</docs/en/glossary#system-reminder>) noting the file changed, and Claude re-reads it if needed.
+When you edit a source file Claude already read, the cached prefix stays intact, because your edit doesn’t change the copy already in the conversation.
### Editing CLAUDE.md mid-session
-Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, on demand. Editing one yourself before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
+When you edit your project-root or user-level CLAUDE.md mid-session, the cached prefix stays intact. Claude Code reads these files at session start and holds them in memory. To reload them, run `/clear` or `/compact`, or restart Claude Code. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, on demand. Editing one yourself before it loads takes effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
### Changing permission mode
@@ -182,7 +182,7 @@
### Rewinding the conversation
-[`/rewind`](</docs/en/checkpointing>) truncates your conversation back to an earlier turn. 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. Every turn since then has read through that prefix, which kept the entry warm even if the original turn was longer ago than the TTL. Restoring file checkpoints alongside the conversation has no separate effect on the cache. File contents enter context only when Claude reads them, the same as editing files in your repository.
+[`/rewind`](</docs/en/checkpointing>) truncates your conversation back to an earlier turn. 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. Every turn since then has read through that prefix, which kept the entry warm even if the original turn was longer ago than the TTL. Restoring file checkpoints alongside the conversation has no separate effect on the cache.
## Resuming a session
Show diff (387 lines)
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -1,10 +1,6 @@
Prompt caching makes Claude Code faster and more cost-efficient. Without caching, the API would reprocess your full history on every turn. With caching, it reuses what it already processed, bills the re-read at the [cached token rate](<https://platform.claude.com/docs/en/about-claude/pricing>), and fully processes only what changed. Claude Code handles prompt caching for you, unless you disable it. It is still useful to know how prompt caching works, because some actions invalidate the cache and make the next response slower and more expensive while it rebuilds. This page covers which actions those are, why some settings wait for a restart to apply, and how to check cache performance when usage looks high.
-##
-
-
-
-How the cache is organized
+## How the cache is organized
Each time you send a message in Claude Code, it makes a new API request. The model doesn’t remember anything between requests, so Claude Code re-sends the full context: the system prompt, your project context, every prior message and tool result, and your new message. New content is appended at the end, which means most of each request is identical to the one before it. Prompt caching is how the API avoids reprocessing the part that didn’t change. The API caches by matching the start of each request, called the prefix, against content it recently processed. On a normal turn, the prefix is the entire previous request and only the latest exchange is new. The match is exact, so a change anywhere in the prefix recomputes everything after it. There is no per-file or per-segment caching. See [how prompt caching works](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#how-prompt-caching-works>) in the API reference for the underlying mechanism. To get the most out of prefix matching, Claude Code orders each request so content that rarely changes between turns comes first:
@@ -14,18 +10,14 @@
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
-A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
+An addition to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
* **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. With an API key or a Claude subscription, the cache stays intact by default on Fable 5.1 and later, Opus 5.5, Sonnet 5.5, and Haiku 5.5. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
-###
-
-
-
-Where the cache lives
+### Where the cache lives
Caching happens server-side, in whichever infrastructure serves your model. Where that is depends on how you authenticate:
@@ -42,11 +34,7 @@
For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
-##
-
-
-
-Actions that invalidate the cache
+## Actions that invalidate the cache
These actions can cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch can feel free until you notice the slower turn that follows.
@@ -60,27 +48,15 @@
* Accumulating many images
* Upgrading Claude Code
-###
-
-
-
-Switching models
+### Switching models
Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model and Claude Code re-runs the request on that model, the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
-###
-
-
-
-Changing effort level
+### Changing effort level
On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. With an API key or a Claude subscription, changing effort keeps the cache on Fable 5.1 and later, Opus 5.5, Sonnet 5.5, and Haiku 5.5. Claude Code [applies the new level](</docs/en/model-config#when-a-new-effort-level-starts>) without asking. On Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration, it works as on most models. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
-###
-
-
-
-Turning on fast mode
+### Turning on fast mode
[Fast mode](</docs/en/fast-mode>) and standard speed keep separate caches, so after you turn fast mode on or off, the next request can’t use what the other speed cached. The first time you turn fast mode on in a conversation, the next request reads the whole conversation so far uncached at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>). To keep that cost small, turn it on at the start of a session.
@@ -89,11 +65,7 @@
Each later toggle reads uncached whatever the speed you switch to doesn’t have cached. Speed changes Claude Code makes on its own, such as the [fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit and the return to fast mode later, count as toggles too.
-###
-
-
-
-Connecting or removing an MCP server
+### Connecting or removing an MCP server
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) defers the session’s MCP tools, the default on supported models:
@@ -113,43 +85,23 @@
When you resume a conversation whose tools load into the prefix, one of its MCP servers can still be connecting as the first request goes out. If the transcript recorded that server’s tool definitions, that request includes them as recorded, so it doesn’t change when the server finishes connecting with the same tools. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
-###
-
-
-
-Enabling or disabling a plugin
+### Enabling or disabling a plugin
When you enable or disable a [plugin](</docs/en/plugins/overview>), what the change costs depends on which component types the plugin provides. The cases below cover each component type, when Claude Code applies the change, and what happens when you disable a plugin again in the same session.
-####
-
-
-
-Plugin components that keep the cache
+#### Plugin components that keep the cache
Claude Code never invalidates the cache for a plugin’s skills, commands, agents, hooks, monitors, or themes. It appends their content after the existing conversation, so the next request pays for that content and still reads everything before it from the cache.
-####
-
-
-
-Plugins that provide MCP servers
+#### Plugins that provide MCP servers
When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or remove an MCP server.
-####
-
-
-
-Code intelligence plugins
+#### Code intelligence plugins
When you enable a [code intelligence plugin](</docs/en/plugins/code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>).
-####
-
-
-
-When plugin changes apply
+#### When plugin changes apply
A change you make in the `/plugin` menu goes through [`/reload-plugins`](</docs/en/plugins/cli-reference#reload-plugins>), which Claude Code runs for you when you close the menu. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
@@ -160,62 +112,38 @@
When `/reload-plugins` runs and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Run `/reload-plugins --force` to apply it anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/plugins/cli-reference#reload-plugins>) and so never cost a full re-read mid-session.
-####
-
-
-
-Plugins you enable and then disable in one session
+#### Plugins you enable and then disable in one session
When you disable a plugin you enabled earlier in the session, Claude Code restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
-###
-
-
-
-Denying an entire tool
+### Denying an entire tool
If you add a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>), Claude can’t call that tool from your next request on, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). That includes a rule you add through `/permissions` in the middle of a turn. When [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) is active, which is the default on supported models, the request’s tool definitions don’t change and the cached prefix survives. When tool search is unavailable or disabled, Claude Code removes the definition from the next request, which invalidates the cache, and so does removing the rule later. Only a deny rule that matches in the tool-name position blocks a tool this way: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, blocks those tools the same way. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
-###
-
-
-
-Compacting the conversation
-
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one. The system prompt and project context layers can stay cached:
+### Compacting the conversation
+
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one.
* **System prompt** : the next request reads this layer from the cache, unless a resumed conversation kept a system prompt that is now out of date. The first time that conversation is compacted, Claude Code switches it to the current prompt, and the next request rebuilds this layer’s cache once.
- * **Project context** : Claude Code reloads this layer from disk. The next request reads it from the cache only if CLAUDE.md and memory are unchanged since the session started.
-
-To produce the summary, Claude Code sends a separate request. The request repeats your conversation’s system prompt, tools, and the history being summarized. It ends with a summarization instruction. While the cache is warm, that request reads your prefix from the cache. A mid-session `/compact` then costs a fraction of what the context size suggests and spends most of its time generating the summary. After a break longer than the cache lifetime, there is no cache left to read, so the summarization request reprocesses that history as uncached input. This is why `/compact` costs the most when you [resume an old session](</docs/en/sessions#resume-a-session>). In both the warm and cold cases, the turn after compaction rebuilds the conversation cache for only the much shorter summary, so that turn isn’t the slow part.
+ * **Project context** : Claude Code reloads this layer from disk. It’s cached together with the conversation, so after `/compact` or automatic compaction its cache is rebuilt even if its files are unchanged.
+
+To produce the summary, Claude Code sends a separate request. The request repeats your conversation’s system prompt, tools, and the history being summarized. It ends with a summarization instruction. While the cache is warm, that request reads your prefix from the cache. A mid-session `/compact` then costs a fraction of what the context size suggests and spends most of its time generating the summary. After a break longer than the cache lifetime, there is no cache left to read, so the summarization request reprocesses that history as uncached input. This is why `/compact` costs the most when you [resume an old session](</docs/en/sessions#resume-a-session>). In both the warm and cold cases, the turn after compaction rebuilds the conversation cache for only the much shorter history, so that turn isn’t the slow part.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
If you leave a long conversation idle while it is on the one-hour TTL, Claude Code can compact it. To turn idle compaction off, set [`idleCompaction`](</docs/en/settings-reference#idlecompaction>) to `false`, which requires Claude Code v2.1.290 or later.
-###
-
-
-
-Accumulating many images
+### Accumulating many images
The API limits how many images and PDFs each request can carry. For the current numbers, see [Request limits](<https://platform.claude.com/docs/en/build-with-claude/vision#request-limits>) in the API docs. Claude Code also caps the total size of the images and PDFs in a request, so large screenshots reach the limit with fewer images than small ones. When the next request would pass either limit, Claude Code removes a batch of the oldest images and PDFs from what it sends, which leaves room for more before it needs to remove any again. Claude can no longer see the removed images. If Claude needs one of them again, share it again. Removing images changes the messages that held them, so the next request reprocesses the conversation from the earliest of those messages onward. Because Claude Code removes a batch at a time, you see one slower turn per batch rather than one with each new screenshot.
-###
-
-
-
-Upgrading Claude Code
+### Upgrading Claude Code
A new Claude Code version typically updates the system prompt or tool definitions, so the first conversation you start after an upgrade builds its cache from the top. [Auto-update](</docs/en/setup#auto-updates>) downloads new versions in the background but applies them on the next launch, never mid-session, so you see this as an uncached first turn after restarting rather than a surprise during a session. Set `DISABLE_AUTOUPDATER=1` to control when upgrades apply.
For what it costs to resume a conversation you started before the upgrade, see Resuming a session.
-##
-
-
-
-Actions that keep the cache
+## Actions that keep the cache
These actions either append to the end of the conversation or don’t touch the request at all. Some of them, such as editing CLAUDE.md, keep the cache for the same reason the change doesn’t reach the running session until `/clear`, `/compact`, or a restart.
@@ -228,83 +156,43 @@
* Rewinding the conversation
* Spawning a subagent
-###
-
-
-
-Editing files in your repository
+### Editing files in your repository
File contents enter context only when Claude reads them, and reads append to the conversation. Editing a file Claude previously read does not retroactively change the earlier read in history. Instead, Claude Code appends a [`<system-reminder>`](</docs/en/glossary#system-reminder>) noting the file changed, and Claude re-reads it if needed.
-###
-
-
-
-Editing CLAUDE.md mid-session
+### Editing CLAUDE.md mid-session
Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, on demand. Editing one yourself before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
-###
-
-
-
-Changing permission mode
+### Changing permission mode
Switching between [permission modes](</docs/en/permission-modes>), such as from Manual to accept edits, does not change the system prompt or tool definitions, so mode changes are cache-safe. The exception is plan mode with the [`opusplan`](</docs/en/model-config#opusplan-model-setting>) model setting, which switches the model between Opus and Sonnet as you enter or leave plan mode. That makes the mode toggle a model switch.
-###
-
-
-
-Changing output style
+### Changing output style
When you switch [output styles](</docs/en/output-styles>) mid-session with [`/output-style`](</docs/en/output-styles#change-your-output-style>), `/config`, or the `outputStyle` setting, Claude uses the new style starting with your next message. Claude Code delivers the new style’s instructions as a message in the conversation, so that request still reads the system prompt and the earlier conversation from the cache. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
-###
-
-
-
-Invoking skills and commands
+### Invoking skills and commands
[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes. A skill or command whose frontmatter names a `model` can be a model switch for that turn.
-###
-
-
-
-Running `/recap`
+### Running `/recap`
[`/recap`](</docs/en/interactive-mode#session-recap>) generates a summary for display in your terminal. Unlike `/compact`, it appends the summary as command output rather than replacing your message history, so the cached prefix stays intact.
-###
-
-
-
-Rewinding the conversation
+### Rewinding the conversation
[`/rewind`](</docs/en/checkpointing>) truncates your conversation back to an earlier turn. 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. Every turn since then has read through that prefix, which kept the entry warm even if the original turn was longer ago than the TTL. Restoring file checkpoints alongside the conversation has no separate effect on the cache. File contents enter context only when Claude reads them, the same as editing files in your repository.
-##
-
-
-
-Resuming a session
+## Resuming a session
When you [resume a session](</docs/en/sessions#resume-a-session>), Claude Code sends the whole conversation again, and the request reads from the cache whatever part of its prefix is unchanged and still within the cache lifetime. The layer table at the top of this page says what changes each layer. The system prompt would change after a Claude Code upgrade or with different [`--append-system-prompt`](</docs/en/cli-reference#system-prompt-flags>) text on the resume. By default, the resumed conversation keeps the system prompt it started with, so its history still sits behind the same prompt, and the change takes effect once the conversation is compacted or in a new conversation. [System prompt flags in resumed conversations](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>) covers the cases where Claude Code rebuilds the prompt on every request instead.
-##
-
-
-
-Cache lifetime
+## Cache lifetime
Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [charges a higher rate for cache writes](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
-###
-
-
-
-Which TTL each request gets
+### Which TTL each request gets
Claude Code decides the TTL per request, and every request falls in one of two fixed buckets:
@@ -320,11 +208,7 @@
Once you go over your plan’s usage limit and Claude Code draws on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code drops the main conversation to the five-minute TTL, which charges a lower rate for cache writes. To keep the one-hour TTL there, choose the TTL yourself.
-###
-
-
-
-Choose the TTL yourself
+### Choose the TTL yourself
You can set a TTL for either bucket. Each control takes `5m` or `1h`, and Claude Code ignores any other value.
@@ -346,11 +230,7 @@
* **[Claude apps gateway](</docs/en/claude-apps-gateway>)** : ask your administrator to request the one-hour TTL in a [gateway policy](</docs/en/claude-apps-gateway-config#one-hour-prompt-cache>)
* **Amazon Bedrock** : prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
-##
-
-
-
-Cache scope
+## Cache scope
In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds your auto memory paths, and the conversation opens with an announcement of the working directory, platform, shell, and OS version. Two sessions in different directories therefore build different prefixes and miss each other’s cache.
@@ -359,11 +239,7 @@
The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, two requests share a cache only when their model, speed, and prefix match. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to move the auto memory location out of the system prompt.
-##
-
-
-
-Check cache performance
+## Check cache performance
Cache performance shows up as two token counts the API reports on every response. The most direct way to watch them live is a [statusline script](</docs/en/statusline>) that reads the `current_usage` object:
@@ -374,11 +250,7 @@
A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For a per-session summary, run `/usage`. After the main conversation’s first response, Claude Code adds a [`Prompt cache (main)` line](</docs/en/costs#prompt-cache-statistics>) to the Session block, showing the session’s hit ratio, miss count, and whether the cache is warm right now. A status line script can read the same numbers from the [`prompt_cache` object](</docs/en/statusline#prompt-cache-fields>). Both require Claude Code v2.1.251 or later. The `Prompt cache (main)` line also names the likely cause of the last miss when Claude Code can identify one, for example `likely cause: tool definitions changed`. The likely-cause text requires Claude Code v2.1.260 or later. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
-##
-
-
-
-Subagents and the cache
+## Subagents and the cache
A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents fall outside the main-conversation TTL bucket, so they get five minutes even on a subscription until you choose a longer one. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. Other requests can also read a prefix that an earlier request cached:
@@ -387,11 +259,7 @@
* **Resumed subagents** : when Claude [resumes a subagent](</docs/en/sub-agents#resume-subagents>), the resumed run’s first request can read the cache the original run warmed.
* **Workflow fan-outs** : in a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code holds all but the first for up to 5 seconds by default, so their first requests can read the prefix that the first agent cached.
-##
-
-
-
-Disable prompt caching
+## Disable prompt caching
Disabling caching is occasionally useful when debugging caching behavior with a specific model or provider. To turn it off, set one of these environment variables to `1`:
@@ -405,11 +273,7 @@
`DISABLE_PROMPT_CACHING_HAIKU` applies to the default Haiku model, the model the `haiku` alias resolves to. It disables caching wherever that model runs, including the main conversation when it is your main model. Covering the main conversation requires Claude Code v2.1.283 or later. The variable also covers a background model you set with the deprecated `ANTHROPIC_SMALL_FAST_MODEL` variable, when that model differs from your main model. A different Haiku version that you pin as your main model keeps caching; set `DISABLE_PROMPT_CACHING` to disable caching for it. `DISABLE_PROMPT_CACHING_SONNET` and `DISABLE_PROMPT_CACHING_OPUS` each apply to the model the `sonnet` or `opus` alias resolves to. If you set any other Sonnet or Opus model ID as your main model, that model keeps caching. For example, a session on `claude-sonnet-5` keeps caching while `sonnet` resolves to `claude-sonnet-5-5`. To disable caching for that model, set `DISABLE_PROMPT_CACHING`. To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
-##
-
-
-
-Related resources
+## Related resources
* [Lessons from building Claude Code: Prompt caching is everything](<https://claude.com/blog/lessons-from-building-claude-code-prompt-caching-is-everything>): the design rationale for plan mode, deferred tool loading, and compaction
* [Explore the context window](</docs/en/context-window>): what loads into context and when
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -85,7 +85,7 @@
[Fast mode](</docs/en/fast-mode>) and standard speed keep separate caches, so after you turn fast mode on or off, the next request can’t use what the other speed cached. The first time you turn fast mode on in a conversation, the next request reads the whole conversation so far uncached at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>). To keep that cost small, turn it on at the start of a session.
* If you turn it on while Claude is working, that turn finishes at standard speed, and you pay for any uncached read on your next turn’s first request.
- * If your current model doesn’t support fast mode, running `/fast` also [switches you to Opus](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
+ * If your current model doesn’t support fast mode, running `/fast` also [switches your model](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
Each later toggle reads uncached whatever the speed you switch to doesn’t have cached. Speed changes Claude Code makes on its own, such as the [fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit and the return to fast mode later, count as toggles too.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -17,7 +17,7 @@
A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
+ * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. With an API key or a Claude subscription, the cache stays intact by default on Fable 5.1 and later, Opus 5.5, Sonnet 5.5, and Haiku 5.5. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -74,7 +74,7 @@
Changing effort level
-On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, you keep the cache when you change effort. Claude Code [applies the new level](</docs/en/model-config#when-a-new-effort-level-starts>) without asking. On Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration, it works as on most models. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. With an API key or a Claude subscription, changing effort keeps the cache on Fable 5.1 and later, Opus 5.5, Sonnet 5.5, and Haiku 5.5. Claude Code [applies the new level](</docs/en/model-config#when-a-new-effort-level-starts>) without asking. On Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration, it works as on most models. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -85,7 +85,7 @@
[Fast mode](</docs/en/fast-mode>) and standard speed keep separate caches, so after you turn fast mode on or off, the next request can’t use what the other speed cached. The first time you turn fast mode on in a conversation, the next request reads the whole conversation so far uncached at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>). To keep that cost small, turn it on at the start of a session.
* If you turn it on while Claude is working, that turn finishes at standard speed, and you pay for any uncached read on your next turn’s first request.
- * If your current model doesn’t support fast mode, enabling fast mode also [switches you to Opus](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
+ * If your current model doesn’t support fast mode, running `/fast` also [switches you to Opus](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
Each later toggle reads uncached whatever the speed you switch to doesn’t have cached. Speed changes Claude Code makes on its own, such as the [fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit and the return to fast mode later, count as toggles too.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -74,7 +74,7 @@
Changing effort level
-On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, you keep the cache when you change effort. Claude Code [applies the new level](</docs/en/model-config#when-a-new-effort-level-starts>) without asking. On Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration, it works as on most models. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -82,7 +82,12 @@
Turning on fast mode
-Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the first request Claude Code sends with fast mode on reads the entire conversation history with no cache hits. Claude Code sets that header once when a turn starts and keeps it for the whole turn, so when you turn fast mode on while Claude is working, the cache miss from the header happens on the first request of your next turn. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. If your current model doesn’t support fast mode, enabling fast mode also switches your model, and that switch starts a fresh cache on its own from the next request in the running turn. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. If you [run out of usage credits](</docs/en/fast-mode#handle-rate-limits>) mid-session, Claude Code retries each rejected fast mode request at standard speed the same way, so this fallback also keeps the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
+[Fast mode](</docs/en/fast-mode>) and standard speed keep separate caches, so after you turn fast mode on or off, the next request can’t use what the other speed cached. The first time you turn fast mode on in a conversation, the next request reads the whole conversation so far uncached at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>). To keep that cost small, turn it on at the start of a session.
+
+ * If you turn it on while Claude is working, that turn finishes at standard speed, and you pay for any uncached read on your next turn’s first request.
+ * If your current model doesn’t support fast mode, enabling fast mode also [switches you to Opus](</docs/en/fast-mode#toggle-fast-mode>). That model switch starts a fresh cache on its own from the next request in the running turn.
+
+Each later toggle reads uncached whatever the speed you switch to doesn’t have cached. Speed changes Claude Code makes on its own, such as the [fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit and the return to fast mode later, count as toggles too.
###
@@ -347,7 +352,12 @@
Cache scope
-In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds your auto memory paths, and the conversation opens with an announcement of the working directory, platform, shell, and OS version. Two sessions in different directories therefore build different prefixes and miss each other’s cache. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot taken at startup matches, since each conversation also carries the branch and recent commits from that snapshot. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to move the auto memory location out of the system prompt and share the system prompt’s cache entry across users and machines.
+In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds your auto memory paths, and the conversation opens with an announcement of the working directory, platform, shell, and OS version. Two sessions in different directories therefore build different prefixes and miss each other’s cache.
+
+ * Sessions you run in parallel in the same directory build matching prefixes and can read each other’s cache.
+ * Sequential sessions share the prefix only when the git status snapshot taken at startup matches, since each conversation also carries the branch and recent commits from that snapshot.
+
+The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, two requests share a cache only when their model, speed, and prefix match. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to move the auto memory location out of the system prompt.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -186,7 +186,7 @@
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
-If you leave a long conversation idle in a terminal session while it is on the one-hour TTL, Claude Code can compact it shortly before the cache expires. To turn idle compaction off, set [`idleCompaction`](</docs/en/settings-reference#idlecompaction>) to `false`, which requires Claude Code v2.1.290 or later.
+If you leave a long conversation idle while it is on the one-hour TTL, Claude Code can compact it. To turn idle compaction off, set [`idleCompaction`](</docs/en/settings-reference#idlecompaction>) to `false`, which requires Claude Code v2.1.290 or later.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -102,7 +102,7 @@
Mid-session change| Cache| Tool definitions in the next request
---|---|---
A server connects, or a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) adds tools| Invalidated| The new definitions are added
-A server drops out with no action on your part, such as a stdio server’s process exiting| Kept| The server’s definitions stay unchanged. A call to one of its tools returns an error instead of running
+A server drops out with no action on your part, such as a stdio server’s process exiting| Kept| The server’s definitions stay unchanged. A call to one of its tools returns an error instead of running, unless Claude Code [starts the server again](</docs/en/mcp#stdio-servers-that-exit-or-fail-to-start>) for that call
A remote server [reconnects automatically](</docs/en/mcp#automatic-reconnection>) after its connection drops| Kept, unless a request sent while the server reconnects adds the `WaitForMcpServers` tool, which invalidates the cache once| The server’s definitions stay unchanged. A request sent while the server reconnects can add `WaitForMcpServers` when the conversation hasn’t listed it yet, and the tool then stays listed for the rest of the conversation
You remove a tool on purpose, such as with a deny rule or by disabling its server in `/mcp`| Invalidated| The definition is removed
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -177,7 +177,12 @@
Compacting the conversation
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer unless the conversation was resumed while keeping a system prompt that would otherwise have changed; in that case the first compaction switches to the current prompt and that layer rebuilds once. It reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-a-session>). 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.
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer: the next request has a new, shorter history that doesn’t share a prefix with the old one. The system prompt and project context layers can stay cached:
+
+ * **System prompt** : the next request reads this layer from the cache, unless a resumed conversation kept a system prompt that is now out of date. The first time that conversation is compacted, Claude Code switches it to the current prompt, and the next request rebuilds this layer’s cache once.
+ * **Project context** : Claude Code reloads this layer from disk. The next request reads it from the cache only if CLAUDE.md and memory are unchanged since the session started.
+
+To produce the summary, Claude Code sends a separate request. The request repeats your conversation’s system prompt, tools, and the history being summarized. It ends with a summarization instruction. While the cache is warm, that request reads your prefix from the cache. A mid-session `/compact` then costs a fraction of what the context size suggests and spends most of its time generating the summary. After a break longer than the cache lifetime, there is no cache left to read, so the summarization request reprocesses that history as uncached input. This is why `/compact` costs the most when you [resume an old session](</docs/en/sessions#resume-a-session>). In both the warm and cold cases, the turn after compaction rebuilds the conversation cache for only the much shorter summary, so that turn isn’t the slow part.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
@@ -330,7 +335,11 @@
5. `ENABLE_PROMPT_CACHING_1H=1`, which requests one hour for both buckets
6. The default for the request’s bucket
-Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). To confirm which TTL your main conversation’s cache writes used, run `claude -p "hello" --output-format json` and read `usage.cache_creation` in the result. Claude Code reports one-hour cache writes under `ephemeral_1h_input_tokens` and five-minute cache writes under `ephemeral_5m_input_tokens`. Through an LLM gateway you set with `ANTHROPIC_BASE_URL`, part of the one-hour request travels in the `anthropic-beta` header, so configure the gateway to [forward that header unchanged](</docs/en/llm-gateway-protocol#request-headers>). The one-hour TTL isn’t available through the [Claude apps gateway](</docs/en/claude-apps-gateway#availability-and-limitations>). On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
+Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). To confirm which TTL your main conversation’s cache writes used, run `claude -p "hello" --output-format json` and read `usage.cache_creation` in the result. Claude Code reports one-hour cache writes under `ephemeral_1h_input_tokens` and five-minute cache writes under `ephemeral_5m_input_tokens`. To get one hour through a gateway or on Amazon Bedrock:
+
+ * **LLM gateway you set with`ANTHROPIC_BASE_URL`**: part of the one-hour request travels in the `anthropic-beta` header, so configure the gateway to [forward that header unchanged](</docs/en/llm-gateway-protocol#request-headers>)
+ * **[Claude apps gateway](</docs/en/claude-apps-gateway>)** : ask your administrator to request the one-hour TTL in a [gateway policy](</docs/en/claude-apps-gateway-config#one-hour-prompt-cache>)
+ * **Amazon Bedrock** : prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -37,7 +37,7 @@
Claude Code also appends system context mid-conversation, such as file-change notices, and marks that block for caching on every provider and connection unless you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>), in which case that block is sent uncached. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>), a custom `ANTHROPIC_BASE_URL`, or a cloud provider base-URL override such as [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), what stays cached depends on how the gateway handles the [`cache_control` markers](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) Claude Code sends:
* **Forwards them unchanged** : the block and your conversation cache the same as at the provider’s own endpoint.
- * **Rejects the marked request with a`400` error naming `cache_control`**: Claude Code re-sends the request with the marker moved off the block and onto your last conversation message, and keeps it there for the rest of the conversation. The block bills as uncached input; your conversation stays cached.
+ * **Rejects the marked request with a`400` error naming `cache_control`**: Claude Code re-sends the request with the marker moved off the block and onto your last conversation message, and keeps it there until Claude Code exits. The block bills as uncached input; your conversation stays cached.
* **Removes the markers while returning success** : your entire conversation history bills as uncached input on every turn. A gateway that converts block-form system content to a plain string drops the marker the same way.
For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
@@ -93,7 +93,9 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) defers the session’s MCP tools, the default on supported models:
* **Tools deferred** : Claude Code keeps the tool list from the conversation’s first request for the whole conversation, so a server connecting or disconnecting mid-session doesn’t disturb anything already cached. A server that finishes connecting after the first request supplies its tools as deferred definitions that Claude loads on demand.
- * **Tools loaded upfront** : adding a definition invalidates the cache, and so does removing one on purpose. This applies when tool search is [below its `auto` threshold, disabled, or unavailable](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than Opus 4.5, Sonnet 4.5, and Haiku 4.5, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
+ * **Tools loaded upfront** : adding a definition invalidates the cache, and so does removing one on purpose. This applies when tool search is [off or unavailable](</docs/en/mcp#configure-tool-search>), such as on:
+ * Google Cloud’s Agent Platform models earlier than Opus 4.5, Sonnet 4.5, and Haiku 4.5
+ * A Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search
Without tool search, whether a mid-session server change invalidates the cache depends on what changed. For each change, this table gives whether the cache is kept and what happens to the tool definitions in the next request.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -175,7 +175,7 @@
Compacting the conversation
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer unless the conversation was resumed while keeping a system prompt that would otherwise have changed; in that case the first compaction switches to the current prompt and that layer rebuilds once. It reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer unless the conversation was resumed while keeping a system prompt that would otherwise have changed; in that case the first compaction switches to the current prompt and that layer rebuilds once. It reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-a-session>). 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.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
@@ -286,7 +286,7 @@
Cache lifetime
-Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [charges a higher rate for cache writes](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
+Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [charges a higher rate for cache writes](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -179,6 +179,8 @@
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
+If you leave a long conversation idle in a terminal session while it is on the one-hour TTL, Claude Code can compact it shortly before the cache expires. To turn idle compaction off, set [`idleCompaction`](</docs/en/settings-reference#idlecompaction>) to `false`, which requires Claude Code v2.1.290 or later.
+
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -93,7 +93,7 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) defers the session’s MCP tools, the default on supported models:
* **Tools deferred** : Claude Code keeps the tool list from the conversation’s first request for the whole conversation, so a server connecting or disconnecting mid-session doesn’t disturb anything already cached. A server that finishes connecting after the first request supplies its tools as deferred definitions that Claude loads on demand.
- * **Tools loaded upfront** : adding a definition invalidates the cache, and so does removing one on purpose. This applies when tool search is [below its `auto` threshold, disabled, or unavailable](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
+ * **Tools loaded upfront** : adding a definition invalidates the cache, and so does removing one on purpose. This applies when tool search is [below its `auto` threshold, disabled, or unavailable](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than Opus 4.5, Sonnet 4.5, and Haiku 4.5, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
Without tool search, whether a mid-session server change invalidates the cache depends on what changed. For each change, this table gives whether the cache is kept and what happens to the tool definitions in the next request.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -66,7 +66,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model and Claude Code re-runs the request on that model, the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -17,7 +17,7 @@
A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5, Sonnet 5.5, and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
+ * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -74,7 +74,7 @@
Changing effort level
-On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, Haiku 5.5, and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
@@ -284,7 +284,7 @@
Cache lifetime
-Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
+Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [charges a higher rate for cache writes](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
###
@@ -304,7 +304,7 @@
Main conversation| One hour| Five minutes
Everything else| Five minutes, except the server-controlled helper requests, which get one hour| Five minutes
-Once you go over your plan’s usage limit and Claude Code draws on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code drops the main conversation to the cheaper five-minute TTL. To keep the one-hour TTL there, choose the TTL yourself.
+Once you go over your plan’s usage limit and Claude Code draws on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code drops the main conversation to the five-minute TTL, which charges a lower rate for cache writes. To keep the one-hour TTL there, choose the TTL yourself.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -228,7 +228,7 @@
Editing CLAUDE.md mid-session
-Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, when Claude first reads a matching file. Editing one before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
+Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, on demand. Editing one yourself before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -376,11 +376,11 @@
---|---
`DISABLE_PROMPT_CACHING`| Disable for all models
`DISABLE_PROMPT_CACHING_HAIKU`| Disable for the default Haiku model
-`DISABLE_PROMPT_CACHING_SONNET`| Disable for Sonnet only
-`DISABLE_PROMPT_CACHING_OPUS`| Disable for Opus only
+`DISABLE_PROMPT_CACHING_SONNET`| Disable for the default Sonnet model
+`DISABLE_PROMPT_CACHING_OPUS`| Disable for the default Opus model
`DISABLE_PROMPT_CACHING_FABLE`| Disable for Fable only
-`DISABLE_PROMPT_CACHING_HAIKU` applies to the default Haiku model, the model the `haiku` alias resolves to. It disables caching wherever that model runs, including the main conversation when it is your main model. Covering the main conversation requires Claude Code v2.1.283 or later. The variable also covers a background model you set with the deprecated `ANTHROPIC_SMALL_FAST_MODEL` variable, when that model differs from your main model. A different Haiku version that you pin as your main model keeps caching; set `DISABLE_PROMPT_CACHING` to disable caching for it. To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
+`DISABLE_PROMPT_CACHING_HAIKU` applies to the default Haiku model, the model the `haiku` alias resolves to. It disables caching wherever that model runs, including the main conversation when it is your main model. Covering the main conversation requires Claude Code v2.1.283 or later. The variable also covers a background model you set with the deprecated `ANTHROPIC_SMALL_FAST_MODEL` variable, when that model differs from your main model. A different Haiku version that you pin as your main model keeps caching; set `DISABLE_PROMPT_CACHING` to disable caching for it. `DISABLE_PROMPT_CACHING_SONNET` and `DISABLE_PROMPT_CACHING_OPUS` each apply to the model the `sonnet` or `opus` alias resolves to. If you set any other Sonnet or Opus model ID as your main model, that model keeps caching. For example, a session on `claude-sonnet-5` keeps caching while `sonnet` resolves to `claude-sonnet-5-5`. To disable caching for that model, set `DISABLE_PROMPT_CACHING`. To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -17,7 +17,7 @@
A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5 and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
+ * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5, Sonnet 5.5, and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -66,7 +66,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, Sonnet 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
###
@@ -74,7 +74,7 @@
Changing effort level
-On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5 and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5, Sonnet 5.5, and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
@@ -90,10 +90,10 @@
Connecting or removing an MCP server
-Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
-
- * **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : adding a definition invalidates the cache, and so does removing one on purpose. This is the case when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
+Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) defers the session’s MCP tools, the default on supported models:
+
+ * **Tools deferred** : Claude Code keeps the tool list from the conversation’s first request for the whole conversation, so a server connecting or disconnecting mid-session doesn’t disturb anything already cached. A server that finishes connecting after the first request supplies its tools as deferred definitions that Claude loads on demand.
+ * **Tools loaded upfront** : adding a definition invalidates the cache, and so does removing one on purpose. This applies when tool search is [below its `auto` threshold, disabled, or unavailable](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
Without tool search, whether a mid-session server change invalidates the cache depends on what changed. For each change, this table gives whether the cache is kept and what happens to the tool definitions in the next request.
@@ -128,10 +128,7 @@
Plugins that provide MCP servers
-When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or remove an MCP server:
-
- * If Claude Code defers the server’s tools, it keeps the cache.
- * If Claude Code loads them into the prefix, the next request re-reads the entire conversation.
+When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or remove an MCP server.
####
@@ -337,7 +334,7 @@
Cache scope
-In Claude Code, the cache is effectively scoped to one machine and directory. Each conversation carries the working directory, platform, shell, and OS version, and the system prompt names your auto memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot taken at startup matches, since each conversation also carries the branch and recent commits from that snapshot. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
+In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds your auto memory paths, and the conversation opens with an announcement of the working directory, platform, shell, and OS version. Two sessions in different directories therefore build different prefixes and miss each other’s cache. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot taken at startup matches, since each conversation also carries the branch and recent commits from that snapshot. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to move the auto memory location out of the system prompt and share the system prompt’s cache entry across users and machines.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -223,7 +223,7 @@
Editing files in your repository
-File contents enter context only when Claude reads them, and reads append to the conversation. Editing a file Claude previously read does not retroactively change the earlier read in history. Instead, Claude Code appends a `<system-reminder>` noting the file changed, and Claude re-reads it if needed.
+File contents enter context only when Claude reads them, and reads append to the conversation. Editing a file Claude previously read does not retroactively change the earlier read in history. Instead, Claude Code appends a [`<system-reminder>`](</docs/en/glossary#system-reminder>) noting the file changed, and Claude re-reads it if needed.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -48,12 +48,12 @@
Actions that invalidate the cache
-These actions cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch can feel free until you notice the slower turn that follows.
+These actions can cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch can feel free until you notice the slower turn that follows.
* Switching models
* Changing effort level
* Turning on fast mode
- * Connecting or disconnecting an MCP server
+ * Connecting or removing an MCP server
* Enabling or disabling a plugin
* Denying an entire tool
* Compacting the conversation
@@ -88,14 +88,23 @@
-Connecting or disconnecting an MCP server
+Connecting or removing an MCP server
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
-
-When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
+ * **Tools loaded into the prefix** : adding a definition invalidates the cache, and so does removing one on purpose. This is the case when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search.
+
+Without tool search, whether a mid-session server change invalidates the cache depends on what changed. For each change, this table gives whether the cache is kept and what happens to the tool definitions in the next request.
+
+Mid-session change| Cache| Tool definitions in the next request
+---|---|---
+A server connects, or a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) adds tools| Invalidated| The new definitions are added
+A server drops out with no action on your part, such as a stdio server’s process exiting| Kept| The server’s definitions stay unchanged. A call to one of its tools returns an error instead of running
+A remote server [reconnects automatically](</docs/en/mcp#automatic-reconnection>) after its connection drops| Kept, unless a request sent while the server reconnects adds the `WaitForMcpServers` tool, which invalidates the cache once| The server’s definitions stay unchanged. A request sent while the server reconnects can add `WaitForMcpServers` when the conversation hasn’t listed it yet, and the tool then stays listed for the rest of the conversation
+You remove a tool on purpose, such as with a deny rule or by disabling its server in `/mcp`| Invalidated| The definition is removed
+
+When you resume a conversation whose tools load into the prefix, one of its MCP servers can still be connecting as the first request goes out. If the transcript recorded that server’s tool definitions, that request includes them as recorded, so it doesn’t change when the server finishes connecting with the same tools. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
###
@@ -119,7 +128,7 @@
Plugins that provide MCP servers
-When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or disconnect an MCP server:
+When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or remove an MCP server:
* If Claude Code defers the server’s tools, it keeps the cache.
* If Claude Code loads them into the prefix, the next request re-reads the entire conversation.
@@ -369,12 +378,12 @@
Variable| Effect
---|---
`DISABLE_PROMPT_CACHING`| Disable for all models
-`DISABLE_PROMPT_CACHING_HAIKU`| Disable for Haiku only
+`DISABLE_PROMPT_CACHING_HAIKU`| Disable for the default Haiku model
`DISABLE_PROMPT_CACHING_SONNET`| Disable for Sonnet only
`DISABLE_PROMPT_CACHING_OPUS`| Disable for Opus only
`DISABLE_PROMPT_CACHING_FABLE`| Disable for Fable only
-To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
+`DISABLE_PROMPT_CACHING_HAIKU` applies to the default Haiku model, the model the `haiku` alias resolves to. It disables caching wherever that model runs, including the main conversation when it is your main model. Covering the main conversation requires Claude Code v2.1.283 or later. The variable also covers a background model you set with the deprecated `ANTHROPIC_SMALL_FAST_MODEL` variable, when that model differs from your main model. A different Haiku version that you pin as your main model keeps caching; set `DISABLE_PROMPT_CACHING` to disable caching for it. To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -103,7 +103,7 @@
Enabling or disabling a plugin
-When you enable or disable a [plugin](</docs/en/plugins>), what the change costs depends on which component types the plugin provides. The cases below cover each component type, when Claude Code applies the change, and what happens when you disable a plugin again in the same session.
+When you enable or disable a [plugin](</docs/en/plugins/overview>), what the change costs depends on which component types the plugin provides. The cases below cover each component type, when Claude Code applies the change, and what happens when you disable a plugin again in the same session.
####
@@ -119,7 +119,7 @@
Plugins that provide MCP servers
-When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>), Claude Code follows the same rules as when you connect or disconnect an MCP server:
+When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins/components#mcp-servers>), Claude Code follows the same rules as when you connect or disconnect an MCP server:
* If Claude Code defers the server’s tools, it keeps the cache.
* If Claude Code loads them into the prefix, the next request re-reads the entire conversation.
@@ -130,7 +130,7 @@
Code intelligence plugins
-When you enable a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>).
+When you enable a [code intelligence plugin](</docs/en/plugins/code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>).
####
@@ -138,14 +138,14 @@
When plugin changes apply
-A change you make in the `/plugin` menu goes through [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>), which Claude Code runs for you when you close the menu. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
-
- * For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>).
- * When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. The install summary tells you whether it did.
+A change you make in the `/plugin` menu goes through [`/reload-plugins`](</docs/en/plugins/cli-reference#reload-plugins>), which Claude Code runs for you when you close the menu. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
+
+ * For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugins/loading#when-a-command-source-re-runs>).
+ * When you [install a plugin from the `/plugin` interface](</docs/en/plugins/install#install-a-plugin>), Claude Code can activate it during the install. The install summary tells you whether it did.
* When you [move the session with `/cd`](</docs/en/permissions#move-the-session-to-another-directory>) on v2.1.246 or later, Claude Code applies the plugins the new directory’s settings enable as part of the move, without the full re-read warning that holds a `/reload-plugins`.
- * In interactive sessions, when you add or remove a plugin in a [folder of plugins](</docs/en/plugins#test-your-plugins-locally>) you passed with `--plugin-dir`, the change applies right away. If applying it would trigger a full re-read, Claude Code holds the change instead and shows a notice to run `/reload-plugins`. Requires Claude Code v2.1.265 or later.
-
-When `/reload-plugins` runs and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Run `/reload-plugins --force` to apply it anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) and so never cost a full re-read mid-session.
+ * In interactive sessions, when you add or remove a plugin in a [folder of plugins](</docs/en/plugins/create#load-a-directory-or-archive-for-one-session>) you passed with `--plugin-dir`, the change applies right away. If applying it would trigger a full re-read, Claude Code holds the change instead and shows a notice to run `/reload-plugins`. Requires Claude Code v2.1.265 or later.
+
+When `/reload-plugins` runs and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Run `/reload-plugins --force` to apply it anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/plugins/cli-reference#reload-plugins>) and so never cost a full re-read mid-session.
####
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -17,7 +17,7 @@
A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
+ * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Opus 5.5 and Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -66,7 +66,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models, Opus 5.5, and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
###
@@ -74,7 +74,7 @@
Changing effort level
-On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Opus 5.5 and Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
@@ -341,7 +341,7 @@
Field| Meaning
---|---
`cache_creation_input_tokens`| Tokens written to the cache on this turn, billed at the cache write rate
-`cache_read_input_tokens`| Tokens served from cache on this turn, billed at roughly 10% of the standard input rate
+`cache_read_input_tokens`| Tokens served from cache on this turn, billed at the model’s [cached token rate](<https://platform.claude.com/docs/en/about-claude/pricing>), below the standard input rate
A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For a per-session summary, run `/usage`. After the main conversation’s first response, Claude Code adds a [`Prompt cache (main)` line](</docs/en/costs#prompt-cache-statistics>) to the Session block, showing the session’s hit ratio, miss count, and whether the cache is warm right now. A status line script can read the same numbers from the [`prompt_cache` object](</docs/en/statusline#prompt-cache-fields>). Both require Claude Code v2.1.251 or later. The `Prompt cache (main)` line also names the likely cause of the last miss when Claude Code can identify one, for example `likely cause: tool definitions changed`. The likely-cause text requires Claude Code v2.1.260 or later. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -238,7 +238,7 @@
Changing output style
-When you switch [output styles](</docs/en/output-styles>) mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message. Claude Code delivers the new style’s instructions as a message in the conversation, so that request still reads the system prompt and the earlier conversation from the cache. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
+When you switch [output styles](</docs/en/output-styles>) mid-session with [`/output-style`](</docs/en/output-styles#change-your-output-style>), `/config`, or the `outputStyle` setting, Claude uses the new style starting with your next message. Claude Code delivers the new style’s instructions as a message in the conversation, so that request still reads the system prompt and the earlier conversation from the cache. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -270,7 +270,7 @@
Resuming a session
-When you [resume a session](</docs/en/sessions#resume-a-session>), Claude Code sends the whole conversation again, and the request reads from the cache whatever part of its prefix is unchanged and still within the cache lifetime. The layer table at the top of this page says what changes each layer. The system prompt would change after a Claude Code upgrade or with different [`--append-system-prompt`](</docs/en/cli-reference#system-prompt-flags>) text on the resume. By default, the resumed conversation keeps the system prompt it started with, so its history still sits behind the same prompt, and the change takes effect once the conversation is compacted or in a new conversation. [System prompt flags in resumed conversations](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>) covers `--system-prompt-snapshot off` and bare mode, where this doesn’t apply.
+When you [resume a session](</docs/en/sessions#resume-a-session>), Claude Code sends the whole conversation again, and the request reads from the cache whatever part of its prefix is unchanged and still within the cache lifetime. The layer table at the top of this page says what changes each layer. The system prompt would change after a Claude Code upgrade or with different [`--append-system-prompt`](</docs/en/cli-reference#system-prompt-flags>) text on the resume. By default, the resumed conversation keeps the system prompt it started with, so its history still sits behind the same prompt, and the change takes effect once the conversation is compacted or in a new conversation. [System prompt flags in resumed conversations](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>) covers the cases where Claude Code rebuilds the prompt on every request instead.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -66,7 +66,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm and the new model isn’t the one that produced the last response. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
###
@@ -161,7 +161,7 @@
Denying an entire tool
-Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Claude Code loads built-in tool definitions into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. Claude Code applies the change on the next request, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). That includes a rule you add through `/permissions` in the middle of a turn. Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+If you add a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>), Claude can’t call that tool from your next request on, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). That includes a rule you add through `/permissions` in the middle of a turn. When [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) is active, which is the default on supported models, the request’s tool definitions don’t change and the cached prefix survives. When tool search is unavailable or disabled, Claude Code removes the definition from the next request, which invalidates the cache, and so does removing the rule later. Only a deny rule that matches in the tool-name position blocks a tool this way: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, blocks those tools the same way. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -34,7 +34,7 @@
* **Microsoft Foundry** : depends on the deployment’s [hosting option](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>). Hosted on Azure deployments are served on Azure infrastructure; Hosted on Anthropic deployments are served on Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
-Claude Code also appends system context mid-conversation, such as file-change notices, and marks that block for caching on every provider and connection. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>), a custom `ANTHROPIC_BASE_URL`, or a cloud provider base-URL override such as [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), what stays cached depends on how the gateway handles the [`cache_control` markers](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) Claude Code sends:
+Claude Code also appends system context mid-conversation, such as file-change notices, and marks that block for caching on every provider and connection unless you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>), in which case that block is sent uncached. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>), a custom `ANTHROPIC_BASE_URL`, or a cloud provider base-URL override such as [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), what stays cached depends on how the gateway handles the [`cache_control` markers](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) Claude Code sends:
* **Forwards them unchanged** : the block and your conversation cache the same as at the provider’s own endpoint.
* **Rejects the marked request with a`400` error naming `cache_control`**: Claude Code re-sends the request with the marker moved off the block and onto your last conversation message, and keeps it there for the rest of the conversation. The block bills as uncached input; your conversation stays cached.
Show diff (116 lines)
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -10,7 +10,7 @@
Layer| Content| Changes when
---|---|---
-System prompt| Core instructions, tool definitions| The set of loaded tool definitions changes or Claude Code is upgraded
+System prompt| Core instructions, tool definitions| The set of loaded tool definitions changes
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
@@ -56,7 +56,6 @@
* Connecting or disconnecting an MCP server
* Enabling or disabling a plugin
* Denying an entire tool
- * Changing output style
* Compacting the conversation
* Accumulating many images
* Upgrading Claude Code
@@ -139,14 +138,14 @@
When plugin changes apply
-A plugin change applies when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session, not when you run `/plugin enable` or `/plugin disable`. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
+A change you make in the `/plugin` menu goes through [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>), which Claude Code runs for you when you close the menu. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
* For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>).
- * When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. Claude Code tells you in the install summary whether it did or whether to run `/reload-plugins`.
+ * When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. The install summary tells you whether it did.
* When you [move the session with `/cd`](</docs/en/permissions#move-the-session-to-another-directory>) on v2.1.246 or later, Claude Code applies the plugins the new directory’s settings enable as part of the move, without the full re-read warning that holds a `/reload-plugins`.
* In interactive sessions, when you add or remove a plugin in a [folder of plugins](</docs/en/plugins#test-your-plugins-locally>) you passed with `--plugin-dir`, the change applies right away. If applying it would trigger a full re-read, Claude Code holds the change instead and shows a notice to run `/reload-plugins`. Requires Claude Code v2.1.265 or later.
-When you run `/reload-plugins` and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Rerun it with `--force` to apply the reload anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) and so never cost a full re-read mid-session.
+When `/reload-plugins` runs and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Run `/reload-plugins --force` to apply it anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) and so never cost a full re-read mid-session.
####
@@ -168,17 +167,9 @@
-Changing output style
-
-When you switch [output styles](</docs/en/output-styles>) mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message. In a conversation that [keeps a recorded system prompt](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>), as sessions signed in with a claude.ai or Console account do by default, Claude Code delivers the new style’s instructions as a message in the conversation. That request still reads the system prompt and the earlier conversation from the cache. In sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as on Amazon Bedrock, Google Cloud’s Agent Platform, or Microsoft Foundry, the style’s instructions are part of the system prompt, so the request after a switch reads the entire conversation history with no cache hits. There, switch styles before your first message in a session or right after `/clear` or `/compact`, when there is little or no conversation history to re-read. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
-
-###
-
-
-
Compacting the conversation
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer unless the conversation was resumed while keeping a system prompt that would otherwise have changed; in that case the first compaction switches to the current prompt and that layer rebuilds once. It reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
@@ -196,9 +187,9 @@
Upgrading Claude Code
-A new Claude Code version typically updates the system prompt or tool definitions, so the first request after an upgrade rebuilds the cache from the top. [Auto-update](</docs/en/setup#auto-updates>) downloads new versions in the background but applies them on the next launch, never mid-session, so you see this as an uncached first turn after restarting rather than a surprise during a session. Set `DISABLE_AUTOUPDATER=1` to control when upgrades apply.
-
-[Resuming a session](</docs/en/sessions#resume-a-session>) after an upgrade reprocesses the entire conversation history with no cache hits, since the history now sits behind a different system prompt. The cost scales with how long the resumed conversation is, so the first turn back into a long session can be the most expensive request you send.
+A new Claude Code version typically updates the system prompt or tool definitions, so the first conversation you start after an upgrade builds its cache from the top. [Auto-update](</docs/en/setup#auto-updates>) downloads new versions in the background but applies them on the next launch, never mid-session, so you see this as an uncached first turn after restarting rather than a surprise during a session. Set `DISABLE_AUTOUPDATER=1` to control when upgrades apply.
+
+For what it costs to resume a conversation you started before the upgrade, see Resuming a session.
##
@@ -211,6 +202,7 @@
* Editing files in your repository
* Editing CLAUDE.md mid-session
* Changing permission mode
+ * Changing output style
* Invoking skills and commands
* Running `/recap`
* Rewinding the conversation
@@ -244,6 +236,14 @@
+Changing output style
+
+When you switch [output styles](</docs/en/output-styles>) mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message. Claude Code delivers the new style’s instructions as a message in the conversation, so that request still reads the system prompt and the earlier conversation from the cache. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
+
+###
+
+
+
Invoking skills and commands
[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes. A skill or command whose frontmatter names a `model` can be a model switch for that turn.
@@ -263,6 +263,14 @@
Rewinding the conversation
[`/rewind`](</docs/en/checkpointing>) truncates your conversation back to an earlier turn. 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. Every turn since then has read through that prefix, which kept the entry warm even if the original turn was longer ago than the TTL. Restoring file checkpoints alongside the conversation has no separate effect on the cache. File contents enter context only when Claude reads them, the same as editing files in your repository.
+
+##
+
+
+
+Resuming a session
+
+When you [resume a session](</docs/en/sessions#resume-a-session>), Claude Code sends the whole conversation again, and the request reads from the cache whatever part of its prefix is unchanged and still within the cache lifetime. The layer table at the top of this page says what changes each layer. The system prompt would change after a Claude Code upgrade or with different [`--append-system-prompt`](</docs/en/cli-reference#system-prompt-flags>) text on the resume. By default, the resumed conversation keeps the system prompt it started with, so its history still sits behind the same prompt, and the change takes effect once the conversation is compacted or in a new conversation. [System prompt flags in resumed conversations](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>) covers `--system-prompt-snapshot off` and bare mode, where this doesn’t apply.
##
@@ -320,7 +328,7 @@
Cache scope
-In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds the working directory, platform, shell, OS version, and auto memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot at startup matches, since the system prompt also captures branch and recent commits. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
+In Claude Code, the cache is effectively scoped to one machine and directory. Each conversation carries the working directory, platform, shell, and OS version, and the system prompt names your auto memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot taken at startup matches, since each conversation also carries the branch and recent commits from that snapshot. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -10,7 +10,7 @@
Layer| Content| Changes when
---|---|---
-System prompt| Core instructions, tool definitions, output style| The set of loaded tool definitions changes, you switch output style, or Claude Code is upgraded
+System prompt| Core instructions, tool definitions| The set of loaded tool definitions changes or Claude Code is upgraded
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
@@ -67,7 +67,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5.1, Fable 5, and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable models and Opus 5 is also a model switch. When a safety classifier flags a request in a category that has a fallback model, Claude Code re-runs the request on that model and the session continues there. When a skill or command’s frontmatter names a [`model`](</docs/en/skills#frontmatter-reference>) other than the session’s current model, that turn is also a model switch: the next request reads the entire conversation history with no cache hits. The session model resumes on your next prompt. A `context: fork` skill sets the [forked subagent’s model](</docs/en/skills#run-skills-in-a-subagent>) instead.
###
@@ -139,13 +139,14 @@
When plugin changes apply
-Claude Code applies a plugin change when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. Claude Code can also apply a change on its own in three cases:
+A plugin change applies when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session, not when you run `/plugin enable` or `/plugin disable`. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies. Claude Code can also apply a change on its own:
* For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>).
* When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. Claude Code tells you in the install summary whether it did or whether to run `/reload-plugins`.
* When you [move the session with `/cd`](</docs/en/permissions#move-the-session-to-another-directory>) on v2.1.246 or later, Claude Code applies the plugins the new directory’s settings enable as part of the move, without the full re-read warning that holds a `/reload-plugins`.
-
-When you run `/reload-plugins` and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Rerun it with `--force` to apply the reload anyway.
+ * In interactive sessions, when you add or remove a plugin in a [folder of plugins](</docs/en/plugins#test-your-plugins-locally>) you passed with `--plugin-dir`, the change applies right away. If applying it would trigger a full re-read, Claude Code holds the change instead and shows a notice to run `/reload-plugins`. Requires Claude Code v2.1.265 or later.
+
+When you run `/reload-plugins` and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Rerun it with `--force` to apply the reload anyway. `/reload-plugins` also runs in sessions without an interactive terminal, such as the desktop app, the Agent SDK, and [non-interactive mode](</docs/en/headless>) with `-p`, when you type it into the session directly. Requires Claude Code v2.1.260 or later. In those sessions the reload applies everything except plugin MCP server changes, which [take effect in your next session](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) and so never cost a full re-read mid-session.
####
@@ -169,7 +170,7 @@
Changing output style
-[Output style](</docs/en/output-styles>) is part of the system prompt. When you switch styles mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message, and that request reads the entire conversation history with no cache hits. To keep that cost small, switch styles before your first message in a session or right after `/clear` or `/compact`, when there is little or no conversation history to re-read. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
+When you switch [output styles](</docs/en/output-styles>) mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message. In a conversation that [keeps a recorded system prompt](</docs/en/cli-reference#system-prompt-flags-in-resumed-conversations>), as sessions signed in with a claude.ai or Console account do by default, Claude Code delivers the new style’s instructions as a message in the conversation. That request still reads the system prompt and the earlier conversation from the cache. In sessions that don’t [fetch feature flags](</docs/en/env-vars#features-that-need-feature-flag-fetching>), such as on Amazon Bedrock, Google Cloud’s Agent Platform, or Microsoft Foundry, the style’s instructions are part of the system prompt, so the request after a switch reads the entire conversation history with no cache hits. There, switch styles before your first message in a session or right after `/clear` or `/compact`, when there is little or no conversation history to re-read. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
###
@@ -245,7 +246,7 @@
Invoking skills and commands
-[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes.
+[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes. A skill or command whose frontmatter names a `model` can be a model switch for that turn.
###
@@ -346,6 +347,7 @@
* **Session copies** : a session you [copy with `/fork`](</docs/en/agent-view#copy-the-session-with-%2Ffork>) receives its isolation instruction as a message at the end of the copied conversation, so the cache that the original conversation built stays intact.
* **Compaction** : the summarization call described in Compacting the conversation uses the same prefix-sharing approach.
+ * **Resumed subagents** : when Claude [resumes a subagent](</docs/en/sub-agents#resume-subagents>), the resumed run’s first request can read the cache the original run warmed.
* **Workflow fan-outs** : in a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code holds all but the first for up to 5 seconds by default, so their first requests can read the prefix that the first agent cached.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -10,11 +10,11 @@
Layer| Content| Changes when
---|---|---
-System prompt| Core instructions, tool definitions, output style| The set of loaded tool definitions changes, or Claude Code is upgraded
+System prompt| Core instructions, tool definitions, output style| The set of loaded tool definitions changes, you switch output style, or Claude Code is upgraded
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
-A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
+A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
* **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
@@ -56,6 +56,7 @@
* Connecting or disconnecting an MCP server
* Enabling or disabling a plugin
* Denying an entire tool
+ * Changing output style
* Compacting the conversation
* Accumulating many images
* Upgrading Claude Code
@@ -166,6 +167,14 @@
+Changing output style
+
+[Output style](</docs/en/output-styles>) is part of the system prompt. When you switch styles mid-session with `/config` or the `outputStyle` setting, Claude uses the new style starting with your next message, and that request reads the entire conversation history with no cache hits. To keep that cost small, switch styles before your first message in a session or right after `/clear` or `/compact`, when there is little or no conversation history to re-read. Before v2.1.251, a mid-session style switch kept the cache but didn’t apply until you ran `/clear` or started a new session.
+
+###
+
+
+
Compacting the conversation
[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
@@ -196,11 +205,10 @@
Actions that keep the cache
-These actions either append to the end of the conversation or don’t touch the request at all. Some of them, such as editing CLAUDE.md or changing output style, are also why a setting change waits for a restart to apply.
+These actions either append to the end of the conversation or don’t touch the request at all. Some of them, such as editing CLAUDE.md, keep the cache for the same reason the change doesn’t reach the running session until `/clear`, `/compact`, or a restart.
* Editing files in your repository
* Editing CLAUDE.md mid-session
- * Changing output style
* Changing permission mode
* Invoking skills and commands
* Running `/recap`
@@ -222,14 +230,6 @@
Editing CLAUDE.md mid-session
Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, when Claude first reads a matching file. Editing one before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
-
-###
-
-
-
-Changing output style
-
-[Output style](</docs/en/output-styles>) is part of the system prompt, which Claude Code reads once at session start. Changing it via `/config` or the `outputStyle` setting mid-session does not invalidate the cache, but the change also doesn’t apply. Claude keeps using the style that was loaded at session start. The new style loads on the next `/clear` or restart.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -334,7 +334,7 @@
`cache_creation_input_tokens`| Tokens written to the cache on this turn, billed at the cache write rate
`cache_read_input_tokens`| Tokens served from cache on this turn, billed at roughly 10% of the standard input rate
-A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For a per-session summary, run `/usage`. After the main conversation’s first response, Claude Code adds a [`Prompt cache (main)` line](</docs/en/costs#prompt-cache-statistics>) to the Session block, showing the session’s hit ratio, miss count, and whether the cache is warm right now. A status line script can read the same numbers from the [`prompt_cache` object](</docs/en/statusline#prompt-cache-fields>). Both require Claude Code v2.1.251 or later. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
+A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For a per-session summary, run `/usage`. After the main conversation’s first response, Claude Code adds a [`Prompt cache (main)` line](</docs/en/costs#prompt-cache-statistics>) to the Session block, showing the session’s hit ratio, miss count, and whether the cache is warm right now. A status line script can read the same numbers from the [`prompt_cache` object](</docs/en/statusline#prompt-cache-fields>). Both require Claude Code v2.1.251 or later. The `Prompt cache (main)` line also names the likely cause of the last miss when Claude Code can identify one, for example `likely cause: tool definitions changed`. The likely-cause text requires Claude Code v2.1.260 or later. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -14,10 +14,10 @@
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
-A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings aren’t part of the prompt text at all, so they don’t appear in the layer table, but both are part of the cache key:
+A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings don’t appear in the layer table but still affect what stays cached:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : each effort level has its own cache for the same model. Changing effort mid-session recomputes the entire request. See Changing effort level below.
+ * **Effort level** : on most models, each effort level has its own cache, so changing effort mid-session recomputes the entire request. On Fable 5.1 with an API key or a Claude subscription, the cache stays intact by default. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -74,7 +74,7 @@
Changing effort level
-The cache is keyed by [effort level](</docs/en/model-config#adjust-effort-level>) as well as model, so switching with `/effort` means the next request reads the entire conversation history with no cache hits. Changing effort follows the same confirmation as switching models. When a change resolves to the same level already in effect, such as setting the model’s default explicitly, Claude Code keeps the cache and applies the change without asking.
+On most models, changing the [effort level](</docs/en/model-config#adjust-effort-level>) mid-session means the next request reads the entire conversation history with no cache hits. While the cache is still warm, Claude Code asks you to confirm the change first. On Fable 5.1 with an API key or a Claude subscription, changing effort keeps the cache, and Claude Code applies the new level without asking. This doesn’t apply on Amazon Bedrock, Google Cloud’s Agent Platform, or a [Claude apps gateway](</docs/en/claude-apps-gateway>), or when you set [`CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS`](</docs/en/llm-gateway-protocol#disable-pre-release-capabilities>) or your organization has a HIPAA configuration. Before v2.1.260, changing effort on Fable 5.1 with an API key or a Claude subscription also invalidated the cache.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -57,6 +57,7 @@
* Enabling or disabling a plugin
* Denying an entire tool
* Compacting the conversation
+ * Accumulating many images
* Upgrading Claude Code
###
@@ -170,6 +171,14 @@
[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
+
+###
+
+
+
+Accumulating many images
+
+The API limits how many images and PDFs each request can carry. For the current numbers, see [Request limits](<https://platform.claude.com/docs/en/build-with-claude/vision#request-limits>) in the API docs. Claude Code also caps the total size of the images and PDFs in a request, so large screenshots reach the limit with fewer images than small ones. When the next request would pass either limit, Claude Code removes a batch of the oldest images and PDFs from what it sends, which leaves room for more before it needs to remove any again. Claude can no longer see the removed images. If Claude needs one of them again, share it again. Removing images changes the messages that held them, so the next request reprocesses the conversation from the earliest of those messages onward. Because Claude Code removes a batch at a time, you see one slower turn per batch rather than one with each new screenshot.
###
@@ -333,7 +342,11 @@
Subagents and the cache
-A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents fall outside the main-conversation TTL bucket, so they get five minutes even on a subscription until you choose a longer one. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach. In a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code briefly holds all but the first so their first requests can read the prefix the first agent cached.
+A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents fall outside the main-conversation TTL bucket, so they get five minutes even on a subscription until you choose a longer one. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. Other requests can also read a prefix that an earlier request cached:
+
+ * **Session copies** : a session you [copy with `/fork`](</docs/en/agent-view#copy-the-session-with-%2Ffork>) receives its isolation instruction as a message at the end of the copied conversation, so the cache that the original conversation built stays intact.
+ * **Compaction** : the summarization call described in Compacting the conversation uses the same prefix-sharing approach.
+ * **Workflow fan-outs** : in a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code holds all but the first for up to 5 seconds by default, so their first requests can read the prefix that the first agent cached.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -65,7 +65,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5.1, Fable 5, and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -65,7 +65,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. You can also require this confirmation or skip it with a [PreModelSwitch hook](</docs/en/hooks#premodelswitch-decision-control>). The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
###
@@ -129,7 +129,7 @@
Code intelligence plugins
-When you enable a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>). If you enable one mid-session, Claude Code changes the tool set at most once in that session. Once Claude Code has had a language server available, it keeps the LSP tool in the request for the rest of the session. Claude Code doesn’t change the tool set or invalidate the cache when a language server stops, fails, or reconnects later. Before v2.1.235, Claude Code removed the tool from the request whenever every language server had crashed or failed to start and added it back when one recovered.
+When you enable a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>).
####
@@ -151,7 +151,7 @@
Plugins you enable and then disable in one session
-When you disable a plugin you enabled earlier in the session, Claude Code restores the previous request shape, apart from the LSP tool, which Claude Code keeps for the rest of the session. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+When you disable a plugin you enabled earlier in the session, Claude Code restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -34,15 +34,13 @@
* **Microsoft Foundry** : depends on the deployment’s [hosting option](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>). Hosted on Azure deployments are served on Azure infrastructure; Hosted on Anthropic deployments are served on Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
-Claude Code also appends system context mid-conversation, such as file-change notices. Whether that block is cached depends on how your requests reach the provider. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. For Bedrock, Mantle, and Agent Platform, that means their base-URL variables are unset. For Foundry, it means `ANTHROPIC_FOUNDRY_BASE_URL` is unset or points at your resource’s `services.ai.azure.com` host, the standard [Microsoft Foundry setup](</docs/en/microsoft-foundry>). Before v2.1.211, these providers billed the block as uncached input tokens on every request. Claude Code doesn’t mark the block for caching, so it shows up as uncached input on every request, in any of these setups:
-
- * [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_BEDROCK_MANTLE_BASE_URL` set to any value, even the provider’s own endpoint
- * `ANTHROPIC_FOUNDRY_BASE_URL` pointing at a host outside `services.ai.azure.com`, such as a gateway
- * [`ANTHROPIC_AWS_BASE_URL`](</docs/en/env-vars>) set to any value on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>), including a custom-region endpoint
- * An [LLM gateway](</docs/en/llm-gateway>) or a custom `ANTHROPIC_BASE_URL`
- * A [Claude apps gateway](</docs/en/claude-apps-gateway>) session
-
-Claude Code keeps the conversation’s own [cache breakpoints](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) in place, so a gateway that forwards them still caches your conversation. Before v2.1.237, Claude Code marked the block for caching through gateways too, and a gateway that silently removed the marker left the entire conversation billed as uncached input on every turn. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
+Claude Code also appends system context mid-conversation, such as file-change notices, and marks that block for caching on every provider and connection. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>), a custom `ANTHROPIC_BASE_URL`, or a cloud provider base-URL override such as [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), what stays cached depends on how the gateway handles the [`cache_control` markers](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) Claude Code sends:
+
+ * **Forwards them unchanged** : the block and your conversation cache the same as at the provider’s own endpoint.
+ * **Rejects the marked request with a`400` error naming `cache_control`**: Claude Code re-sends the request with the marker moved off the block and onto your last conversation message, and keeps it there for the rest of the conversation. The block bills as uncached input; your conversation stays cached.
+ * **Removes the markers while returning success** : your entire conversation history bills as uncached input on every turn. A gateway that converts block-form system content to a plain string drops the marker the same way.
+
+For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
##
@@ -83,7 +81,7 @@
Turning on fast mode
-Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the next request reads the entire conversation history with no cache hits. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. Enabling fast mode from a non-Opus model also switches your model, which starts a fresh cache on its own. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. If you [run out of usage credits](</docs/en/fast-mode#handle-rate-limits>) mid-session, Claude Code retries each rejected fast mode request at standard speed the same way, so this fallback also keeps the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
+Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the first request Claude Code sends with fast mode on reads the entire conversation history with no cache hits. Claude Code sets that header once when a turn starts and keeps it for the whole turn, so when you turn fast mode on while Claude is working, the cache miss from the header happens on the first request of your next turn. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. If your current model doesn’t support fast mode, enabling fast mode also switches your model, and that switch starts a fresh cache on its own from the next request in the running turn. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. If you [run out of usage credits](</docs/en/fast-mode#handle-rate-limits>) mid-session, Claude Code retries each rejected fast mode request at standard speed the same way, so this fallback also keeps the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
###
@@ -300,8 +298,9 @@
1. `FORCE_PROMPT_CACHING_5M=1`, which forces five minutes for both buckets
2. The bucket’s environment variable
3. The bucket’s setting
- 4. `ENABLE_PROMPT_CACHING_1H=1`, which requests one hour for both buckets
- 5. The default for the request’s bucket
+ 4. For a subagent’s requests, the `cacheTtl` value in the subagent’s [`experimental` frontmatter field](</docs/en/sub-agents#supported-frontmatter-fields>), which requires Claude Code v2.1.248 or later. Claude Code ignores a `1h` there while your Claude subscription is using usage credits
+ 5. `ENABLE_PROMPT_CACHING_1H=1`, which requests one hour for both buckets
+ 6. The default for the request’s bucket
Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). To confirm which TTL your main conversation’s cache writes used, run `claude -p "hello" --output-format json` and read `usage.cache_creation` in the result. Claude Code reports one-hour cache writes under `ephemeral_1h_input_tokens` and five-minute cache writes under `ephemeral_5m_input_tokens`. Through an LLM gateway you set with `ANTHROPIC_BASE_URL`, part of the one-hour request travels in the `anthropic-beta` header, so configure the gateway to [forward that header unchanged](</docs/en/llm-gateway-protocol#request-headers>). The one-hour TTL isn’t available through the [Claude apps gateway](</docs/en/claude-apps-gateway#availability-and-limitations>). On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
@@ -326,7 +325,7 @@
`cache_creation_input_tokens`| Tokens written to the cache on this turn, billed at the cache write rate
`cache_read_input_tokens`| Tokens served from cache on this turn, billed at roughly 10% of the standard input rate
-A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
+A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For a per-session summary, run `/usage`. After the main conversation’s first response, Claude Code adds a [`Prompt cache (main)` line](</docs/en/costs#prompt-cache-statistics>) to the Session block, showing the session’s hit ratio, miss count, and whether the cache is warm right now. A status line script can read the same numbers from the [`prompt_cache` object](</docs/en/statusline#prompt-cache-fields>). Both require Claude Code v2.1.251 or later. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -139,10 +139,11 @@
When plugin changes apply
-Claude Code applies a plugin change when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. Claude Code can also apply a change on its own in two cases:
+Claude Code applies a plugin change when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. Claude Code can also apply a change on its own in three cases:
* For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>).
* When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. Claude Code tells you in the install summary whether it did or whether to run `/reload-plugins`.
+ * When you [move the session with `/cd`](</docs/en/permissions#move-the-session-to-another-directory>) on v2.1.246 or later, Claude Code applies the plugins the new directory’s settings enable as part of the move, without the full re-read warning that holds a `/reload-plugins`.
When you run `/reload-plugins` and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Rerun it with `--force` to apply the reload anyway.
@@ -302,7 +303,7 @@
4. `ENABLE_PROMPT_CACHING_1H=1`, which requests one hour for both buckets
5. The default for the request’s bucket
-Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). The one-hour TTL isn’t available through the [Claude apps gateway](</docs/en/claude-apps-gateway#availability-and-limitations>). On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
+Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). To confirm which TTL your main conversation’s cache writes used, run `claude -p "hello" --output-format json` and read `usage.cache_creation` in the result. Claude Code reports one-hour cache writes under `ephemeral_1h_input_tokens` and five-minute cache writes under `ephemeral_5m_input_tokens`. Through an LLM gateway you set with `ANTHROPIC_BASE_URL`, part of the one-hour request travels in the `anthropic-beta` header, so configure the gateway to [forward that header unchanged](</docs/en/llm-gateway-protocol#request-headers>). The one-hour TTL isn’t available through the [Claude apps gateway](</docs/en/claude-apps-gateway#availability-and-limitations>). On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -261,31 +261,48 @@
Cache lifetime
-Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). Claude Code picks the TTL for you based on how you authenticate, and you can override it with environment variables.
-
-###
-
-
-
-On a Claude subscription
-
-On a Claude subscription, Claude Code requests the one-hour TTL automatically, so the cache survives breaks of up to an hour. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage. Cache writes cost more at the one-hour TTL than at the five-minute TTL, so Claude Code automatically drops to the shorter one. To keep the one-hour TTL while drawing on usage credits, set `ENABLE_PROMPT_CACHING_1H=1`.
-
-###
-
-
-
-On an API key or third-party provider
-
-On an API key, Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or Claude Platform on AWS, you pay the per-token rates, so the TTL stays at the cheaper five minutes by default. To opt into the [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>), set `ENABLE_PROMPT_CACHING_1H=1`. On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
-
-###
-
-
-
-Override the TTL
-
-Set `FORCE_PROMPT_CACHING_5M=1` to force the five-minute TTL regardless of authentication. This is useful when you’re debugging cache behavior, comparing the two TTLs, or overriding an `ENABLE_PROMPT_CACHING_1H` set in [managed settings](</docs/en/managed-settings>).
+Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). The longer TTL helps when you leave a session idle and come back to it, because you skip the reprocessing an expired prefix costs. It costs more on short bursts of work that never idle past five minutes, where the higher write rate applies and the longer cache lifetime goes unused.
+
+###
+
+
+
+Which TTL each request gets
+
+Claude Code decides the TTL per request, and every request falls in one of two fixed buckets:
+
+ * **Main conversation** : your interactive turns, non-interactive `-p` runs, and Agent SDK turns, plus the helpers Claude Code runs inline with them
+ * **Everything else** : the requests Claude Code makes outside that conversation, such as [subagents](</docs/en/sub-agents>), [workflows](</docs/en/workflows>), in-process [teammates](</docs/en/agent-teams>), forks, compaction, and session titles
+
+Unless you choose a TTL yourself, Claude Code requests the one-hour TTL only on a Claude subscription within your plan’s included usage. There it requests the hour for the main conversation, plus a small set of helper requests that Anthropic controls server-side. This table gives each bucket’s default TTL under both kinds of billing.
+
+Request bucket| Claude subscription, within plan usage| Usage credits, API key, or cloud provider
+---|---|---
+Main conversation| One hour| Five minutes
+Everything else| Five minutes, except the server-controlled helper requests, which get one hour| Five minutes
+
+Once you go over your plan’s usage limit and Claude Code draws on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code drops the main conversation to the cheaper five-minute TTL. To keep the one-hour TTL there, choose the TTL yourself.
+
+###
+
+
+
+Choose the TTL yourself
+
+You can set a TTL for either bucket. Each control takes `5m` or `1h`, and Claude Code ignores any other value.
+
+ * **Main conversation** : the [`promptCacheTtl`](</docs/en/settings-reference#promptcachettl>) setting, or the `CLAUDE_CODE_PROMPT_CACHE_TTL` [environment variable](</docs/en/env-vars>)
+ * **Everything else** : the [`subagentPromptCacheTtl`](</docs/en/settings-reference#subagentpromptcachettl>) setting, or the `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL` environment variable
+
+Both settings and both environment variables require Claude Code v2.1.242 or later. If you sign in with an API key or use a cloud provider, set `promptCacheTtl` to `1h` to give the main conversation a one-hour cache. Requests outside it keep the five-minute default until you choose a TTL for that bucket too. When more than one control applies, Claude Code takes the first match in this order:
+
+ 1. `FORCE_PROMPT_CACHING_5M=1`, which forces five minutes for both buckets
+ 2. The bucket’s environment variable
+ 3. The bucket’s setting
+ 4. `ENABLE_PROMPT_CACHING_1H=1`, which requests one hour for both buckets
+ 5. The default for the request’s bucket
+
+Set `FORCE_PROMPT_CACHING_5M=1` when you’re debugging cache behavior, comparing the two TTLs, or overriding a longer TTL set in [managed settings](</docs/en/managed-settings>). The one-hour TTL isn’t available through the [Claude apps gateway](</docs/en/claude-apps-gateway#availability-and-limitations>). On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
##
@@ -316,7 +333,7 @@
Subagents and the cache
-A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents use the five-minute TTL even on a subscription, since the automatic one-hour TTL applies to the main conversation. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach. In a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code briefly holds all but the first so their first requests can read the prefix the first agent cached.
+A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents fall outside the main-conversation TTL bucket, so they get five minutes even on a subscription until you choose a longer one. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach. In a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code briefly holds all but the first so their first requests can read the prefix the first agent cached.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -34,7 +34,15 @@
* **Microsoft Foundry** : depends on the deployment’s [hosting option](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>). Hosted on Azure deployments are served on Azure infrastructure; Hosted on Anthropic deployments are served on Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
-System context that Claude Code appends mid-conversation, such as file-change notices, is cached on Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry the same way it is on the Claude API. Before v2.1.211, these providers billed that appended system context as uncached input tokens on every request. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>) or a custom `ANTHROPIC_BASE_URL`, Claude Code marks that appended system context for caching the same way, and whether the cache takes effect depends on the gateway. If the gateway rejects the [cache breakpoint](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) on that block, Claude Code retries the request without it and leaves that block uncached for the rest of the conversation. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
+Claude Code also appends system context mid-conversation, such as file-change notices. Whether that block is cached depends on how your requests reach the provider. At the provider’s own endpoint, Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry cache the block the same way the Claude API does. For Bedrock, Mantle, and Agent Platform, that means their base-URL variables are unset. For Foundry, it means `ANTHROPIC_FOUNDRY_BASE_URL` is unset or points at your resource’s `services.ai.azure.com` host, the standard [Microsoft Foundry setup](</docs/en/microsoft-foundry>). Before v2.1.211, these providers billed the block as uncached input tokens on every request. Claude Code doesn’t mark the block for caching, so it shows up as uncached input on every request, in any of these setups:
+
+ * [`ANTHROPIC_BEDROCK_BASE_URL`](</docs/en/env-vars>), `ANTHROPIC_VERTEX_BASE_URL`, or `ANTHROPIC_BEDROCK_MANTLE_BASE_URL` set to any value, even the provider’s own endpoint
+ * `ANTHROPIC_FOUNDRY_BASE_URL` pointing at a host outside `services.ai.azure.com`, such as a gateway
+ * [`ANTHROPIC_AWS_BASE_URL`](</docs/en/env-vars>) set to any value on [Claude Platform on AWS](</docs/en/claude-platform-on-aws>), including a custom-region endpoint
+ * An [LLM gateway](</docs/en/llm-gateway>) or a custom `ANTHROPIC_BASE_URL`
+ * A [Claude apps gateway](</docs/en/claude-apps-gateway>) session
+
+Claude Code keeps the conversation’s own [cache breakpoints](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) in place, so a gateway that forwards them still caches your conversation. Before v2.1.237, Claude Code marked the block for caching through gateways too, and a gateway that silently removed the marker left the entire conversation billed as uncached input on every turn. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
##
@@ -59,12 +67,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the current cache hasn’t expired. Whether the cache has expired depends on how long it has been since Claude Code last sent a request in this conversation or Claude last responded:
-
- * **Less than onecache TTL ago**: the cache is still warm.
- * **One cache TTL or longer ago** : the cache has already expired, so Claude Code switches without asking.
-
-Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the cache is still warm. The cache stays warm for one cache TTL after Claude Code last sent a request in this conversation or Claude last responded. Once that time passes, the cache has expired, so Claude Code switches without asking. Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
###
@@ -157,7 +160,7 @@
Denying an entire tool
-Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. Claude Code applies the change on the next request, even one in the middle of a turn, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Claude Code loads built-in tool definitions into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. Claude Code applies the change on the next request, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). That includes a rule you add through `/permissions` in the middle of a turn. Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
###
@@ -282,7 +285,7 @@
Override the TTL
-Set `FORCE_PROMPT_CACHING_5M=1` to force the five-minute TTL regardless of authentication. This is useful when you’re debugging cache behavior, comparing the two TTLs, or overriding an `ENABLE_PROMPT_CACHING_1H` set in [managed settings](</docs/en/settings#settings-files>).
+Set `FORCE_PROMPT_CACHING_5M=1` to force the five-minute TTL regardless of authentication. This is useful when you’re debugging cache behavior, comparing the two TTLs, or overriding an `ENABLE_PROMPT_CACHING_1H` set in [managed settings](</docs/en/managed-settings>).
##
@@ -331,7 +334,7 @@
`DISABLE_PROMPT_CACHING_OPUS`| Disable for Opus only
`DISABLE_PROMPT_CACHING_FABLE`| Disable for Fable only
-To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/settings#settings-files>). For normal use, leave caching enabled.
+To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/managed-settings>). For normal use, leave caching enabled.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -17,7 +17,7 @@
A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings aren’t part of the prompt text at all, so they don’t appear in the layer table, but both are part of the cache key:
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : each effort level has its own cache for the same model. Changing it mid-session recomputes the entire request, and Claude Code asks you to confirm before applying the change. See Changing effort level below.
+ * **Effort level** : each effort level has its own cache for the same model. Changing effort mid-session recomputes the entire request. See Changing effort level below.
Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
@@ -59,7 +59,12 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. When you run `/model` at the terminal, Claude Code asks you to confirm the switch only while the current cache hasn’t expired. Whether the cache has expired depends on how long it has been since Claude Code last sent a request in this conversation or Claude last responded:
+
+ * **Less than onecache TTL ago**: the cache is still warm.
+ * **One cache TTL or longer ago** : the cache has already expired, so Claude Code switches without asking.
+
+Before v2.1.238, Claude Code didn’t check the cache TTL and asked even after the cache had expired. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
###
@@ -67,7 +72,7 @@
Changing effort level
-The cache is keyed by [effort level](</docs/en/model-config#adjust-effort-level>) as well as model, so switching with `/effort` means the next request reads the entire conversation history with no cache hits. Once a conversation has started, Claude Code shows a confirmation dialog before applying an effort change that would invalidate the cache. A change that resolves to the same level already in effect, such as setting the model’s default explicitly, skips the dialog and keeps the cache.
+The cache is keyed by [effort level](</docs/en/model-config#adjust-effort-level>) as well as model, so switching with `/effort` means the next request reads the entire conversation history with no cache hits. Changing effort follows the same confirmation as switching models. When a change resolves to the same level already in effect, such as setting the model’s default explicitly, Claude Code keeps the cache and applies the change without asking.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -96,7 +96,55 @@
Enabling or disabling a plugin
-[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>). Claude Code can also activate a plugin you [install from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>) during the install; the install summary tells you whether it did or whether to run `/reload-plugins`. If that reload would trigger the full re-read below, the command warns first and applies when you rerun it with `--force`. The cost, whether appended announcements or a full re-read, shows up on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. When a reload would trigger the full re-read, `/reload-plugins` shows a warning and doesn’t apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+When you enable or disable a [plugin](</docs/en/plugins>), what the change costs depends on which component types the plugin provides. The cases below cover each component type, when Claude Code applies the change, and what happens when you disable a plugin again in the same session.
+
+####
+
+
+
+Plugin components that keep the cache
+
+Claude Code never invalidates the cache for a plugin’s skills, commands, agents, hooks, monitors, or themes. It appends their content after the existing conversation, so the next request pays for that content and still reads everything before it from the cache.
+
+####
+
+
+
+Plugins that provide MCP servers
+
+When you enable or disable a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>), Claude Code follows the same rules as when you connect or disconnect an MCP server:
+
+ * If Claude Code defers the server’s tools, it keeps the cache.
+ * If Claude Code loads them into the prefix, the next request re-reads the entire conversation.
+
+####
+
+
+
+Code intelligence plugins
+
+When you enable a [code intelligence plugin](</docs/en/discover-plugins#code-intelligence>), Claude gets the [LSP tool](</docs/en/tools-reference#lsp-tool-behavior>). If you enable one mid-session, Claude Code changes the tool set at most once in that session. Once Claude Code has had a language server available, it keeps the LSP tool in the request for the rest of the session. Claude Code doesn’t change the tool set or invalidate the cache when a language server stops, fails, or reconnects later. Before v2.1.235, Claude Code removed the tool from the request whenever every language server had crashed or failed to start and added it back when one recovered.
+
+####
+
+
+
+When plugin changes apply
+
+Claude Code applies a plugin change when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. You pay the cost, whether appended announcements or a full re-read, on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. Claude Code can also apply a change on its own in two cases:
+
+ * For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>).
+ * When you [install a plugin from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>), Claude Code can activate it during the install. Claude Code tells you in the install summary whether it did or whether to run `/reload-plugins`.
+
+When you run `/reload-plugins` and the reload would trigger a full re-read, Claude Code shows a warning and doesn’t apply the reload. Rerun it with `--force` to apply the reload anyway.
+
+####
+
+
+
+Plugins you enable and then disable in one session
+
+When you disable a plugin you enabled earlier in the session, Claude Code restores the previous request shape, apart from the LSP tool, which Claude Code keeps for the rest of the session. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -104,7 +104,7 @@
Denying an entire tool
-Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. Claude Code applies the change on the next request, even one in the middle of a turn, whether you add the rule through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -173,7 +173,7 @@
Changing permission mode
-Switching between [permission modes](</docs/en/permission-modes>), such as from default to accept edits, does not change the system prompt or tool definitions, so mode changes are cache-safe. The exception is plan mode with the [`opusplan`](</docs/en/model-config#opusplan-model-setting>) model setting, which switches the model between Opus and Sonnet as you enter or leave plan mode. That makes the mode toggle a model switch.
+Switching between [permission modes](</docs/en/permission-modes>), such as from Manual to accept edits, does not change the system prompt or tool definitions, so mode changes are cache-safe. The exception is plan mode with the [`opusplan`](</docs/en/model-config#opusplan-model-setting>) model setting, which switches the model between Opus and Sonnet as you enter or leave plan mode. That makes the mode toggle a model switch.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -96,7 +96,7 @@
Enabling or disabling a plugin
-[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. Claude Code can also activate a plugin you [install from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>) during the install; the install summary tells you whether it did or whether to run `/reload-plugins`. If that reload would trigger the full re-read below, the command warns first and applies when you rerun it with `--force`. The cost, whether appended announcements or a full re-read, shows up on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. When a reload would trigger the full re-read, `/reload-plugins` shows a warning and doesn’t apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. For a plugin with a `command` source, Claude Code [can reload the plugin itself](</docs/en/plugin-marketplaces#when-claude-code-re-runs-the-command>). Claude Code can also activate a plugin you [install from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>) during the install; the install summary tells you whether it did or whether to run `/reload-plugins`. If that reload would trigger the full re-read below, the command warns first and applies when you rerun it with `--force`. The cost, whether appended announcements or a full re-read, shows up on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. When a reload would trigger the full re-read, `/reload-plugins` shows a warning and doesn’t apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
@@ -260,7 +260,7 @@
Subagents and the cache
-A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. It builds its own cache, starting with no cache hits on its first call and warming up across its own turns. Subagents use the five-minute TTL even on a subscription, since the automatic one-hour TTL applies to the main conversation. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach.
+A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. Its first request doesn’t read the parent’s cache, because the two prefixes differ, and it warms a cache of its own across its turns. Subagents use the five-minute TTL even on a subscription, since the automatic one-hour TTL applies to the main conversation. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach. In a [workflow fan-out](</docs/en/workflows#prompt-caching-in-a-fan-out>) of same-prefix agents, Claude Code briefly holds all but the first so their first requests can read the prefix the first agent cached.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -237,7 +237,7 @@
Cache scope
-In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds the working directory, platform, shell, OS version, and auto-memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot at startup matches, since the system prompt also captures branch and recent commits. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
+In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds the working directory, platform, shell, OS version, and auto memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot at startup matches, since the system prompt also captures branch and recent commits. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -213,7 +213,7 @@
On a Claude subscription
-On a Claude subscription, Claude Code requests the one-hour TTL automatically, so the cache survives breaks of up to an hour. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage. Cache writes cost more at the one-hour TTL than at the five-minute TTL, so Claude Code automatically drops to the shorter one.
+On a Claude subscription, Claude Code requests the one-hour TTL automatically, so the cache survives breaks of up to an hour. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage. Cache writes cost more at the one-hour TTL than at the five-minute TTL, so Claude Code automatically drops to the shorter one. To keep the one-hour TTL while drawing on usage credits, set `ENABLE_PROMPT_CACHING_1H=1`.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -75,7 +75,7 @@
Turning on fast mode
-Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the next request reads the entire conversation history with no cache hits. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. Enabling fast mode from a non-Opus model also switches your model, which starts a fresh cache on its own. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
+Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the next request reads the entire conversation history with no cache hits. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. Enabling fast mode from a non-Opus model also switches your model, which starts a fresh cache on its own. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. If you [run out of usage credits](</docs/en/fast-mode#handle-rate-limits>) mid-session, Claude Code retries each rejected fast mode request at standard speed the same way, so this fallback also keeps the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
###
@@ -86,7 +86,7 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
+ * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform models earlier than the Claude 4.5 generation, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
@@ -96,7 +96,7 @@
Enabling or disabling a plugin
-[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. As of v2.1.163, when a reload would trigger the full re-read, `/reload-plugins` shows a warning and does not apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. Claude Code can also activate a plugin you [install from the `/plugin` interface](</docs/en/discover-plugins#install-plugins>) during the install; the install summary tells you whether it did or whether to run `/reload-plugins`. If that reload would trigger the full re-read below, the command warns first and applies when you rerun it with `--force`. The cost, whether appended announcements or a full re-read, shows up on the first turn after the change applies, not when you run `/plugin enable` or `/plugin disable`. When a reload would trigger the full re-read, `/reload-plugins` shows a warning and doesn’t apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -1,4 +1,4 @@
-Prompt caching makes Claude Code faster and more cost-efficient. Without caching, the API would reprocess your full history on every turn. With caching, it reuses what it already processed and only does new work for what changed. Claude Code handles prompt caching for you, unless you disable it. It is still useful to know how prompt caching works, because some actions invalidate the cache and make the next response slower and more expensive while it rebuilds. This page covers which actions those are, why some settings wait for a restart to apply, and how to check cache performance when usage looks high.
+Prompt caching makes Claude Code faster and more cost-efficient. Without caching, the API would reprocess your full history on every turn. With caching, it reuses what it already processed, bills the re-read at the [cached token rate](<https://platform.claude.com/docs/en/about-claude/pricing>), and fully processes only what changed. Claude Code handles prompt caching for you, unless you disable it. It is still useful to know how prompt caching works, because some actions invalidate the cache and make the next response slower and more expensive while it rebuilds. This page covers which actions those are, why some settings wait for a restart to apply, and how to check cache performance when usage looks high.
##
@@ -86,7 +86,7 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
+ * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform, with a custom `ANTHROPIC_BASE_URL` gateway, or on a Microsoft Foundry [deployment hosted on Azure](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>) once Claude Code detects that the deployment rejects tool search. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
@@ -112,7 +112,7 @@
Compacting the conversation
-[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. To produce the summary, Claude Code sends a one-off request with the same system prompt, tools, and history as your conversation, plus a summarization instruction appended as a final user message. Because it shares your prefix, that request reads the existing cache rather than reprocessing the full history. Most of compaction’s time goes to generating the summary, not to a cache miss. The turn that follows rebuilds the conversation cache only for the much shorter summary, so the post-compaction turn is not the slow part.
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. 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. 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. 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](</docs/en/sessions#resume-from-a-summary>). 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.
Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
@@ -205,7 +205,7 @@
Cache lifetime
-Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). Claude Code picks the TTL for you based on how you authenticate, and you can override it with environment variables.
+Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. On a Pro or Max plan, when you resume a large session after a long break, Claude Code [offers to resume from a summary](</docs/en/sessions#resume-from-a-summary>) so later requests don’t carry the full history. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). Claude Code picks the TTL for you based on how you authenticate, and you can override it with environment variables.
###
@@ -213,7 +213,7 @@
On a Claude subscription
-On a Claude subscription, Claude Code requests the one-hour TTL automatically. Usage is included in your plan rather than billed per token, so the longer TTL costs you nothing extra and only affects how long your cache stays warm. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code automatically drops the TTL to five minutes.
+On a Claude subscription, Claude Code requests the one-hour TTL automatically, so the cache survives breaks of up to an hour. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage. Cache writes cost more at the one-hour TTL than at the five-minute TTL, so Claude Code automatically drops to the shorter one.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -59,7 +59,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 is also a model switch. When a safety classifier flags a request, Claude Code re-runs it on the default Opus model and the session continues there.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 and Opus 5 is also a model switch. When a safety classifier flags a request and the flagged category has a fallback model, Claude Code re-runs the request on that model and the session continues there.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -34,7 +34,7 @@
* **Microsoft Foundry** : depends on the deployment’s [hosting option](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>). Hosted on Azure deployments are served on Azure infrastructure; Hosted on Anthropic deployments are served on Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
-System context that Claude Code appends mid-conversation, such as file-change notices, is cached on Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry the same way it is on the Claude API. Before v2.1.211, these providers billed that appended system context as uncached input tokens on every request. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
+System context that Claude Code appends mid-conversation, such as file-change notices, is cached on Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry the same way it is on the Claude API. Before v2.1.211, these providers billed that appended system context as uncached input tokens on every request. When your requests pass through an [LLM gateway](</docs/en/llm-gateway>) or a custom `ANTHROPIC_BASE_URL`, Claude Code marks that appended system context for caching the same way, and whether the cache takes effect depends on the gateway. If the gateway rejects the [cache breakpoint](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#explicit-cache-breakpoints>) on that block, Claude Code retries the request without it and leaves that block uncached for the rest of the conversation. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -31,10 +31,10 @@
* **API key, Claude subscription, or[Claude Platform on AWS](</docs/en/claude-platform-on-aws>)**: the cache lives in Anthropic’s infrastructure, accessed through the [Claude API](<https://platform.claude.com/docs>)
* **Amazon Bedrock or Google Cloud’s Agent Platform** : the cache lives in your cloud provider’s serving infrastructure
- * **Microsoft Foundry** : requests route to Anthropic’s infrastructure
+ * **Microsoft Foundry** : depends on the deployment’s [hosting option](<https://platform.claude.com/docs/en/build-with-claude/claude-in-microsoft-foundry#hosting-options>). Hosted on Azure deployments are served on Azure infrastructure; Hosted on Anthropic deployments are served on Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
-For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
+System context that Claude Code appends mid-conversation, such as file-change notices, is cached on Amazon Bedrock and its [Mantle endpoint](</docs/en/amazon-bedrock#use-the-mantle-endpoint>), Google Cloud’s Agent Platform, and Microsoft Foundry the same way it is on the Claude API. Before v2.1.211, these providers billed that appended system context as uncached input tokens on every request. For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
##
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -86,7 +86,7 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Haiku models, on Google Cloud’s Agent Platform, or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
+ * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Google Cloud’s Agent Platform or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -77,8 +77,6 @@
Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the next request reads the entire conversation history with no cache hits. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. Enabling fast mode from a non-Opus model also switches your model, which starts a fresh cache on its own. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
-Keeping the header across toggles requires Claude Code v2.1.86 or later. On earlier versions, every fast mode toggle and rate-limit fallback invalidates the cache.
-
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -30,8 +30,8 @@
Caching happens server-side, in whichever infrastructure serves your model. Where that is depends on how you authenticate:
* **API key, Claude subscription, or[Claude Platform on AWS](</docs/en/claude-platform-on-aws>)**: the cache lives in Anthropic’s infrastructure, accessed through the [Claude API](<https://platform.claude.com/docs>)
- * **Bedrock or Vertex AI** : the cache lives in your cloud provider’s serving infrastructure
- * **Foundry** : requests route to Anthropic’s infrastructure
+ * **Amazon Bedrock or Google Cloud’s Agent Platform** : the cache lives in your cloud provider’s serving infrastructure
+ * **Microsoft Foundry** : requests route to Anthropic’s infrastructure
* **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
@@ -88,7 +88,7 @@
Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
- * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Haiku models, on Vertex AI, or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
+ * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Haiku models, on Google Cloud’s Agent Platform, or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
@@ -223,7 +223,7 @@
On an API key or third-party provider
-On an API key, Bedrock, Vertex, Foundry, or Claude Platform on AWS, you pay the per-token rates, so the TTL stays at the cheaper five minutes by default. To opt into the [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>), set `ENABLE_PROMPT_CACHING_1H=1`. On Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Bedrock documentation.
+On an API key, Amazon Bedrock, Google Cloud’s Agent Platform, Microsoft Foundry, or Claude Platform on AWS, you pay the per-token rates, so the TTL stays at the cheaper five minutes by default. To opt into the [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>), set `ENABLE_PROMPT_CACHING_1H=1`. On Amazon Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Amazon Bedrock documentation.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -59,7 +59,7 @@
Switching models
-Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache.
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache. [Automatic model fallback](</docs/en/model-config#automatic-model-fallback>) on Fable 5 is also a model switch. When a safety classifier flags a request, Claude Code re-runs it on the default Opus model and the session continues there.
###
@@ -85,7 +85,7 @@
Connecting or disconnecting an MCP server
-Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
+Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Toggling the [advisor tool](</docs/en/advisor>) is an exception: its definition sits after the cache breakpoint, so enabling or disabling `/advisor` keeps the cached prefix intact. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
* **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
* **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Haiku models, on Vertex AI, or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
@@ -98,7 +98,7 @@
Enabling or disabling a plugin
-[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. As of v2.1.163, when a reload would trigger the full re-read, `/reload-plugins` warns and holds instead of applying it. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. As of v2.1.163, when a reload would trigger the full re-read, `/reload-plugins` shows a warning and does not apply the reload. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
@@ -106,7 +106,7 @@
Denying an entire tool
-Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a bare tool name, or the equivalent `Bash(*)` form, has this effect. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a deny rule that matches in the tool-name position has this effect: a bare tool name, the equivalent `Bash(*)` form, or a [tool-name glob](</docs/en/permissions#tool-name-wildcards>) like `"*"`. A glob that matches only MCP tools, such as `"mcp__*"`, removes those tools the same way but leaves the cache intact when the matched tools are deferred, the default, since deferred definitions were never in the cached prefix. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
###
@@ -278,6 +278,7 @@
`DISABLE_PROMPT_CACHING_HAIKU`| Disable for Haiku only
`DISABLE_PROMPT_CACHING_SONNET`| Disable for Sonnet only
`DISABLE_PROMPT_CACHING_OPUS`| Disable for Opus only
+`DISABLE_PROMPT_CACHING_FABLE`| Disable for Fable only
To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/settings#settings-files>). For normal use, leave caching enabled.
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -98,7 +98,7 @@
Enabling or disabling a plugin
-[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
+[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. As of v2.1.163, when a reload would trigger the full re-read, `/reload-plugins` warns and holds instead of applying it. Pass `--force` to apply anyway. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -1,9 +1,3 @@
-> ## Documentation Index
->
-> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt>
->
-> Use this file to discover all available pages before exploring further.
-
Prompt caching makes Claude Code faster and more cost-efficient. Without caching, the API would reprocess your full history on every turn. With caching, it reuses what it already processed and only does new work for what changed. Claude Code handles prompt caching for you, unless you disable it. It is still useful to know how prompt caching works, because some actions invalidate the cache and make the next response slower and more expensive while it rebuilds. This page covers which actions those are, why some settings wait for a restart to apply, and how to check cache performance when usage looks high.
##
@@ -52,6 +46,7 @@
* Switching models
* Changing effort level
+ * Turning on fast mode
* Connecting or disconnecting an MCP server
* Enabling or disabling a plugin
* Denying an entire tool
@@ -73,6 +68,16 @@
Changing effort level
The cache is keyed by [effort level](</docs/en/model-config#adjust-effort-level>) as well as model, so switching with `/effort` means the next request reads the entire conversation history with no cache hits. Once a conversation has started, Claude Code shows a confirmation dialog before applying an effort change that would invalidate the cache. A change that resolves to the same level already in effect, such as setting the model’s default explicitly, skips the dialog and keeps the cache.
+
+###
+
+
+
+Turning on fast mode
+
+Enabling [fast mode](</docs/en/fast-mode>) adds a request header that is part of the cache key, so the next request reads the entire conversation history with no cache hits. Those uncached input tokens are billed at [fast mode rates](</docs/en/fast-mode#understand-the-cost-tradeoff>), which is why turning it on at the start of a session costs less than turning it on deep into a long one. Enabling fast mode from a non-Opus model also switches your model, which starts a fresh cache on its own. The cost applies once per conversation. After the first fast mode turn, Claude Code keeps sending the header and varies only the request’s speed setting, which is not part of the cache key. Turning fast mode off, the [automatic fallback to standard speed](</docs/en/fast-mode#handle-rate-limits>) after a rate limit, and turning it back on later all keep the cache. `/clear` and `/compact` reset this, since they rebuild the cache at those points anyway.
+
+Keeping the header across toggles requires Claude Code v2.1.86 or later. On earlier versions, every fast mode toggle and rate-limit fallback invalidates the cache.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -16,7 +16,7 @@
Layer| Content| Changes when
---|---|---
-System prompt| Core instructions, tool definitions, output style| An MCP server connects or disconnects, or Claude Code is upgraded
+System prompt| Core instructions, tool definitions, output style| The set of loaded tool definitions changes, or Claude Code is upgraded
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
@@ -25,7 +25,7 @@
* **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
* **Effort level** : each effort level has its own cache for the same model. Changing it mid-session recomputes the entire request, and Claude Code asks you to confirm before applying the change. See Changing effort level below.
-Pick your model, effort level, and MCP servers at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
+Pick your model and effort level at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
###
@@ -48,11 +48,12 @@
Actions that invalidate the cache
-These actions cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch or an MCP reconnect can feel free until you notice the slower turn that follows.
+These actions cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch can feel free until you notice the slower turn that follows.
* Switching models
* Changing effort level
* Connecting or disconnecting an MCP server
+ * Enabling or disabling a plugin
* Denying an entire tool
* Compacting the conversation
* Upgrading Claude Code
@@ -79,7 +80,20 @@
Connecting or disconnecting an MCP server
-Tool definitions sit in the system prompt layer, so the cache invalidates when the set of MCP tools available to Claude changes between turns. The most common cause is an [MCP server](</docs/en/mcp>) connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects. [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) reduces how much each tool contributes to the prefix by deferring full tool definitions, but the set of tool names still has to stay stable for the cache to remain valid.
+Tool definitions sit in the system prompt layer, so the cache invalidates when the set of tool definitions in the request changes between turns. Whether an [MCP server](</docs/en/mcp>) change does this depends on whether its tools are deferred by [tool search](</docs/en/mcp#scale-with-mcp-tool-search>) or loaded into the prefix:
+
+ * **Deferred tools** , the default on supported models: a server connecting, disconnecting, or changing its tool list only appends new content and doesn’t disturb anything already cached.
+ * **Tools loaded into the prefix** : any change to them invalidates the cache. This happens when [tool search is unavailable or disabled](</docs/en/mcp#configure-tool-search>), such as on Haiku models, on Vertex AI, or with a custom `ANTHROPIC_BASE_URL` gateway. It also happens for a server or tool marked [`alwaysLoad`](</docs/en/mcp#exempt-a-server-from-deferral>), and for definitions kept upfront by [threshold-based loading](</docs/en/mcp#configure-tool-search>).
+
+When tools load into the prefix, the most common cause of an invalidation is a server connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects.
+
+###
+
+
+
+Enabling or disabling a plugin
+
+[Plugins](</docs/en/plugins>) bundle several component types, and the cost of a change depends on which components the plugin provides. Skills, commands, agents, hooks, LSP servers, monitors, and themes never invalidate the cache: anything they add to the request is appended after the existing conversation, so the next request pays for the new content but still reads everything before it from the cache. The exception is a plugin that provides [MCP servers](</docs/en/plugins-reference#mcp-servers>). Enabling or disabling one follows the same rules as connecting or disconnecting an MCP server: the cache survives when the server’s tools are deferred, and the next request re-reads the entire conversation when they load into the prefix. Plugin changes apply when you run [`/reload-plugins`](</docs/en/discover-plugins#apply-plugin-changes-without-restarting>) or start a new session. The cost, whether appended announcements or a full re-read, shows up on the first turn after the reload, not when you run `/plugin install`, `/plugin enable`, or `/plugin disable`. Disabling a plugin you enabled earlier in the session restores the previous request shape. If that prefix is still within its cache lifetime, the next request reads the older cache entry instead of rebuilding.
###
@@ -87,7 +101,7 @@
Denying an entire tool
-Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Tool definitions sit in the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache the same way an MCP server connecting or disconnecting does. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a bare tool name, or the equivalent `Bash(*)` form, has this effect. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Built-in tool definitions load into the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a bare tool name, or the equivalent `Bash(*)` form, has this effect. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
###
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -20,12 +20,12 @@
Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
Conversation| Your messages, Claude’s responses, tool results| Every turn
-A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings aren’t part of the prompt text at all, so they don’t appear in the layer table. They behave differently for caching:
-
- * **Model** : the cache is keyed by model, so each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
- * **Effort level** : not part of the cache key or the prompt, so [changing it](</docs/en/model-config#adjust-effort-level>) mid-session has no effect on the cache.
-
-Pick your model and connect MCP servers at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
+A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings aren’t part of the prompt text at all, so they don’t appear in the layer table, but both are part of the cache key:
+
+ * **Model** : each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
+ * **Effort level** : each effort level has its own cache for the same model. Changing it mid-session recomputes the entire request, and Claude Code asks you to confirm before applying the change. See Changing effort level below.
+
+Pick your model, effort level, and MCP servers at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
###
@@ -51,6 +51,7 @@
These actions cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch or an MCP reconnect can feel free until you notice the slower turn that follows.
* Switching models
+ * Changing effort level
* Connecting or disconnecting an MCP server
* Denying an entire tool
* Compacting the conversation
@@ -63,6 +64,14 @@
Switching models
Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache.
+
+###
+
+
+
+Changing effort level
+
+The cache is keyed by [effort level](</docs/en/model-config#adjust-effort-level>) as well as model, so switching with `/effort` means the next request reads the entire conversation history with no cache hits. Once a conversation has started, Claude Code shows a confirmation dialog before applying an effort change that would invalidate the cache. A change that resolves to the same level already in effect, such as setting the model’s default explicitly, skips the dialog and keeps the cache.
###
Show diff (269 lines)
--- a/prompt-caching.md
+++ b/prompt-caching.md
@@ -0,0 +1,266 @@
+> ## Documentation Index
+>
+> Fetch the complete documentation index at: <https://code.claude.com/docs/llms.txt>
+>
+> Use this file to discover all available pages before exploring further.
+
+Prompt caching makes Claude Code faster and more cost-efficient. Without caching, the API would reprocess your full history on every turn. With caching, it reuses what it already processed and only does new work for what changed. Claude Code handles prompt caching for you, unless you disable it. It is still useful to know how prompt caching works, because some actions invalidate the cache and make the next response slower and more expensive while it rebuilds. This page covers which actions those are, why some settings wait for a restart to apply, and how to check cache performance when usage looks high.
+
+##
+
+
+
+How the cache is organized
+
+Each time you send a message in Claude Code, it makes a new API request. The model doesn’t remember anything between requests, so Claude Code re-sends the full context: the system prompt, your project context, every prior message and tool result, and your new message. New content is appended at the end, which means most of each request is identical to the one before it. Prompt caching is how the API avoids reprocessing the part that didn’t change. The API caches by matching the start of each request, called the prefix, against content it recently processed. On a normal turn, the prefix is the entire previous request and only the latest exchange is new. The match is exact, so a change anywhere in the prefix recomputes everything after it. There is no per-file or per-segment caching. See [how prompt caching works](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#how-prompt-caching-works>) in the API reference for the underlying mechanism. To get the most out of prefix matching, Claude Code orders each request so content that rarely changes between turns comes first:
+
+Layer| Content| Changes when
+---|---|---
+System prompt| Core instructions, tool definitions, output style| An MCP server connects or disconnects, or Claude Code is upgraded
+Project context| CLAUDE.md, auto memory, unscoped rules| Session starts, or after `/clear` or `/compact`
+Conversation| Your messages, Claude’s responses, tool results| Every turn
+
+A change to the conversation layer leaves the system prompt and project context cached. A change to the system prompt invalidates everything, because all later content now sits behind a different prefix. The third column gives common triggers rather than an exhaustive list, and the sections below cover the full set, including content such as output style that is fixed at session start. The prefix-match rule explains most of the behaviors on this page. [Plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>) and [skill loading](</docs/en/skills>), for example, append their instructions as conversation messages, so the cached prefix stays intact. Two settings aren’t part of the prompt text at all, so they don’t appear in the layer table. They behave differently for caching:
+
+ * **Model** : the cache is keyed by model, so each model has its own cache. Switching models recomputes the entire request even when the content is identical. See Switching models below.
+ * **Effort level** : not part of the cache key or the prompt, so [changing it](</docs/en/model-config#adjust-effort-level>) mid-session has no effect on the cache.
+
+Pick your model and connect MCP servers at the top of a session, then save `/compact` for natural breaks between tasks. The fewer changes you make mid-task, the higher your cache hit rate.
+
+###
+
+
+
+Where the cache lives
+
+Caching happens server-side, in whichever infrastructure serves your model. Where that is depends on how you authenticate:
+
+ * **API key, Claude subscription, or[Claude Platform on AWS](</docs/en/claude-platform-on-aws>)**: the cache lives in Anthropic’s infrastructure, accessed through the [Claude API](<https://platform.claude.com/docs>)
+ * **Bedrock or Vertex AI** : the cache lives in your cloud provider’s serving infrastructure
+ * **Foundry** : requests route to Anthropic’s infrastructure
+ * **Custom`ANTHROPIC_BASE_URL` or [LLM gateway](</docs/en/llm-gateway>)**: the cache lives wherever your requests are forwarded, and whether caching works depends on the gateway
+
+For what each provider stores and processes, see [data usage](</docs/en/data-usage>). Wherever the cache lives, entries expire after a period of inactivity, and Cache lifetime below covers the TTL and how to extend it.
+
+##
+
+
+
+Actions that invalidate the cache
+
+These actions cause the next request to miss part or all of the cache. You see a one-time slower, more expensive turn, after which the new prefix is cached. Most of them are avoidable mid-task once you know they have a cost. A model switch or an MCP reconnect can feel free until you notice the slower turn that follows.
+
+ * Switching models
+ * Connecting or disconnecting an MCP server
+ * Denying an entire tool
+ * Compacting the conversation
+ * Upgrading Claude Code
+
+###
+
+
+
+Switching models
+
+Each model has its own cache. Switching with [`/model`](</docs/en/model-config#setting-your-model>) means the next request reads the entire conversation history with no cache hits, even though the content is identical. The [`opusplan` model setting](</docs/en/model-config#opusplan-model-setting>) resolves to Opus during plan mode and Sonnet during execution, so each plan-mode toggle is a model switch and starts a fresh cache.
+
+###
+
+
+
+Connecting or disconnecting an MCP server
+
+Tool definitions sit in the system prompt layer, so the cache invalidates when the set of MCP tools available to Claude changes between turns. The most common cause is an [MCP server](</docs/en/mcp>) connecting or disconnecting mid-session, which can happen without any action on your part: a stdio server’s process exits, an HTTP session expires, or a server [reconnects automatically after a transient failure](</docs/en/mcp#automatic-reconnection>). A connected server can also push a [dynamic tool update](</docs/en/mcp#dynamic-tool-updates>) that changes its tool list. Editing your MCP config does not by itself change the cache. The new config takes effect only after a restart, which is when the server connects or disconnects. [MCP tool search](</docs/en/mcp#scale-with-mcp-tool-search>) reduces how much each tool contributes to the prefix by deferring full tool definitions, but the set of tool names still has to stay stable for the cache to remain valid.
+
+###
+
+
+
+Denying an entire tool
+
+Adding a bare tool name like `Bash` or `WebFetch` as a [deny rule](</docs/en/permissions#manage-permissions>) removes that tool from Claude’s context entirely. Tool definitions sit in the system prompt layer, so adding or removing one of these rules mid-session invalidates the cache the same way an MCP server connecting or disconnecting does. The change takes effect on the next turn whether you add it through `/permissions` or by [editing a settings file directly](</docs/en/settings#when-edits-take-effect>). Only a bare tool name, or the equivalent `Bash(*)` form, has this effect. Scoped deny rules like `Bash(rm *)`, and all allow and ask rules, don’t change which tools Claude sees. Claude Code checks them when Claude attempts a call, leaving the prefix intact.
+
+###
+
+
+
+Compacting the conversation
+
+[Compaction](</docs/en/context-window#what-survives-compaction>) replaces your message history with a summary. By design, this invalidates the conversation layer, since the next request has a new, shorter history that doesn’t share a prefix with the old one. Claude Code reuses the system prompt layer and reloads project context from disk, which cache-hits only if CLAUDE.md and memory are unchanged since the session started. To produce the summary, Claude Code sends a one-off request with the same system prompt, tools, and history as your conversation, plus a summarization instruction appended as a final user message. Because it shares your prefix, that request reads the existing cache rather than reprocessing the full history. Most of compaction’s time goes to generating the summary, not to a cache miss. The turn that follows rebuilds the conversation cache only for the much shorter summary, so the post-compaction turn is not the slow part.
+
+Compaction works in your favor when the context you discard is content you no longer need. 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. If you’ve gone down a path you want to abandon entirely, `/rewind` to an earlier turn instead. Rewinding truncates back to a prefix that is already cached, rather than building a new one as compaction does.
+
+###
+
+
+
+Upgrading Claude Code
+
+A new Claude Code version typically updates the system prompt or tool definitions, so the first request after an upgrade rebuilds the cache from the top. [Auto-update](</docs/en/setup#auto-updates>) downloads new versions in the background but applies them on the next launch, never mid-session, so you see this as an uncached first turn after restarting rather than a surprise during a session. Set `DISABLE_AUTOUPDATER=1` to control when upgrades apply.
+
+[Resuming a session](</docs/en/sessions#resume-a-session>) after an upgrade reprocesses the entire conversation history with no cache hits, since the history now sits behind a different system prompt. The cost scales with how long the resumed conversation is, so the first turn back into a long session can be the most expensive request you send.
+
+##
+
+
+
+Actions that keep the cache
+
+These actions either append to the end of the conversation or don’t touch the request at all. Some of them, such as editing CLAUDE.md or changing output style, are also why a setting change waits for a restart to apply.
+
+ * Editing files in your repository
+ * Editing CLAUDE.md mid-session
+ * Changing output style
+ * Changing permission mode
+ * Invoking skills and commands
+ * Running `/recap`
+ * Rewinding the conversation
+ * Spawning a subagent
+
+###
+
+
+
+Editing files in your repository
+
+File contents enter context only when Claude reads them, and reads append to the conversation. Editing a file Claude previously read does not retroactively change the earlier read in history. Instead, Claude Code appends a `<system-reminder>` noting the file changed, and Claude re-reads it if needed.
+
+###
+
+
+
+Editing CLAUDE.md mid-session
+
+Your project-root and user-level CLAUDE.md files are read once at session start and held in memory. Editing them mid-session does not invalidate the cache, but the edit also doesn’t apply. Claude keeps working with the version that was loaded at session start. The new content loads on the next `/clear`, `/compact`, or restart. [Nested CLAUDE.md files in subdirectories](</docs/en/memory>) and [rules with `paths:` frontmatter](</docs/en/memory#path-specific-rules>) load later, when Claude first reads a matching file. Editing one before it loads does take effect. After it loads, the content is part of the conversation history, so a mid-session edit doesn’t retroactively change it.
+
+###
+
+
+
+Changing output style
+
+[Output style](</docs/en/output-styles>) is part of the system prompt, which Claude Code reads once at session start. Changing it via `/config` or the `outputStyle` setting mid-session does not invalidate the cache, but the change also doesn’t apply. Claude keeps using the style that was loaded at session start. The new style loads on the next `/clear` or restart.
+
+###
+
+
+
+Changing permission mode
+
+Switching between [permission modes](</docs/en/permission-modes>), such as from default to accept edits, does not change the system prompt or tool definitions, so mode changes are cache-safe. The exception is plan mode with the [`opusplan`](</docs/en/model-config#opusplan-model-setting>) model setting, which switches the model between Opus and Sonnet as you enter or leave plan mode. That makes the mode toggle a model switch.
+
+###
+
+
+
+Invoking skills and commands
+
+[Skills](</docs/en/skills>) and [commands](</docs/en/commands>) inject their instructions as user messages at the point of invocation. Nothing earlier in the conversation changes.
+
+###
+
+
+
+Running `/recap`
+
+[`/recap`](</docs/en/interactive-mode#session-recap>) generates a summary for display in your terminal. Unlike `/compact`, it appends the summary as command output rather than replacing your message history, so the cached prefix stays intact.
+
+###
+
+
+
+Rewinding the conversation
+
+[`/rewind`](</docs/en/checkpointing>) truncates your conversation back to an earlier turn. 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. Every turn since then has read through that prefix, which kept the entry warm even if the original turn was longer ago than the TTL. Restoring file checkpoints alongside the conversation has no separate effect on the cache. File contents enter context only when Claude reads them, the same as editing files in your repository.
+
+##
+
+
+
+Cache lifetime
+
+Cached prefixes expire after a period of inactivity. Each request that hits the cache resets the timer, so the cache stays warm as long as you keep working. After a long enough gap, the next request recomputes the full input and re-establishes the cache, which is why the first turn back after stepping away can be noticeably slower. The time to live (TTL) controls how long a gap the cache survives. The API offers two: a five-minute TTL, and a [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>) that keeps the cache warm through longer breaks but [bills cache writes at a higher rate](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing>). Claude Code picks the TTL for you based on how you authenticate, and you can override it with environment variables.
+
+###
+
+
+
+On a Claude subscription
+
+On a Claude subscription, Claude Code requests the one-hour TTL automatically. Usage is included in your plan rather than billed per token, so the longer TTL costs you nothing extra and only affects how long your cache stays warm. If you’ve gone over your plan’s usage limit and Claude Code is drawing on [usage credits](<https://support.claude.com/en/articles/12429409-extra-usage-for-paid-claude-plans>), you are billed for that usage, so Claude Code automatically drops the TTL to five minutes.
+
+###
+
+
+
+On an API key or third-party provider
+
+On an API key, Bedrock, Vertex, Foundry, or Claude Platform on AWS, you pay the per-token rates, so the TTL stays at the cheaper five minutes by default. To opt into the [one-hour TTL](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#1-hour-cache-duration>), set `ENABLE_PROMPT_CACHING_1H=1`. On Bedrock, prompt caching support, minimum cacheable prefix length, and one-hour TTL availability all vary by model. If cache token counts stay at zero, check [supported models, regions, and limits](<https://docs.aws.amazon.com/bedrock/latest/userguide/prompt-caching.html#prompt-caching-models>) in the Bedrock documentation.
+
+###
+
+
+
+Override the TTL
+
+Set `FORCE_PROMPT_CACHING_5M=1` to force the five-minute TTL regardless of authentication. This is useful when you’re debugging cache behavior, comparing the two TTLs, or overriding an `ENABLE_PROMPT_CACHING_1H` set in [managed settings](</docs/en/settings#settings-files>).
+
+##
+
+
+
+Cache scope
+
+In Claude Code, the cache is effectively scoped to one machine and directory. The system prompt embeds the working directory, platform, shell, OS version, and auto-memory paths, so two sessions in different directories build different prefixes and miss each other’s cache. That includes worktrees of the same repository, since each worktree has its own working directory. Sessions you run in parallel in the same directory build matching prefixes and read each other’s cache. Sequential sessions share the prefix only when the git status snapshot at startup matches, since the system prompt also captures branch and recent commits. The underlying API cache is broader. Caches are isolated between organizations, and on some providers, [between workspaces within an organization](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching#cache-storage-and-sharing>). Within those boundaries, any two requests with the same model and prefix read the same cache. For Agent SDK callers running fleets of automated processes, see [improve prompt caching across users and machines](</docs/en/agent-sdk/modifying-system-prompts#improve-prompt-caching-across-users-and-machines>) to suppress the per-machine sections of the system prompt and share the cache across machines.
+
+##
+
+
+
+Check cache performance
+
+Cache performance shows up as two token counts the API reports on every response. The most direct way to watch them live is a [statusline script](</docs/en/statusline>) that reads the `current_usage` object:
+
+Field| Meaning
+---|---
+`cache_creation_input_tokens`| Tokens written to the cache on this turn, billed at the cache write rate
+`cache_read_input_tokens`| Tokens served from cache on this turn, billed at roughly 10% of the standard input rate
+
+A high read-to-creation ratio means caching is working well. If creation stays high turn after turn, something is changing in your prefix. The actions that invalidate the cache section lists the usual causes. For visibility across an organization, the OpenTelemetry exporter reports cache read and creation tokens per user and session. See [Monitor usage](</docs/en/monitoring-usage>) for the metric and event attribute reference.
+
+##
+
+
+
+Subagents and the cache
+
+A [subagent](</docs/en/sub-agents>) starts its own conversation with its own system prompt and tool set, separate from the parent’s. It builds its own cache, starting with no cache hits on its first call and warming up across its own turns. Subagents use the five-minute TTL even on a subscription, since the automatic one-hour TTL applies to the main conversation. The parent’s cache is unaffected. From the parent’s side, the subagent’s call and result append to the conversation, leaving the parent’s prefix intact. A [fork](</docs/en/sub-agents#fork-the-current-conversation>), by contrast, inherits the parent’s system prompt, tools, and conversation history exactly, so its first request reads the parent’s cache. The compaction summarization call described in Compacting the conversation uses the same prefix-sharing approach.
+
+##
+
+
+
+Disable prompt caching
+
+Disabling caching is occasionally useful when debugging caching behavior with a specific model or provider. To turn it off, set one of these environment variables to `1`:
+
+Variable| Effect
+---|---
+`DISABLE_PROMPT_CACHING`| Disable for all models
+`DISABLE_PROMPT_CACHING_HAIKU`| Disable for Haiku only
+`DISABLE_PROMPT_CACHING_SONNET`| Disable for Sonnet only
+`DISABLE_PROMPT_CACHING_OPUS`| Disable for Opus only
+
+To set caching policy across an organization, put any of these or the TTL variables in the `env` block of [managed settings](</docs/en/settings#settings-files>). For normal use, leave caching enabled.
+
+##
+
+
+
+Related resources
+
+ * [Lessons from building Claude Code: Prompt caching is everything](<https://claude.com/blog/lessons-from-building-claude-code-prompt-caching-is-everything>): the design rationale for plan mode, deferred tool loading, and compaction
+ * [Explore the context window](</docs/en/context-window>): what loads into context and when
+ * [Reduce token usage](</docs/en/costs#reduce-token-usage>): strategies beyond caching for managing context size
+ * [Track and reduce costs](</docs/en/agent-sdk/cost-tracking>): cache token tracking and TTL configuration for Agent SDK callers
+ * [Prompt caching](<https://platform.claude.com/docs/en/build-with-claude/prompt-caching>): the underlying API mechanism, breakpoints, and pricing