← All posts

What Happens When Claude Code Runs Out of Context?

A long Claude Code session does not just stop when the context window fills. It summarizes itself. Here is what that summary keeps, what it drops, and the commands that let you decide instead.

November 17, 2026 7 min read Guide
Quick answer

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:

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?

ItemAfter compaction
System prompt and output styleStill apply
Project-root CLAUDE.md and unscoped rulesRe-injected from disk
Auto memoryRe-injected from disk
Plan written in plan modeRe-injected from disk
Files Claude read or editedUp to five re-read, most recently modified first; a file over 5,000 tokens comes back as a path reference only
Invoked skill bodiesRe-injected, capped at 5,000 tokens per skill and 25,000 in total
Rules with paths: frontmatter and nested CLAUDE.mdSummarized away, then reloaded on demand when Claude touches a matching file
Context that hooks addedSummarized with the rest of the conversation
Background commands and subagentsKeep 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?

SituationCommandWhat happens
Same task, but the history is long/compact focus on the auth bugSummary 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 hereCompresses one stretch and keeps the rest word for word
Switching to unrelated work/clearFresh conversation with empty context; old one stays in /resume
Compaction happens too late for you/autocompact with a token countSets how full the window gets before the automatic pass runs
A task needs lots of readingAsk Claude to use a subagentFile 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?

  1. Keep CLAUDE.md short. The costs docs suggest under 200 lines. Move workflow-specific instructions into skills, which load only when used.
  2. Clear between tasks. Stale history costs tokens on every message.
  3. Delegate verbose work. Test runs, log reading and wide searches belong in subagents.
  4. Filter output before Claude sees it. A PreToolUse hook can trim test output to its last lines; see our hooks guide.
  5. Disable MCP servers you are not using. Run /mcp and turn off the idle ones.
  6. Write specific prompts. "Add input validation to the login function in auth.ts" reads far less than "improve this codebase".
  7. 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.

Open the Claude Code Cheatsheet →