Explore the context window
--- a/context-window.md
+++ b/context-window.md
@@ -68,15 +68,15 @@
## When your context fills up
-Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. For when Claude Code also compacts a conversation you leave idle, see [idle compaction](</docs/en/settings-reference#idlecompaction>). You can also act before the automatic pass runs:
+Claude Code compacts automatically as you approach the [auto-compact window](</docs/en/model-config#context-window-and-auto-compaction>), so a long conversation doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. For when Claude Code also compacts a conversation you leave idle, see [idle compaction](</docs/en/settings-reference#idlecompaction>). You can also act before the automatic pass runs:
* **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
* **Compact part of the conversation** : run `/rewind`, select a message, and choose **Summarize from here** or **Summarize up to here**. See [Rewind and summarize](</docs/en/checkpointing#rewind-and-summarize>) for what each option keeps and how to guide the summary.
- * **Compact earlier** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See [Set the auto-compact window](</docs/en/model-config#set-the-auto-compact-window>) for accepted values and overrides.
+ * **Compact earlier or later** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See [Set the auto-compact window](</docs/en/model-config#set-the-auto-compact-window>) for accepted values and overrides.
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, choose a model with a 1 million token context window. Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support it. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. To keep a session from compacting well before 1M, see [Compaction near 400K on a 1M model](</docs/en/model-config#compaction-near-400k-on-a-1m-model>). The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
## Check your own session
--- a/context-window.md
+++ b/context-window.md
@@ -2,12 +2,47 @@
## What the timeline shows
-The session walks through a realistic flow with representative token counts:
-
* **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](</docs/en/memory#agents-md>) can load in place of CLAUDE.md. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
- * **At the end of the walkthrough** : you run `/compact`, which replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
+ * **At the end of the session** : you run `/compact`, which replaces the conversation with a structured summary. Most startup content reloads automatically. See what survives compaction for what reloads and what gets summarized.
+
+Token counts for each step
+
+Compare how many tokens each step adds in the timeline’s example session. The counts are illustrative and vary with your CLAUDE.md size, MCP servers, and file lengths. For real numbers, check your own session.
+
+Phase| What enters context| Example tokens
+---|---|---
+Before you type| System prompt| 4,200
+Before you type| Auto memory (`MEMORY.md`)| 680
+Before you type| Environment info| 280
+Before you type| MCP tool names| 120
+Before you type| Skill descriptions| 450
+Before you type| `~/.claude/CLAUDE.md`| 320
+Before you type| Project CLAUDE.md| 1,800
+First prompt| Your prompt| 45
+As Claude works| Read `src/api/auth.ts`| 2,400
+As Claude works| Read `src/lib/tokens.ts`| 1,100
+As Claude works| Rule `api-conventions.md`| 380
+As Claude works| Read `middleware.ts`| 1,800
+As Claude works| Read `auth.test.ts`| 1,600
+As Claude works| Rule `testing.md`| 290
+As Claude works| Search for `refreshToken`| 600
+As Claude works| Claude’s analysis| 800
+As Claude works| Edit `auth.ts`| 400
+As Claude works| Prettier hook output| 120
+As Claude works| Edit `auth.test.ts`| 600
+As Claude works| Prettier hook output| 100
+As Claude works| `npm test` output| 1,200
+As Claude works| Claude’s summary of its changes| 400
+Follow-up prompt| Your follow-up prompt| 40
+Follow-up prompt| Claude’s call to the subagent| 80
+Follow-up prompt| Subagent’s summary| 420
+Follow-up prompt| Claude’s response| 1,200
+End of the session| `!git status` and its output| 180
+End of the session| `/commit-push` skill body| 620
+
+Before `/compact`, 22,225 tokens are in use. The subagent uses another 9,890 tokens in its own context window.After `/compact`, 17,095 tokens are in use: the “Before you type” rows, a 1,725-token conversation summary, the four files read under “As Claude works”, and the `/commit-push` skill body.
## What survives compaction
--- a/context-window.md
+++ b/context-window.md
@@ -1,10 +1,6 @@
Claude Code’s context window holds everything Claude knows about your session: your instructions, the files it reads, its own responses, and content that never appears in your terminal. The timeline below plays a full session from startup to compaction: what loads before you type, what each file read, rule, and hook adds as Claude works, and how a subagent keeps large reads out of your context. See the written breakdown for the same content as a list.
-##
-
-
-
-What the timeline shows
+## What the timeline shows
The session walks through a realistic flow with representative token counts:
@@ -13,11 +9,7 @@
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
* **At the end of the walkthrough** : you run `/compact`, which replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
-##
-
-
-
-What survives compaction
+## What survives compaction
When a long session compacts, Claude Code summarizes the conversation history to fit the context window.
@@ -39,11 +31,7 @@
Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Path-scoped rules and nested CLAUDE.md files load into message history when Claude reads, writes, or edits their trigger file, so compaction summarizes them away with everything else. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
-##
-
-
-
-When your context fills up
+## When your context fills up
Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. For when Claude Code also compacts a conversation you leave idle, see [idle compaction](</docs/en/settings-reference#idlecompaction>). You can also act before the automatic pass runs:
@@ -55,19 +43,11 @@
If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
-##
-
-
-
-Check your own session
+## Check your own session
The visualization uses representative numbers. To see your actual context usage at any point, run `/context` for a live breakdown by category with optimization suggestions, including which CLAUDE.md and auto memory files loaded. Run `/memory` to open and edit those files.
-##
-
-
-
-Related resources
+## Related resources
For deeper coverage of the features shown in the timeline, see these pages:
--- a/context-window.md
+++ b/context-window.md
@@ -19,7 +19,7 @@
What survives compaction
-When a long session compacts, Claude Code summarizes the conversation history to fit the context window. As of v2.1.198, the summarization request inherits your session’s [extended thinking](</docs/en/model-config#extended-thinking>) configuration, so it reasons with thinking enabled when your session has it enabled and stays off otherwise. Thinking affects only how the summary is produced; your session settings are unchanged afterward. What happens to each kind of content depends on how it was loaded:
+When a long session compacts, Claude Code summarizes the conversation history to fit the context window.
Mechanism| After compaction
---|---
--- a/context-window.md
+++ b/context-window.md
@@ -74,6 +74,6 @@
* [Extend Claude Code](</docs/en/features-overview>): when to use CLAUDE.md vs skills vs rules vs hooks vs MCP
* [Store instructions and memories](</docs/en/memory>): CLAUDE.md hierarchy and auto memory
* [Subagents](</docs/en/sub-agents>): delegate research to a separate context window
- * [Best practices](</docs/en/best-practices>): managing context as your primary constraint
+ * [Best practices](</docs/en/best-practices#keep-cost-and-context-down>): keep sessions focused and costs down
* [Prompt caching](</docs/en/prompt-caching>): which actions invalidate the cached prefix
* [Reduce token usage](</docs/en/costs#reduce-token-usage>): strategies for keeping context usage low
--- a/context-window.md
+++ b/context-window.md
@@ -26,6 +26,7 @@
System prompt and output style| Both still apply
Project-root CLAUDE.md and unscoped rules| Re-injected from disk
Auto memory| Re-injected from disk
+Skill descriptions| Rebuilt from your current [skills](</docs/en/skills>) and re-injected. Requires Claude Code v2.1.304 or later
[Git status snapshot](</docs/en/settings-reference#includegitinstructions>)| If the session started with one, Claude Code reads a fresh one from your repository
The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
Rules with `paths:` frontmatter| Claude Code reloads them [on demand](</docs/en/memory#path-specific-rules>)
--- a/context-window.md
+++ b/context-window.md
@@ -26,7 +26,7 @@
System prompt and output style| Both still apply
Project-root CLAUDE.md and unscoped rules| Re-injected from disk
Auto memory| Re-injected from disk
-[Git status snapshot](</docs/en/settings-reference#includegitinstructions>)| Claude Code reads a fresh one from your repository
+[Git status snapshot](</docs/en/settings-reference#includegitinstructions>)| If the session started with one, Claude Code reads a fresh one from your repository
The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
Rules with `paths:` frontmatter| Claude Code reloads them [on demand](</docs/en/memory#path-specific-rules>)
Nested CLAUDE.md in subdirectories| Claude Code reloads them [on demand](</docs/en/memory#how-claude-md-files-load>)
--- a/context-window.md
+++ b/context-window.md
@@ -44,7 +44,7 @@
When your context fills up
-Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. You can also act before the automatic pass runs:
+Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. For when Claude Code also compacts a conversation you leave idle, see [idle compaction](</docs/en/settings-reference#idlecompaction>). You can also act before the automatic pass runs:
* **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
* **Compact part of the conversation** : run `/rewind`, select a message, and choose **Summarize from here** or **Summarize up to here**. See [Rewind and summarize](</docs/en/checkpointing#rewind-and-summarize>) for what each option keeps and how to guide the summary.
--- a/context-window.md
+++ b/context-window.md
@@ -52,7 +52,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds, and [the context window behind a gateway](</docs/en/model-config#context-window-behind-a-gateway>) for how Claude Code sizes the window when you set `ANTHROPIC_BASE_URL` to an [LLM gateway](</docs/en/llm-gateway>). The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -36,7 +36,7 @@
Context that hooks added earlier| Summarized with the rest of the conversation
[SessionStart hooks](</docs/en/hooks-guide#re-inject-context-after-compaction>) that match the `compact` source| Claude Code runs them and adds their output to the compacted context
-Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
+Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Path-scoped rules and nested CLAUDE.md files load into message history when Claude reads, writes, or edits their trigger file, so compaction summarizes them away with everything else. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
##
@@ -52,7 +52,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds, and [the context window behind a gateway](</docs/en/model-config#context-window-behind-a-gateway>) for how Claude Code sizes the window when you set `ANTHROPIC_BASE_URL` to an [LLM gateway](</docs/en/llm-gateway>). The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Haiku 5.5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds, and [the context window behind a gateway](</docs/en/model-config#context-window-behind-a-gateway>) for how Claude Code sizes the window when you set `ANTHROPIC_BASE_URL` to an [LLM gateway](</docs/en/llm-gateway>). The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -8,7 +8,7 @@
The session walks through a realistic flow with representative token counts:
- * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](</docs/en/memory#agents-md>) can load too, on their own or alongside CLAUDE.md. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
+ * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](</docs/en/memory#agents-md>) can load in place of CLAUDE.md. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
* **At the end of the walkthrough** : you run `/compact`, which replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
--- a/context-window.md
+++ b/context-window.md
@@ -28,8 +28,8 @@
Auto memory| Re-injected from disk
[Git status snapshot](</docs/en/settings-reference#includegitinstructions>)| Claude Code reads a fresh one from your repository
The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
-Rules with `paths:` frontmatter| Claude Code reloads them as Claude reads files they match
-Nested CLAUDE.md in subdirectories| Claude Code reloads them as Claude reads files in that subdirectory
+Rules with `paths:` frontmatter| Claude Code reloads them [on demand](</docs/en/memory#path-specific-rules>)
+Nested CLAUDE.md in subdirectories| Claude Code reloads them [on demand](</docs/en/memory#how-claude-md-files-load>)
Files Claude read or edited| Claude Code re-reads up to five, most recently modified first
Invoked skill bodies| Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first
[Background commands](</docs/en/interactive-mode#background-bash-commands>) and background [subagents](</docs/en/sub-agents#run-subagents-in-foreground-or-background>)| Keep running. Claude Code reminds Claude which ones are still running so it doesn’t start a duplicate
--- a/context-window.md
+++ b/context-window.md
@@ -52,7 +52,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds and the LLM gateway exception. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds, and [the context window behind a gateway](</docs/en/model-config#context-window-behind-a-gateway>) for how Claude Code sizes the window when you set `ANTHROPIC_BASE_URL` to an [LLM gateway](</docs/en/llm-gateway>). The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -52,7 +52,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5 runs with the 1M context window and has no `[1m]` variant to select. See [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5 and later, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5.5 and Sonnet 5 run with the 1M context window and have no `[1m]` variant to select. See [Sonnet 5.5 and Sonnet 5 context window](</docs/en/model-config#sonnet-5-5-and-sonnet-5-context-window>) for their auto-compaction thresholds and the LLM gateway exception. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -11,7 +11,7 @@
* **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](</docs/en/memory#agents-md>) can load too, on their own or alongside CLAUDE.md. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
- * **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
+ * **At the end of the walkthrough** : you run `/compact`, which replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
##
@@ -26,6 +26,7 @@
System prompt and output style| Both still apply
Project-root CLAUDE.md and unscoped rules| Re-injected from disk
Auto memory| Re-injected from disk
+[Git status snapshot](</docs/en/settings-reference#includegitinstructions>)| Claude Code reads a fresh one from your repository
The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
Rules with `paths:` frontmatter| Claude Code reloads them as Claude reads files they match
Nested CLAUDE.md in subdirectories| Claude Code reloads them as Claude reads files in that subdirectory
--- a/context-window.md
+++ b/context-window.md
@@ -8,7 +8,7 @@
The session walks through a realistic flow with representative token counts:
- * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
+ * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](</docs/en/memory#agents-md>) can load too, on their own or alongside CLAUDE.md. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
* **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
--- a/context-window.md
+++ b/context-window.md
@@ -35,7 +35,7 @@
Context that hooks added earlier| Summarized with the rest of the conversation
[SessionStart hooks](</docs/en/hooks-guide#re-inject-context-after-compaction>) that match the `compact` source| Claude Code runs them and adds their output to the compacted context
-Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently, and reloads the rules and nested CLAUDE.md files that apply to those files. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Its rules still reload. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
+Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
##
--- a/context-window.md
+++ b/context-window.md
@@ -31,6 +31,7 @@
Nested CLAUDE.md in subdirectories| Claude Code reloads them as Claude reads files in that subdirectory
Files Claude read or edited| Claude Code re-reads up to five, most recently modified first
Invoked skill bodies| Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first
+[Background commands](</docs/en/interactive-mode#background-bash-commands>) and background [subagents](</docs/en/sub-agents#run-subagents-in-foreground-or-background>)| Keep running. Claude Code reminds Claude which ones are still running so it doesn’t start a duplicate
Context that hooks added earlier| Summarized with the rest of the conversation
[SessionStart hooks](</docs/en/hooks-guide#re-inject-context-after-compaction>) that match the `compact` source| Claude Code runs them and adds their output to the compacted context
--- a/context-window.md
+++ b/context-window.md
@@ -8,7 +8,7 @@
The session walks through a realistic flow with representative token counts:
- * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>), which both go into the system prompt the same way.
+ * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>).
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
* **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
@@ -23,7 +23,7 @@
Mechanism| After compaction
---|---
-System prompt and output style| Unchanged; not part of message history
+System prompt and output style| Both still apply
Project-root CLAUDE.md and unscoped rules| Re-injected from disk
Auto memory| Re-injected from disk
The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
@@ -50,7 +50,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable 5.1, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable models, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit. Sonnet 5 runs with the 1M context window and has no `[1m]` variant to select. See [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -50,7 +50,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
+If you need a larger window rather than a smaller conversation, Fable 5.1, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -19,19 +19,22 @@
What survives compaction
-When a long session compacts, Claude Code summarizes the conversation history to fit the context window. As of v2.1.198, the summarization request inherits your session’s [extended thinking](</docs/en/model-config#extended-thinking>) configuration, so it reasons with thinking enabled when your session has it enabled and stays off otherwise. Thinking affects only how the summary is produced; your session settings are unchanged afterward. What happens to your instructions depends on how they were loaded:
+When a long session compacts, Claude Code summarizes the conversation history to fit the context window. As of v2.1.198, the summarization request inherits your session’s [extended thinking](</docs/en/model-config#extended-thinking>) configuration, so it reasons with thinking enabled when your session has it enabled and stays off otherwise. Thinking affects only how the summary is produced; your session settings are unchanged afterward. What happens to each kind of content depends on how it was loaded:
Mechanism| After compaction
---|---
System prompt and output style| Unchanged; not part of message history
Project-root CLAUDE.md and unscoped rules| Re-injected from disk
Auto memory| Re-injected from disk
-Rules with `paths:` frontmatter| Lost until a matching file is read again
-Nested CLAUDE.md in subdirectories| Lost until a file in that subdirectory is read again
+The plan Claude wrote in [plan mode](</docs/en/permission-modes#analyze-before-you-edit-with-plan-mode>)| Re-injected from disk
+Rules with `paths:` frontmatter| Claude Code reloads them as Claude reads files they match
+Nested CLAUDE.md in subdirectories| Claude Code reloads them as Claude reads files in that subdirectory
+Files Claude read or edited| Claude Code re-reads up to five, most recently modified first
Invoked skill bodies| Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first
-Hooks| Not applicable; hooks run as code, not context
+Context that hooks added earlier| Summarized with the rest of the conversation
+[SessionStart hooks](</docs/en/hooks-guide#re-inject-context-after-compaction>) that match the `compact` source| Claude Code runs them and adds their output to the compacted context
-Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. They reload the next time Claude reads a matching file. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
+Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. Right after compaction, Claude Code re-reads up to five of the files Claude has read or edited in the session, choosing the ones modified most recently, and reloads the rules and nested CLAUDE.md files that apply to those files. A file over 5,000 tokens comes back as a path reference without its content, shown as `Referenced file` instead of `Read`. Its rules still reload. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
##
@@ -42,6 +45,7 @@
Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. You can also act before the automatic pass runs:
* **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
+ * **Compact part of the conversation** : run `/rewind`, select a message, and choose **Summarize from here** or **Summarize up to here**. See [Rewind and summarize](</docs/en/checkpointing#rewind-and-summarize>) for what each option keeps and how to guide the summary.
* **Compact earlier** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See [Set the auto-compact window](</docs/en/model-config#set-the-auto-compact-window>) for accepted values and overrides.
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
--- a/context-window.md
+++ b/context-window.md
@@ -42,37 +42,11 @@
Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. You can also act before the automatic pass runs:
* **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
- * **Compact earlier** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See Set the auto-compact window for accepted values and overrides.
+ * **Compact earlier** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See [Set the auto-compact window](</docs/en/model-config#set-the-auto-compact-window>) for accepted values and overrides.
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit.
-
-###
-
-
-
-Set the auto-compact window
-
-The auto-compact window is how full the context window can get before Claude Code compacts the conversation. You can set it in three places:
-
- * **For this session and later ones** : run `/autocompact` with a value, like `/autocompact 500k`. Claude Code saves it to your user settings as [`autoCompactWindow`](</docs/en/settings#available-settings>) and applies it to the current session; if a higher-priority [settings scope](</docs/en/settings#settings-precedence>) such as managed settings sets the key, the command saves your value but the session keeps that scope’s window, and the command says so. Run `/autocompact auto` to return to the window tuned for your model.
- * **For one launch** : pass [`--autocompact`](</docs/en/cli-reference#cli-flags>) when starting Claude Code. The flag overrides your saved setting for that launch without changing it, and `claude --autocompact auto` runs the session at the tuned window even if your saved setting has a value. Unlike `/autocompact`, the flag isn’t preempted by a higher-priority settings scope such as managed settings.
- * **In scripts and cloud environments** : set [`CLAUDE_CODE_AUTO_COMPACT_WINDOW`](</docs/en/env-vars>). While it’s set, it takes precedence over the command, the flag, and the setting, and `/autocompact` reports the override instead of changing the window.
-
-The command and the flag accept a window size from 100K to 1M tokens, in any of these forms:
-
- * A plain token count, such as `200000`
- * A `k` or `M` suffix, such as `500k` or `1M`
- * A bare number from 100 to 1000, meaning thousands, so `200` sets 200,000
-
-The environment variable accepts only the plain token count. Claude Code caps the window at the model’s context window. With no window size set in any of these places, Claude Code compacts when the conversation reaches the model’s context limit, except in these sessions:
-
- * [Cloud sessions](</docs/en/claude-code-on-the-web>) compact as the conversation approaches the model’s limit
- * Sonnet 4.6 and Opus 4.6 without [extended context](</docs/en/model-config#extended-context>) compact at the 200K boundary, and so do Opus 4.8 and Opus 5 when they run with a 200K context window, such as on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry
- * When you set [`CLAUDE_CODE_DISABLE_1M_CONTEXT=1`](</docs/en/env-vars>), models with a native 1M window, such as Sonnet 5 and Fable 5, compact at the 200K boundary. Before v2.1.223, Claude Code held only Sonnet 5, Opus 4.8, and Opus 5 sessions to 200K
- * Sonnet 5 compacts at the [threshold for its configuration](</docs/en/model-config#sonnet-5-context-window>)
- * Sessions on a model ID Claude Code doesn’t recognize, such as an [LLM gateway](</docs/en/llm-gateway>) alias, compact at the context window Claude Code assumes for the ID. If the ID doesn’t start with `claude-`, set [`CLAUDE_CODE_MAX_CONTEXT_TOKENS`](</docs/en/env-vars>) to correct the assumed window while keeping proactive compaction. Set [`CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1`](</docs/en/env-vars>) to have Claude Code compact only after the API rejects the conversation with Anthropic’s too-long error; that recovery doesn’t run when a gateway [rewrites the error](</docs/en/llm-gateway-connect#troubleshoot-gateway-errors>)
+If you need a larger window rather than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit. The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](</docs/en/model-config#default-auto-compact-thresholds>) for the boundaries per model, and [Correct the window for a gateway or custom model ID](</docs/en/model-config#correct-the-window-for-a-gateway-or-custom-model-id>) if Claude Code assumes the wrong window for your model ID, such as an [LLM gateway](</docs/en/llm-gateway>) alias.
##
--- a/context-window.md
+++ b/context-window.md
@@ -66,11 +66,13 @@
* A `k` or `M` suffix, such as `500k` or `1M`
* A bare number from 100 to 1000, meaning thousands, so `200` sets 200,000
-The environment variable accepts only the plain token count. Claude Code caps the window at the model’s context window. With no window size set in any of these places, Claude Code compacts when the conversation reaches the model’s context limit, except in these sessions, which compact earlier:
+The environment variable accepts only the plain token count. Claude Code caps the window at the model’s context window. With no window size set in any of these places, Claude Code compacts when the conversation reaches the model’s context limit, except in these sessions:
* [Cloud sessions](</docs/en/claude-code-on-the-web>) compact as the conversation approaches the model’s limit
* Sonnet 4.6 and Opus 4.6 without [extended context](</docs/en/model-config#extended-context>) compact at the 200K boundary, and so do Opus 4.8 and Opus 5 when they run with a 200K context window, such as on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry
- * Sonnet 5 compacts at the model’s [default threshold](</docs/en/model-config#sonnet-5-context-window>)
+ * When you set [`CLAUDE_CODE_DISABLE_1M_CONTEXT=1`](</docs/en/env-vars>), models with a native 1M window, such as Sonnet 5 and Fable 5, compact at the 200K boundary. Before v2.1.223, Claude Code held only Sonnet 5, Opus 4.8, and Opus 5 sessions to 200K
+ * Sonnet 5 compacts at the [threshold for its configuration](</docs/en/model-config#sonnet-5-context-window>)
+ * Sessions on a model ID Claude Code doesn’t recognize, such as an [LLM gateway](</docs/en/llm-gateway>) alias, compact at the context window Claude Code assumes for the ID. If the ID doesn’t start with `claude-`, set [`CLAUDE_CODE_MAX_CONTEXT_TOKENS`](</docs/en/env-vars>) to correct the assumed window while keeping proactive compaction. Set [`CLAUDE_CODE_DISABLE_UNKNOWN_MODEL_WINDOW_ENFORCEMENT=1`](</docs/en/env-vars>) to have Claude Code compact only after the API rejects the conversation with Anthropic’s too-long error; that recovery doesn’t run when a gateway [rewrites the error](</docs/en/llm-gateway-connect#troubleshoot-gateway-errors>)
##
--- a/context-window.md
+++ b/context-window.md
@@ -42,10 +42,35 @@
Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. You can also act before the automatic pass runs:
* **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
+ * **Compact earlier** : run [`/autocompact`](</docs/en/commands#all-commands>) with a token count, like `/autocompact 500k`, to set how full the context window gets before the automatic pass runs. See Set the auto-compact window for accepted values and overrides.
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
If you need a larger window rather than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit.
+
+###
+
+
+
+Set the auto-compact window
+
+The auto-compact window is how full the context window can get before Claude Code compacts the conversation. You can set it in three places:
+
+ * **For this session and later ones** : run `/autocompact` with a value, like `/autocompact 500k`. Claude Code saves it to your user settings as [`autoCompactWindow`](</docs/en/settings#available-settings>) and applies it to the current session; if a higher-priority [settings scope](</docs/en/settings#settings-precedence>) such as managed settings sets the key, the command saves your value but the session keeps that scope’s window, and the command says so. Run `/autocompact auto` to return to the window tuned for your model.
+ * **For one launch** : pass [`--autocompact`](</docs/en/cli-reference#cli-flags>) when starting Claude Code. The flag overrides your saved setting for that launch without changing it, and `claude --autocompact auto` runs the session at the tuned window even if your saved setting has a value. Unlike `/autocompact`, the flag isn’t preempted by a higher-priority settings scope such as managed settings.
+ * **In scripts and cloud environments** : set [`CLAUDE_CODE_AUTO_COMPACT_WINDOW`](</docs/en/env-vars>). While it’s set, it takes precedence over the command, the flag, and the setting, and `/autocompact` reports the override instead of changing the window.
+
+The command and the flag accept a window size from 100K to 1M tokens, in any of these forms:
+
+ * A plain token count, such as `200000`
+ * A `k` or `M` suffix, such as `500k` or `1M`
+ * A bare number from 100 to 1000, meaning thousands, so `200` sets 200,000
+
+The environment variable accepts only the plain token count. Claude Code caps the window at the model’s context window. With no window size set in any of these places, Claude Code compacts when the conversation reaches the model’s context limit, except in these sessions, which compact earlier:
+
+ * [Cloud sessions](</docs/en/claude-code-on-the-web>) compact as the conversation approaches the model’s limit
+ * Sonnet 4.6 and Opus 4.6 without [extended context](</docs/en/model-config#extended-context>) compact at the 200K boundary, and so do Opus 4.8 and Opus 5 when they run with a 200K context window, such as on Amazon Bedrock, Google Cloud’s Agent Platform, and Microsoft Foundry
+ * Sonnet 5 compacts at the model’s [default threshold](</docs/en/model-config#sonnet-5-context-window>)
##
--- a/context-window.md
+++ b/context-window.md
@@ -53,7 +53,7 @@
Check your own session
-The visualization uses representative numbers. To see your actual context usage at any point, run `/context` for a live breakdown by category with optimization suggestions. Run `/memory` to check which CLAUDE.md and auto memory files loaded at startup.
+The visualization uses representative numbers. To see your actual context usage at any point, run `/context` for a live breakdown by category with optimization suggestions, including which CLAUDE.md and auto memory files loaded. Run `/memory` to open and edit those files.
##
--- a/context-window.md
+++ b/context-window.md
@@ -19,7 +19,7 @@
What survives compaction
-When a long session compacts, Claude Code summarizes the conversation history to fit the context window. What happens to your instructions depends on how they were loaded:
+When a long session compacts, Claude Code summarizes the conversation history to fit the context window. As of v2.1.198, the summarization request inherits your session’s [extended thinking](</docs/en/model-config#extended-thinking>) configuration, so it reasons with thinking enabled when your session has it enabled and stays off otherwise. Thinking affects only how the summary is produced; your session settings are unchanged afterward. What happens to your instructions depends on how they were loaded:
Mechanism| After compaction
---|---
--- a/context-window.md
+++ b/context-window.md
@@ -45,7 +45,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Fable 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.
+If you need a larger window rather than a smaller conversation, Fable 5, Sonnet 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Sonnet 5 runs at 1M with no `[1m]` variant to select; see [Sonnet 5 context window](</docs/en/model-config#sonnet-5-context-window>) for its auto-compaction thresholds and the LLM gateway exception. Compaction works the same way at the larger limit.
##
--- a/context-window.md
+++ b/context-window.md
@@ -45,7 +45,7 @@
* **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
* **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
-If you need a larger window rather than a smaller conversation, Opus 4.6 and later, and Sonnet 4.6, support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.
+If you need a larger window rather than a smaller conversation, Fable 5, Opus 4.6 and later, and Sonnet 4.6 support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.
##
--- a/context-window.md
+++ b/context-window.md
@@ -1,10 +1,4 @@
-> ## 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.
-
-Claude Code’s context window holds everything Claude knows about your session: your instructions, the files it reads, its own responses, and content that never appears in your terminal. The timeline below walks through what loads and when. See the written breakdown for the same content as a list.
+Claude Code’s context window holds everything Claude knows about your session: your instructions, the files it reads, its own responses, and content that never appears in your terminal. The timeline below plays a full session from startup to compaction: what loads before you type, what each file read, rule, and hook adds as Claude works, and how a subagent keeps large reads out of your context. See the written breakdown for the same content as a list.
##
@@ -43,6 +37,20 @@
+When your context fills up
+
+Claude Code compacts automatically as you approach the limit, so a full context window doesn’t end your session. The automatic pass works the same way as the `/compact` step in the timeline. See [When context fills up](</docs/en/how-claude-code-works#when-context-fills-up>) for what it preserves. You can also act before the automatic pass runs:
+
+ * **Compact with a focus** : run `/compact` with instructions, like `/compact focus on the auth bug fix`, before starting a long new task. The summary keeps what you choose instead of what the automatic pass guesses is important.
+ * **Clear between tasks** : run `/clear` when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
+ * **Delegate large reads** : send research to a [subagent](</docs/en/sub-agents>) so the file contents stay in its context window, not yours.
+
+If you need a larger window rather than a smaller conversation, Opus 4.6 and later, and Sonnet 4.6, support a 1 million token context window. See [Extended context](</docs/en/model-config#extended-context>) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.
+
+##
+
+
+
Check your own session
The visualization uses representative numbers. To see your actual context usage at any point, run `/context` for a live breakdown by category with optimization suggestions. Run `/memory` to check which CLAUDE.md and auto memory files loaded at startup.
--- a/context-window.md
+++ b/context-window.md
@@ -59,4 +59,5 @@
* [Store instructions and memories](</docs/en/memory>): CLAUDE.md hierarchy and auto memory
* [Subagents](</docs/en/sub-agents>): delegate research to a separate context window
* [Best practices](</docs/en/best-practices>): managing context as your primary constraint
+ * [Prompt caching](</docs/en/prompt-caching>): which actions invalidate the cached prefix
* [Reduce token usage](</docs/en/costs#reduce-token-usage>): strategies for keeping context usage low
--- a/context-window.md
+++ b/context-window.md
@@ -1,3 +1,9 @@
+> ## 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.
+
Claude Code’s context window holds everything Claude knows about your session: your instructions, the files it reads, its own responses, and content that never appears in your terminal. The timeline below walks through what loads and when. See the written breakdown for the same content as a list.
##
--- a/context-window.md
+++ b/context-window.md
@@ -11,7 +11,27 @@
* **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>), which both go into the system prompt the same way.
* **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
* **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
- * **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically. The [skill](</docs/en/skills>) listing is the one exception.
+ * **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically; the table below shows what happens to each mechanism.
+
+##
+
+
+
+What survives compaction
+
+When a long session compacts, Claude Code summarizes the conversation history to fit the context window. What happens to your instructions depends on how they were loaded:
+
+Mechanism| After compaction
+---|---
+System prompt and output style| Unchanged; not part of message history
+Project-root CLAUDE.md and unscoped rules| Re-injected from disk
+Auto memory| Re-injected from disk
+Rules with `paths:` frontmatter| Lost until a matching file is read again
+Nested CLAUDE.md in subdirectories| Lost until a file in that subdirectory is read again
+Invoked skill bodies| Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first
+Hooks| Not applicable; hooks run as code, not context
+
+Path-scoped rules and nested CLAUDE.md files load into message history when their trigger file is read, so compaction summarizes them away with everything else. They reload the next time Claude reads a matching file. If a rule must persist across compaction, drop the `paths:` frontmatter or move it to the project-root CLAUDE.md. Skill bodies are re-injected after compaction, but large skills are truncated to fit the per-skill cap, and the oldest invoked skills are dropped once the total budget is exceeded. Truncation keeps the start of the file, so put the most important instructions near the top of `SKILL.md`.
##
--- a/context-window.md
+++ b/context-window.md
@@ -0,0 +1,36 @@
+Claude Code’s context window holds everything Claude knows about your session: your instructions, the files it reads, its own responses, and content that never appears in your terminal. The timeline below walks through what loads and when. See the written breakdown for the same content as a list.
+
+##
+
+
+
+What the timeline shows
+
+The session walks through a realistic flow with representative token counts:
+
+ * **Before you type anything** : CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. Your own setup may add more here, like an [output style](</docs/en/output-styles>) or text from [`--append-system-prompt`](</docs/en/cli-reference>), which both go into the system prompt the same way.
+ * **As Claude works** : each file read adds to context, [path-scoped rules](</docs/en/memory#path-specific-rules>) load automatically alongside matching files, and a [PostToolUse hook](</docs/en/hooks-guide>) fires after each edit.
+ * **The follow-up prompt** : a [subagent](</docs/en/sub-agents>) handles the research in its own separate context window, so the large file reads stay out of yours. Only the summary and a small metadata trailer come back.
+ * **At the end** : `/compact` replaces the conversation with a structured summary. Most startup content reloads automatically. The [skill](</docs/en/skills>) listing is the one exception.
+
+##
+
+
+
+Check your own session
+
+The visualization uses representative numbers. To see your actual context usage at any point, run `/context` for a live breakdown by category with optimization suggestions. Run `/memory` to check which CLAUDE.md and auto memory files loaded at startup.
+
+##
+
+
+
+Related resources
+
+For deeper coverage of the features shown in the timeline, see these pages:
+
+ * [Extend Claude Code](</docs/en/features-overview>): when to use CLAUDE.md vs skills vs rules vs hooks vs MCP
+ * [Store instructions and memories](</docs/en/memory>): CLAUDE.md hierarchy and auto memory
+ * [Subagents](</docs/en/sub-agents>): delegate research to a separate context window
+ * [Best practices](</docs/en/best-practices>): managing context as your primary constraint
+ * [Reduce token usage](</docs/en/costs#reduce-token-usage>): strategies for keeping context usage low