When a Claude Code session approaches its context limit, Claude Code compacts automatically: it replaces the older conversation with a structured summary and carries on, so the session does not end. After compaction it re-injects your project-root CLAUDE.md, auto memory, skill descriptions and any plan file from disk, and re-reads up to five recently edited files. Details from the middle of the conversation survive only as far as the summary keeps them. To stay in control, run /context to see what fills the window, /compact with focus instructions before a big new task, and /clear when you switch to unrelated work.
What fills the context window in the first place?
The context window docs split it into two parts:
- Before you type anything: the system prompt,
CLAUDE.mdfiles, auto memory, MCP tool names and skill descriptions. - As Claude works: every file it reads, path-scoped rules that load with matching files, hook output, command output such as test runs, and Claude's own responses.
Every request sends the whole conversation again. That is why one long session gets slower and more expensive over time, and why a session that has read forty files eventually needs to make room.
What does auto-compaction do?
As you approach the limit, Claude Code runs the same step as /compact on its own. It summarizes the conversation history to fit the context window, then reloads the parts that live on disk. The exact threshold depends on your model and settings; the docs list the defaults per model under the auto-compact window in model configuration.
What survives compaction and what does not?
| Item | After compaction |
|---|---|
| System prompt and output style | Still apply |
Project-root CLAUDE.md and unscoped rules | Re-injected from disk |
| Auto memory | Re-injected from disk |
| Plan written in plan mode | Re-injected from disk |
| Files Claude read or edited | Up to five re-read, most recently modified first; a file over 5,000 tokens comes back as a path reference only |
| Invoked skill bodies | Re-injected, capped at 5,000 tokens per skill and 25,000 in total |
Rules with paths: frontmatter and nested CLAUDE.md | Summarized away, then reloaded on demand when Claude touches a matching file |
| Context that hooks added | Summarized with the rest of the conversation |
| Background commands and subagents | Keep running |
Two practical consequences. First, anything that must hold for the whole session belongs in the root CLAUDE.md or a plan file, not in a chat message from an hour ago. Second, if a skill matters, put its key instructions at the top of SKILL.md, because truncation keeps the start of the file.
How do I check how full the context is?
Run /context. It draws current usage as a colored grid by category and suggests fixes for context-heavy tools, oversized memory files and capacity warnings. /context all also lists which CLAUDE.md and memory files loaded. For a running number on screen, the docs show how to put context usage in the status line.
Which command should I use?
| Situation | Command | What happens |
|---|---|---|
| Same task, but the history is long | /compact focus on the auth bug | Summary keeps what you name instead of what the automatic pass guesses |
| Only part of the history is noise | /rewind, then Summarize from here or up to here | Compresses one stretch and keeps the rest word for word |
| Switching to unrelated work | /clear | Fresh conversation with empty context; old one stays in /resume |
| Compaction happens too late for you | /autocompact with a token count | Sets how full the window gets before the automatic pass runs |
| A task needs lots of reading | Ask Claude to use a subagent | File reads stay in the subagent's own window; only a summary returns |
One cost note from the costs page: /compact reads the whole conversation to summarize it, so compacting a large context is itself a large request. When you want a fresh start rather than continuity, /clear costs nothing.
How do I run out of context less often?
- Keep
CLAUDE.mdshort. The costs docs suggest under 200 lines. Move workflow-specific instructions into skills, which load only when used. - Clear between tasks. Stale history costs tokens on every message.
- Delegate verbose work. Test runs, log reading and wide searches belong in subagents.
- Filter output before Claude sees it. A PreToolUse hook can trim test output to its last lines; see our hooks guide.
- Disable MCP servers you are not using. Run
/mcpand turn off the idle ones. - Write specific prompts. "Add input validation to the login function in auth.ts" reads far less than "improve this codebase".
- Use a larger window when the task needs it. Several current models support a 1 million token context; the docs explain how to pick a
[1m]variant where your plan allows it.
FAQ
Does Claude Code stop working when the context is full?
No. It compacts automatically and continues. You only lose detail that the summary leaves out.
Why did Claude forget an instruction after compaction?
Instructions given in chat are summarized with everything else. Put rules that must last in the project-root CLAUDE.md, which is re-injected from disk after every compaction.
Can I tell compaction what to keep?
Yes. Pass instructions to /compact, or add a "Compact instructions" section to CLAUDE.md describing what summaries should focus on.
Is /clear the same as /compact?
No. /clear starts an empty conversation and keeps the old one available through /resume. /compact keeps working in the same conversation with a summary in place of the history.
Sources
Checked against the official docs on November 17, 2026: Explore the context window, Manage costs effectively, Commands and Checkpointing.
See every current command and shortcut in one reference.