Claude Code

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

SourceWhen it enters contextRecommendation
System promptSession startupManaged by Claude Code; can change after upgrades
Environment informationSession startupWorking directory, platform, shell, Git state
~/.claude/CLAUDE.mdSession startupKeep personal long-term preferences concise
Project CLAUDE.mdSession startupShort, accurate team conventions, architecture, and commands
.claude/rulesWhen matching files are accessedUse paths: for on-demand loading
Skill descriptionsStartup or invocationKeep descriptions short; load bodies as needed
MCP toolsStartup or on-demand searchTool search can load names and relevant schemas as needed
File readsAfter Read/Grep/LSP/BashLarge files consume more space
Hook outputWhen a hook returns additionalContextReturn only information Claude needs
Subagent resultsWhen a subagent finishesMain 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.

ObservationAction
File reads dominateNarrow the task; locate before reading
Tool output dominatesShorten output, or save it and read selected parts
Memory/rules are largeSplit into path-scoped rules or skills
History is long/compact at a natural break; /clear for a new task
Too many MCP toolsUse supported tool search, split servers, or disable unused tools

/context all shows more detail when diagnosing a rapidly filling window.

#/clear, /compact, and /rewind

CommandActionCache effectUse
/clear [name]Clear the conversation; old session remains resumableNew session reloads project contextAn unrelated task
/compact [instructions]Replace history with a summarySummary can read old cache; next turn builds a shorter history cacheContinue a long task
/rewindReturn to an earlier checkpointUsually returns to a previously cached prefixUndo a wrong direction
/contextInspect usage onlyNo cache changeDecide 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

ContentResult
System prompt and toolsRetained
Project CLAUDE.md and auto memoryReloaded
Previously triggered path rulesDepend on the summary and subsequent file access
Important conclusions from invoked skillsDepend on summary quality
Full text of uninvoked skillsNot automatically retained
Intermediate subagent workNot part of main context; final results may be summarized
Actual filesystem changesRemain 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

1

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.

2

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.

3

Delegate exploration

Use subagents to isolate large research reads. The main session receives conclusions instead of every file's contents.

4

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:

ActionContext effectCache effect
Ordinary follow-upLonger historyExisting prefix usually reusable
Read a large fileNoticeable increaseAppended content; old prefix can hit
/compactShorter historyConversation layer becomes a summary
/clearClears current historyNew session creates new cache entries
Change model or effortContent may stay similarCache 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.