12 12
13The session walks through a realistic flow with representative token counts:13The session walks through a realistic flow with representative token counts:
14 14
15* **Before you type anything**: CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](/docs/en/memory.md#agents-md) can load in place of CLAUDE.md. Your own setup may add more here, like an [output style](/docs/en/output-styles.md) or text from [`--append-system-prompt`](/docs/en/cli-reference).15* **Before you type anything**: CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context. [AGENTS.md files](https://code.claude.com/docs/en/memory.md#agents-md) can load in place of CLAUDE.md. Your own setup may add more here, like an [output style](https://code.claude.com/docs/en/output-styles.md) or text from [`--append-system-prompt`](https://code.claude.com/docs/en/cli-reference).
16* **As Claude works**: each file read adds to context, [path-scoped rules](/docs/en/memory.md#path-specific-rules) load automatically alongside matching files, and a [PostToolUse hook](/docs/en/hooks-guide.md) fires after each edit.16* **As Claude works**: each file read adds to context, [path-scoped rules](https://code.claude.com/docs/en/memory.md#path-specific-rules) load automatically alongside matching files, and a [PostToolUse hook](https://code.claude.com/docs/en/hooks-guide.md) fires after each edit.
17* **The follow-up prompt**: a [subagent](/docs/en/sub-agents.md) 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.17* **The follow-up prompt**: a [subagent](https://code.claude.com/docs/en/sub-agents.md) 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.
18* **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.18* **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.
19 19
20## What survives compaction20## What survives compaction
21 21
22When 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.md#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:22When 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](https://code.claude.com/docs/en/model-config.md#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:
23 23
24| Mechanism | After compaction |24| Mechanism | After compaction |
25| :- | :- |25| :- | :- |
26| System prompt and output style | Both still apply |26| System prompt and output style | Both still apply |
27| Project-root CLAUDE.md and unscoped rules | Re-injected from disk |27| Project-root CLAUDE.md and unscoped rules | Re-injected from disk |
28| Auto memory | Re-injected from disk |28| Auto memory | Re-injected from disk |
29| Skill descriptions | Rebuilt from your current [skills](/docs/en/skills.md) and re-injected. Requires Claude Code v2.1.304 or later |29| Skill descriptions | Rebuilt from your current [skills](https://code.claude.com/docs/en/skills.md) and re-injected. Requires Claude Code v2.1.304 or later |
30| [Git status snapshot](/docs/en/settings-reference.md#includegitinstructions) | If the session started with one, Claude Code reads a fresh one from your repository |30| [Git status snapshot](https://code.claude.com/docs/en/settings-reference.md#includegitinstructions) | If the session started with one, Claude Code reads a fresh one from your repository |
31| The plan Claude wrote in [plan mode](/docs/en/permission-modes.md#analyze-before-you-edit-with-plan-mode) | Re-injected from disk |31| The plan Claude wrote in [plan mode](https://code.claude.com/docs/en/permission-modes.md#analyze-before-you-edit-with-plan-mode) | Re-injected from disk |
32| Rules with `paths:` frontmatter | Claude Code reloads them [on demand](/docs/en/memory.md#path-specific-rules) |32| Rules with `paths:` frontmatter | Claude Code reloads them [on demand](https://code.claude.com/docs/en/memory.md#path-specific-rules) |
33| Nested CLAUDE.md in subdirectories | Claude Code reloads them [on demand](/docs/en/memory.md#how-claude-md-files-load) |33| Nested CLAUDE.md in subdirectories | Claude Code reloads them [on demand](https://code.claude.com/docs/en/memory.md#how-claude-md-files-load) |
34| Files Claude read or edited | Claude Code re-reads up to five, most recently modified first |34| Files Claude read or edited | Claude Code re-reads up to five, most recently modified first |
35| Invoked skill bodies | Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first |35| Invoked skill bodies | Re-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first |
36| [Background commands](/docs/en/interactive-mode.md#background-bash-commands) and background [subagents](/docs/en/sub-agents.md#run-subagents-in-foreground-or-background) | Keep running. Claude Code reminds Claude which ones are still running so it doesn't start a duplicate |36| [Background commands](https://code.claude.com/docs/en/interactive-mode.md#background-bash-commands) and background [subagents](https://code.claude.com/docs/en/sub-agents.md#run-subagents-in-foreground-or-background) | Keep running. Claude Code reminds Claude which ones are still running so it doesn't start a duplicate |
37| Context that hooks added earlier | Summarized with the rest of the conversation |37| Context that hooks added earlier | Summarized with the rest of the conversation |
38| [SessionStart hooks](/docs/en/hooks-guide.md#re-inject-context-after-compaction) that match the `compact` source | Claude Code runs them and adds their output to the compacted context |38| [SessionStart hooks](https://code.claude.com/docs/en/hooks-guide.md#re-inject-context-after-compaction) that match the `compact` source | Claude Code runs them and adds their output to the compacted context |
39 39
40Right 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`.40Right 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`.
41 41
45 45
46## When your context fills up46## When your context fills up
47 47
48Claude 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.md#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.md#idlecompaction).48Claude 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](https://code.claude.com/docs/en/how-claude-code-works.md#when-context-fills-up) for what it preserves. For when Claude Code also compacts a conversation you leave idle, see [idle compaction](https://code.claude.com/docs/en/settings-reference.md#idlecompaction).
49 49
50You can also act before the automatic pass runs:50You can also act before the automatic pass runs:
51 51
52* **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.52* **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.
53* **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.md#rewind-and-summarize) for what each option keeps and how to guide the summary.53* **Compact part of the conversation**: run `/rewind`, select a message, and choose **Summarize from here** or **Summarize up to here**. See [Rewind and summarize](https://code.claude.com/docs/en/checkpointing.md#rewind-and-summarize) for what each option keeps and how to guide the summary.
54* **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.md#set-the-auto-compact-window) for accepted values and overrides.54* **Compact earlier**: run [`/autocompact`](https://code.claude.com/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](https://code.claude.com/docs/en/model-config.md#set-the-auto-compact-window) for accepted values and overrides.
55* **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.55* **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.
56* **Delegate large reads**: send research to a [subagent](/docs/en/sub-agents.md) so the file contents stay in its context window, not yours.56* **Delegate large reads**: send research to a [subagent](https://code.claude.com/docs/en/sub-agents.md) so the file contents stay in its context window, not yours.
57 57
58If 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.md#extended-context) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.58If 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](https://code.claude.com/docs/en/model-config.md#extended-context) for availability by plan and how to select a `[1m]` model variant. Compaction works the same way at the larger limit.
59 59
60The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](/docs/en/model-config.md#default-auto-compact-thresholds) for the boundaries per model, and [Correct the window for a gateway or custom model ID](/docs/en/model-config.md#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.60The point where automatic compaction runs depends on your model and configuration. See [Default auto-compact thresholds](https://code.claude.com/docs/en/model-config.md#default-auto-compact-thresholds) for the boundaries per model, and [Correct the window for a gateway or custom model ID](https://code.claude.com/docs/en/model-config.md#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](https://code.claude.com/docs/en/llm-gateway) alias.
61 61
62## Check your own session62## Check your own session
63 63
67 67
68For deeper coverage of the features shown in the timeline, see these pages:68For deeper coverage of the features shown in the timeline, see these pages:
69 69
70* [Extend Claude Code](/docs/en/features-overview.md): when to use CLAUDE.md vs skills vs rules vs hooks vs MCP70* [Extend Claude Code](https://code.claude.com/docs/en/features-overview.md): when to use CLAUDE.md vs skills vs rules vs hooks vs MCP
71* [Store instructions and memories](/docs/en/memory.md): CLAUDE.md hierarchy and auto memory71* [Store instructions and memories](https://code.claude.com/docs/en/memory.md): CLAUDE.md hierarchy and auto memory
72* [Subagents](/docs/en/sub-agents.md): delegate research to a separate context window72* [Subagents](https://code.claude.com/docs/en/sub-agents.md): delegate research to a separate context window
73* [Best practices](/docs/en/best-practices.md): managing context as your primary constraint73* [Best practices](https://code.claude.com/docs/en/best-practices.md): managing context as your primary constraint
74* [Prompt caching](/docs/en/prompt-caching.md): which actions invalidate the cached prefix74* [Prompt caching](https://code.claude.com/docs/en/prompt-caching.md): which actions invalidate the cached prefix
75* [Reduce token usage](/docs/en/costs.md#reduce-token-usage): strategies for keeping context usage low75* [Reduce token usage](https://code.claude.com/docs/en/costs.md#reduce-token-usage): strategies for keeping context usage low