Context window
How system prompts, CLAUDE.md, rules, file reads, tool output, hooks, and subagents use context, and when to use /clear, /compact, and /context.
Claude Code sends the required context to the model on each turn. The context window includes more than chat history: system prompts, project rules, file contents, tool output, hook feedback, subagent results, and your latest message.
#Where context comes from
| Source | When it enters context | Recommendation |
|---|---|---|
| System prompt | Session startup | Managed by Claude Code; can change after upgrades |
| Environment information | Session startup | Working directory, platform, shell, Git state |
~/.claude/CLAUDE.md | Session startup | Keep personal long-term preferences concise |
Project CLAUDE.md | Session startup | Short, accurate team conventions, architecture, and commands |
.claude/rules | When matching files are accessed | Use paths: for on-demand loading |
| Skill descriptions | Startup or invocation | Keep descriptions short; load bodies as needed |
| MCP tools | Startup or on-demand search | Tool search can load names and relevant schemas as needed |
| File reads | After Read/Grep/LSP/Bash | Large files consume more space |
| Hook output | When a hook returns additionalContext | Return only information Claude needs |
| Subagent results | When a subagent finishes | Main session receives the final summary; intermediate reads stay separate |
The most common waste is not a long prompt, but unrelated files, lengthy logs, and large tables read during one task.
#What /context shows
/context visualizes usage and identifies heavy sections.
| Observation | Action |
|---|---|
| File reads dominate | Narrow the task; locate before reading |
| Tool output dominates | Shorten output, or save it and read selected parts |
| Memory/rules are large | Split into path-scoped rules or skills |
| History is long | /compact at a natural break; /clear for a new task |
| Too many MCP tools | Use supported tool search, split servers, or disable unused tools |
/context all shows more detail when diagnosing a rapidly filling window.
#/clear, /compact, and /rewind
| Command | Action | Cache effect | Use |
|---|---|---|---|
/clear [name] | Clear the conversation; old session remains resumable | New session reloads project context | An unrelated task |
/compact [instructions] | Replace history with a summary | Summary can read old cache; next turn builds a shorter history cache | Continue a long task |
/rewind | Return to an earlier checkpoint | Usually returns to a previously cached prefix | Undo a wrong direction |
/context | Inspect usage only | No cache change | Decide whether to reorganize context |
/compact is not a universal cost-saving button: it adds a summarization request. Use it at natural breaks, not constantly. To undo a wrong direction, see Checkpointing.
#What survives compaction
| Content | Result |
|---|---|
| System prompt and tools | Retained |
| Project CLAUDE.md and auto memory | Reloaded |
| Previously triggered path rules | Depend on the summary and subsequent file access |
| Important conclusions from invoked skills | Depend on summary quality |
| Full text of uninvoked skills | Not automatically retained |
| Intermediate subagent work | Not part of main context; final results may be summarized |
| Actual filesystem changes | Remain on disk independently of context |
If information must be available later, write it to a file, issue, or plan, or explicitly ask /compact to retain it.
#Practical context control
Keep permanent rules short
Put stable conventions in CLAUDE.md, not long API references, logs, or TODO lists. Keep long material in skills or project documentation and read it when needed.
Locate before reading
Use rg, the file tree, or symbol search to narrow the scope before reading key files. Avoid reading all of src first in a large repository.
Delegate exploration
Use subagents to isolate large research reads. The main session receives conclusions instead of every file's contents.
Save long output first
Write lengthy test logs or analysis reports to a file, then summarize or search the relevant sections.
#Relationship to caching
Context capacity and prompt caching are different but related:
| Action | Context effect | Cache effect |
|---|---|---|
| Ordinary follow-up | Longer history | Existing prefix usually reusable |
| Read a large file | Noticeable increase | Appended content; old prefix can hit |
/compact | Shorter history | Conversation layer becomes a summary |
/clear | Clears current history | New session creates new cache entries |
| Change model or effort | Content may stay similar | Cache identity can change and invalidate reuse |
See Prompt caching for TTL and hit checks, and Subagents for context boundaries.
Large repositories also need careful startup directories, layered instructions, Read deny rules, and sparse worktrees. See Large codebases and monorepos.
#Official references
Support
Need help?
For setup, billing, or model issues, email us. Check the status page for uptime.
WeChat / QQ support is available at the bottom right.

