Skip to main content
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

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 or text from --append-system-prompt, which both go into the system prompt the same way.
  • As Claude works: each file read adds to context, path-scoped rules load automatically alongside matching files, and a PostToolUse hook fires after each edit.
  • The follow-up prompt: a subagent 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.

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 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: 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.

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 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 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 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 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 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 and applies it to the current session; if a higher-priority settings scope 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 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. 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 compact as the conversation approaches the model’s limit
  • Sonnet 4.6 and Opus 4.6 without 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

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. For deeper coverage of the features shown in the timeline, see these pages:
⌂ Proxy