Claude Code context window: what fills it and what survives compaction
How Claude Code's context window works: what loads at startup, what each file read adds, what survives compaction, and how to manage a full context.
Two hours into a session, Claude Code starts ignoring a convention it followed all morning. The rule is still in the repository. It loaded into the conversation when Claude first touched an API file, and the last automatic compaction summarized it away.
Knowing what's in the context window, and what survives compaction, explains most of these surprises. This guide uses Anthropic's context window explainer, checked on 16 November 2026.
What fills the window
Before you type anything:
CLAUDE.md(orAGENTS.md)- Auto memory
- MCP tool names
- Skill descriptions
As Claude works:
- Each file it reads
- Path-scoped rules, loaded alongside matching files
- Hook output, such as a
PostToolUsehook's message - Claude's own responses and tool results
What stays out: a subagent does its reading in its own context window and returns only a summary.
Run /context to see what's using space in your session right now.
What survives compaction
When the window nears its limit, Claude Code compacts: it replaces the conversation with a structured summary. Here's what happens to each piece:
| 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 |
| Skill descriptions | Rebuilt and re-injected |
| The plan from plan mode | Re-injected from disk |
Path-scoped rules (paths: frontmatter) | Reloaded only when a matching file is touched again |
Nested CLAUDE.md in subdirectories | Reloaded only when needed |
| Files Claude read or edited | Up to five re-read, most recently modified first; files over 5,000 tokens come back as a reference |
| Invoked skill bodies | Re-injected, capped at 5,000 tokens each and 25,000 total; oldest dropped first |
| Background commands and subagents | Keep running |
| Context hooks added earlier | Summarized with the conversation |
SessionStart hooks matching compact | Run again, output added |
Two practical consequences from the docs:
- A rule that must persist shouldn't be path-scoped or nested; put it in the project-root
CLAUDE.mdor drop itspaths:frontmatter. - Long skills get truncated from the end, so put the most important instructions at the top.
Managing a full context
Claude Code compacts automatically, so a full context doesn't end the session. You can do better than the automatic pass:
| Action | Command |
|---|---|
| Compact with a focus | /compact focus on the auth bug fix |
| Compact part of the conversation | /rewind, pick a message, Summarize from here or up to here |
| Compact earlier | /autocompact 500k sets how full the window gets before auto-compaction |
| Start fresh on unrelated work | /clear |
| Keep large reads out | Delegate research to a subagent |
Why it matters for cost
Every message re-sends what's in the context. A bloated context makes each turn slower and more expensive. See how to reduce Claude Code token usage.
Re-injecting context that must survive
A SessionStart hook that matches the compact source runs again after compaction and adds its output to the compacted context. That's the reliable way to restore information you can't afford to lose mid-session. See Claude Code hooks: 6 examples.
Where Lockstep fits
Lockstep's Claude Code briefing uses hooks, so the team's approved decisions that apply to the work are part of the session's context from the start rather than something someone has to paste in again. The decisions come from PRDs, Slack, and pull requests, approved by their owners.
See how it works.
Sources checked 16 November 2026
Related reading
For how memory loads, see how Claude Code memory works. For why long contexts degrade, see context rot and compaction. For the caching side, see prompt caching explained.
Frequently asked questions
- What loads into Claude Code's context window at startup?
- Before you type anything: CLAUDE.md (or AGENTS.md), auto memory, MCP tool names, and skill descriptions, per Anthropic's docs. Your setup may add more. File contents, path-scoped rules, and hook output load as Claude works.
- What happens when Claude Code's context window fills up?
- It compacts automatically as you approach the limit, replacing the conversation with a structured summary, so a full context doesn't end the session. You can compact earlier with /compact, set the threshold with /autocompact, or clear with /clear.
- What survives compaction in Claude Code?
- The system prompt and output style still apply; project-root CLAUDE.md, unscoped rules, auto memory, skill descriptions, and the plan-mode plan are re-injected; up to five recently modified files are re-read; invoked skill bodies come back with size caps. Path-scoped rules and nested CLAUDE.md files reload only when needed.
- Why does Claude forget a rule after compaction?
- Path-scoped rules and nested CLAUDE.md files load into the message history when their trigger file is touched, so compaction summarizes them away. Anthropic's docs suggest dropping the paths frontmatter or moving a rule into the project-root CLAUDE.md if it must persist.
- How do I reduce what fills the context window?
- Clear between unrelated tasks, compact with a focus, send large reads to subagents so file contents stay in their context, keep CLAUDE.md short, and move long procedures into skills that load only when used.
Keep reading