Claude Code Context Window
Definition
The context-window mechanism in Claude Code: what loads at startup, what survives compaction, manual levers, the 1M-token cap, and the /context diagnostic (captured from code.claude.com/docs/en/context-window, 2026-07-31).
Key Points
- Startup context is a fixed cost before typing — CLAUDE.md, auto memory, MCP tool names, and skill descriptions all load into context before any input; output style and
--append-system-promptgo into the system prompt. - What survives
/compactdepends on the loading mechanism — system prompt/output style unchanged; project-root CLAUDE.md, unscoped rules, auto memory re-injected from disk;paths:-scoped rules and nested CLAUDE.md files lost until a matching file is read again; invoked skill bodies re-injected capped at 5,000 tokens/skill and 25,000 total (oldest dropped first, start of file kept). Guidance: “put the most important instructions near the top ofSKILL.md”; “If a rule must persist across compaction, drop thepaths:frontmatter.” - Manual levers before auto-compaction —
/compactwith focus instructions (e.g./compact focus on the auth bug fix),/clearbetween unrelated tasks, or delegate large reads to a subagent so file contents stay in the subagent’s separate context window (“only the summary and a small metadata trailer come back”). - 1M-token context is model-gated — Fable 5, Sonnet 5, Opus 4.6 and later, Sonnet 4.6 support 1M; Sonnet 5 runs at 1M with no
[1m]variant; compaction works the same at the larger limit. /contextis the diagnostic command — live breakdown by category with optimization suggestions, including which CLAUDE.md and auto-memory files loaded; the visualization uses representative (not measured) numbers.
Implications
This is the mechanism behind token-usage-reduction’s context levers. The compaction re-injection behavior matters for skills: the 5k/25k caps and “oldest dropped first” mean skill authors must front-load critical instructions (same guidance as skill-reducer’s progressive disclosure, converging from a different direction). The /context “representative numbers” caveat reinforces the vault-wide rule: token figures need baseline scrutiny (see paper).
Open Questions
- Version-sensitive: as of v2.1.198 the summarization request inherits extended thinking config; the 1M-model list (Fable 5, Sonnet 5, Opus 4.6+, Sonnet 4.6) drifts; Fable 5/Sonnet 5 postdate the vault’s model pages.
- All token counts in the timeline are “representative,” so no hard per-read figures should be cited.
Related
claude-code-sessions — /clear, /compact, /context shared context-control surface
claude-code-memory — what loads into context each session (CLAUDE.md, auto memory, path-scoped rules)
token-usage-reduction — context hygiene, subagent delegation, compaction as cost levers
prompt-caching — which actions invalidate the cached prefix
claude-code-system-prompt — what composes the system prompt (CLAUDE.md, output style, append)
claude-code-model-configuration — which aliases resolve to the 1M-token-capable models
claude-code-best-practices — the workflow this context mechanism serves
Sources
- raw/external/code-claude-com-context-window-4fb02d1e.md