Context window
Understand Claude's most important limit — and how to manage it
⏱ Est. ~5 min
01 · Read
Claude's context window is like a desk. Everything Claude is thinking about has to fit on that desk — your conversation, the contents of files it reads, command outputs, CLAUDE.md, loaded skills, MCP tool descriptions, system instructions.
When the desk fills up, Claude has to push older stuff off to make room for new stuff. When that happens, Claude may forget instructions you gave earlier, or lose track of which files it has read.
This is the single most important concept for using Claude Code effectively.
💡 Picture thisImagine working with a brilliant coworker whose desk only fits 50 pages. Every time you hand them a new document, an old one falls off. Keep handing them new files and eventually your original instructions slide off the desk. Understanding this limit is the key to productive sessions.
Key points
- The context window holds everything Claude is "thinking about"
- Includes conversation, files, command output, CLAUDE.md, skills, MCP tools
- When full, older content is automatically removed
- That's why CLAUDE.md matters — it's always reloaded, even after compaction
02 · Read
Not everything uses the same amount of context. Reading a large file dumps the whole thing into the window. Long command output consumes tokens. Each MCP tool description takes up space (that's why Tool Search exists).
Rough guide — CLAUDE.md uses 2-5k tokens depending on size. Each file read uses tokens proportional to file size. Command output (like test results or build errors) can be unexpectedly large. Skills load on demand, only consuming tokens when activated. MCP tools consume tokens for their descriptions.
Key insight — keep the initial context lean and let Claude load what it needs.
Key points
- CLAUDE.md: 2-5k tokens (keep under 200 lines)
- File reads: proportional to file size
- Command output: can be huge (test suites, build logs)
- Skills: on demand — zero cost at startup
- MCP tools: descriptions consume tokens (Tool Search helps)
03 · Code example
Claude Code gives you tools to monitor context usage and free up space when needed.
See context usage
/context
Compact with a focus instruction
/compact Focus on the API changes and test failures
Clear between unrelated tasks
/clear
Use /context to see how full the window is. When it's getting crowded, /compact summarizes the conversation and keeps what's important — add a focus instruction to tell Claude what to keep. Between completely unrelated tasks, use /clear to reset everything (but CLAUDE.md is reloaded automatically).
04 · Read
When the context gets too full, Claude Code compacts automatically. It summarizes the conversation, keeping recent work and key decisions while condensing older exchanges.
After compaction — whether automatic or manual — Claude re-reads CLAUDE.md from disk. That means things in CLAUDE.md survive compaction. Things only in the conversation might not.
This is the fundamental reason to put important rules in CLAUDE.md rather than just saying them in conversation.
Key points
- Claude compacts automatically as it approaches the limit
- Compaction summarizes old conversation, keeps recent work
- CLAUDE.md is always re-read after compaction
- CLAUDE.md rules survive; spoken instructions might not
- Use /compact proactively before auto-compaction kicks in
05 · Quiz
Early in a long session you told Claude "always use Bun, never npm". After auto-compaction, Claude starts using npm. Why?
- Claude is deliberately ignoring your instructions
- Bun isn't compatible with Claude Code
- You have to restart Claude Code for instructions to take effect
- Spoken instructions are lost during compaction — put them in CLAUDE.md
06 · Drag to sort
Think about how each kind of content affects the context window. Sort them from most context-efficient to least.
(This section is interactive — please enable JavaScript.)
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.