CoreCodeBlog

Guides

Claude Code context window explained: what fills it, and what /compact keeps

Published · Last checked

The 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. This page walks through Anthropic's Explore the context window documentation: what loads at startup, how to check usage, what happens when the window fills, what is still there after /compact, and how /compact, /clear and /rewind each work. The documentation was checked on October 30, 2026.

Key points
  • The context window holds more than your conversation: CLAUDE.md, auto memory, MCP tool names and skill descriptions all load before you type anything.
  • Run /context for a live breakdown by category with optimization suggestions.
  • Claude Code compacts automatically as you approach the limit, so a full context window does not end your session.
  • After compaction, the project-root CLAUDE.md and auto memory are re-injected from disk. Rules with paths: and nested CLAUDE.md files are reloaded on demand instead.
  • To make the summary keep what you care about, run /compact with instructions, such as /compact focus on the auth bug fix. Use /clear when switching to unrelated work.

What goes into the context window

The documentation uses an interactive timeline that plays a session from startup to compaction. Its token counts are representative, not your real usage. As the documentation describes it, the order is roughly this:

For writing subagents, see Claude Code subagents. For skills, see Claude Code skills. For CLAUDE.md, see how to write CLAUDE.md.

How to check context usage

The documentation says to run /context at any point to see your actual usage: 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.

The commands reference describes the two commands like this:

CommandWhat the documentation says
/context [all]Visualizes current context usage as a colored grid, with optimization suggestions for context-heavy tools, memory bloat, and capacity warnings. When the conversation exceeds the context window, the output includes a warning showing how far over the limit you are and which command frees space. In fullscreen mode, /context collapses the per-item breakdown to keep the grid visible. Pass all to expand it.
/memoryEdits CLAUDE.md files, enables or disables auto memory, and views auto memory entries.

The costs documentation adds that /usage checks your current token usage, and that you can configure your status line to display it continuously. /usage shows session cost, plan usage limits, and activity stats.

What happens when the context fills up

Claude Code compacts automatically as you approach the limit, so a full context window does not end your session. The automatic pass works the same way as the /compact step in the timeline.

The point where automatic compaction runs depends on your model and configuration. The documentation keeps the per-model default thresholds, and the fix for when Claude Code assumes the wrong window for your model ID, on the model-config page. This page gives no specific numbers.

If you need a larger window rather than a smaller conversation: the documentation says 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. Availability by plan and how to select a [1m] model variant are in its Extended context section. It also says compaction works the same way at the larger limit.

What survives compaction and what does not

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 each kind of content depends on how it was loaded:

MechanismAfter compaction
System prompt and output styleBoth still apply
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Skill descriptionsRebuilt from your current skills and re-injected. Requires Claude Code v2.1.304 or later
Git status snapshotIf the session started with one, Claude Code reads a fresh one from your repository
The plan Claude wrote in plan modeRe-injected from disk
Rules with paths: frontmatterClaude Code reloads them on demand
Nested CLAUDE.md in subdirectoriesClaude Code reloads them on demand
Files Claude read or editedClaude Code re-reads up to five, most recently modified first
Invoked skill bodiesRe-injected, capped at 5,000 tokens per skill and 25,000 tokens total; oldest dropped first
Background commands and background subagentsKeep running. Claude Code reminds Claude which ones are still running so it does not start a duplicate
Context that hooks added earlierSummarized with the rest of the conversation
SessionStart hooks that match the compact sourceClaude Code runs them and adds their output to the compacted context

Three details the documentation calls out:

What you can do before it compacts

You can act before the automatic pass runs. The documentation lists five ways:

ApproachHow
Compact with a focusRun /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 conversationRun /rewind, select a message, and choose Summarize from here or Summarize up to here.
Compact earlierRun /autocompact with a token count, like /autocompact 500k, to set how full the context window gets before the automatic pass runs.
Clear between tasksRun /clear when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message.
Delegate large readsSend research to a subagent so the file contents stay in its context window, not yours.

The commands reference says this about the commands involved:

CommandWhat the documentation says
/compact [instructions]Frees up context by summarizing the conversation so far. Optionally pass focus instructions for the summary.
/clear [name]Starts a new conversation with empty context. Pass a name to label the previous conversation in the /resume picker. To free up context while continuing the same conversation, use /compact instead. Resume the previous conversation with /resume. Aliases: /reset, /new.
/rewindRewinds the conversation and/or code to a previous point, or summarizes from a selected message. Aliases: /checkpoint, /undo.
/autocompact [auto|<tokens>]Sets the auto-compact window: how full the context window gets before Claude Code compacts automatically. Pass a size such as 500k, or auto to return to the window tuned for your model. Claude Code saves the value to user settings and applies it to the current session. Requires Claude Code v2.1.221 or later.

Keeping context lean

The context-related advice from the costs documentation:

For what these habits do to your bill, see our guide to saving tokens, and for cache behavior see our cache guide. This page stays on how the context itself works.

FAQ

Does a full context window end my session?

No. The documentation says Claude Code compacts automatically as you approach the limit, so a full context window does not end your session. You can also run /compact yourself before that happens and use focus instructions to decide what the summary keeps. Where automatic compaction runs depends on your model and configuration.

Do the rules in my CLAUDE.md survive compaction?

The project-root CLAUDE.md and unscoped rules are re-injected from disk. Rules with paths: frontmatter and nested CLAUDE.md files in subdirectories differ: they are reloaded on demand, and compaction summarizes them away. If a rule must persist across compaction, the documentation says to drop the paths: frontmatter or move it to the project-root CLAUDE.md.

What is the difference between /compact and /clear?

/compact frees up context by summarizing the conversation, and the conversation continues. /clear starts a new conversation with empty context, and the previous one can be resumed with /resume. The commands reference is direct about it: to free up context while continuing the same conversation, use /compact. For switching to unrelated work, the documentation recommends /clear.

Sources