The Context Window Lifecycle: What Gets Loaded and When
Every Claude Code session starts with a context window load sequence — system prompt, environment info, CLAUDE.md files, and MCP tool schemas. Understanding what lives in that window and how it fills up helps you avoid the two most common problems: context exhaustion and stale instructions.
Quick Reference
- →Standard context window: 200K tokens for all plans
- →1M token context available via [1m] model suffix (e.g., claude-sonnet-4-6[1m])
- →Session start loads: system prompt, environment info, all CLAUDE.md files, MCP schemas
- →Each tool call result is appended to the window — reads, edits, command outputs all consume tokens
- →Auto-compact (or /compact) summarizes history to free space when the window fills
- →Auto memory persists selected context to disk across sessions in ~/.claude/projects/
- →The window does not persist between sessions by default — use --continue to resume
- →Large CLAUDE.md files are expensive — they are re-loaded fresh every session
In this article
What Gets Loaded at Session Start
When you start a Claude Code session, the context window does not begin empty. Several pieces of content are loaded automatically before you type your first message. Understanding this load sequence explains why Claude already 'knows' things about your project when the session opens.
System Prompt
Anthropic's base instructions for Claude Code — the rules, capabilities, and constraints that are always in effect. You cannot read or modify this directly. It occupies a fixed amount of context at the top of every session.
Environment Information
Working directory, OS, shell type, current date, git status, and active model. This is how Claude knows you are on macOS, using zsh, in a specific repo, on a specific branch — without you having to tell it.
CLAUDE.md Files
All CLAUDE.md files in scope are loaded: user-level (~/.claude/CLAUDE.md), project-level (./CLAUDE.md), and any directory-level files, plus @imported files and applicable .claude/rules/ files. Every character in every loaded CLAUDE.md file consumes context.
MCP Tool Schemas
If you have MCP servers configured, their tool schemas are loaded into context. Each tool has a name, description, and parameter spec — these can collectively consume thousands of tokens if you have many MCP tools configured.
Auto Memory
If the auto memory system has stored memories from previous sessions (in ~/.claude/projects/), the MEMORY.md index is loaded. Individual memory files are loaded when referenced.
A session with a large CLAUDE.md, several MCP servers, and auto memory files may consume 10,000–30,000 tokens before you type a single character. This is context well spent, but be aware of it when diagnosing context exhaustion mid-session.
How the Window Fills During a Session
As Claude Code works, every exchange appends to the context window. This includes your messages, Claude's responses, and — importantly — the full content of every tool call result. A session that reads many large files can fill the window quickly.
| What fills the window | Token cost |
|---|---|
| Your messages and Claude's responses | Proportional to length |
| File reads (Read tool) | Full file contents each read |
| Grep/Glob results | All matched lines/paths |
| Bash output | All stdout/stderr output |
| Edit confirmations | Diff + confirmation message |
| Web search results | Extracted page content |
Reading the same file twice in one session does not deduplicate — both reads are in context. This is why Claude Code has a strong preference for reading files once and extracting all needed information, rather than reading incrementally.
Reading a 2,000-line file consumes roughly 15,000–20,000 tokens. In a 200K token session, that is 7.5–10% of your entire window for one file read. Claude Code will often read only the most relevant sections using offset and limit — this is intentional, not a limitation.
Managing Context Exhaustion
When the context window approaches its limit, Claude Code has two options: auto-compact or fail. Auto-compact (enabled by default) summarizes the conversation history to free space, allowing the session to continue. This is lossy — some detail is lost in the summary.
| Method | Command | What it does |
|---|---|---|
| Auto-compact | (automatic) | Triggered when window fills — summarizes oldest turns |
| Manual compact | /compact | Summarizes entire conversation history immediately |
| Targeted compact | Esc+Esc → Summarize from here | Compresses from a selected point forward, preserving earlier context |
| Fresh session | --continue | Resumes with just the summary from the previous session |
For tasks that span many files and many edits, use /compact after each major milestone rather than waiting for auto-compact. Proactive compaction gives you cleaner summaries and preserves the context for the next phase of work.
The 1M Token Context Window
Claude Sonnet 4.6 and Opus 4.6/4.7 support a 1 million token context window — roughly 5x the standard 200K. This changes the economics of long sessions: you can read entire codebases, accumulate extensive history, and work through large migrations without triggering compaction.
| Plan | Opus 1M | Sonnet 1M |
|---|---|---|
| Max / Team / Enterprise | Automatic (included) | Extra usage required |
| Pro | Extra usage required | Extra usage required |
| API / Pay-as-you-go | Full access | Full access |
The 1M context window uses standard model pricing — tokens beyond 200K are not charged at a premium rate. The cost difference comes from using more tokens, not a higher per-token price.
Auto Memory: Persisting Context Across Sessions
The context window resets between sessions. Auto memory is the mechanism that bridges sessions — it stores key facts about the user, project, preferences, and feedback to disk so future sessions start with relevant context already in place.
Auto memory files live in ~/.claude/projects/{encoded-path}/memory/ and are indexed by MEMORY.md. Claude automatically saves memories when it learns something worth persisting: your role, feedback about its behavior, project decisions, and references to external systems.
Tell Claude 'remember that...' or 'from now on...' and it will write a memory file. You can also ask Claude to forget something: 'forget that I prefer verbose output'. Memory files are plain Markdown — you can edit them directly in ~/.claude/projects/.
Best Practices
Do
- ✓Keep CLAUDE.md files lean — every byte is re-loaded on every session start
- ✓Use /compact proactively on long tasks rather than waiting for auto-compact
- ✓Use the 1M context window ([1m] model suffix) for codebase-wide migrations or large refactors
- ✓Split large files with offset/limit when you only need a specific section
- ✓Use auto memory to preserve important context (preferences, feedback) across sessions
Don’t
- ✗Don't read entire large files when only a specific function or section is relevant
- ✗Don't assume Claude 'remembers' previous sessions by default — start with --continue to resume
- ✗Don't ignore context exhaustion warnings — they signal the summary phase is approaching
- ✗Don't put large documentation blocks in CLAUDE.md — use @import to reference external files that aren't always loaded
Key Takeaways
- ✓The session start load sequence consumes tokens before you type: system prompt, env info, CLAUDE.md files, MCP schemas
- ✓Every tool result appends to the window — reading large files is expensive
- ✓Use /compact proactively on long tasks, or Esc+Esc to target-compact from a specific point
- ✓The 1M token context window is available on Sonnet 4.6 and Opus 4.6/4.7 via the [1m] model suffix
- ✓Auto memory persists context across sessions — use it to avoid re-explaining project context
Video on this topic
Claude Code Context Window: What's Loaded and Why
tiktok