Context Management
- Tell /clear and /compact apart and pick the right one instantly
- Understand auto-compaction and why proactive clearing still beats it
- Apply four techniques to keep long sessions sharp
- Recognize the symptoms of a full context window and fix them fast
The big idea
Every session has a finite context window. As it fills, older content gets squeezed and Claude can start to "drift." Managing context deliberately is what keeps long sessions sharp.
The two essential commands
Two commands cover almost every situation. The trick is matching the command to your intent.
Decide with one question: is this a new task or the same one?
Auto-compaction
When context approaches the limit, Claude Code can auto-compact so work continues without a hard stop. It's a safety net — but proactively /clear-ing between tasks gives better results than relying on it.
- Treat auto-compaction as a backstop, not a strategy. Clearing between unrelated tasks keeps context cleaner than letting the window fill until auto-compaction kicks in.
Techniques to stay effective
Beyond the two commands, four habits keep your context lean from the start.
- Don't let an afternoon of unrelated work pile into one context.
- Hand large reads to subagents — they burn THEIR context and return only the conclusion. See /docs/claude-code/subagents.
- Point Claude at files with @path instead of pasting large blobs, and keep CLAUDE.md lean (see /docs/claude-code/claude-md).
- A statusline showing context use tells you when to compact. See /docs/claude-code/statusline.
These map to live docs: subagents, CLAUDE.md, and statusline.
:::tip Symptom → fix
If Claude starts forgetting an earlier instruction or repeating itself, the window is likely full. /compact (same task) or /clear (new task) usually fixes it instantly. More in Why Did Claude Do That?.
If you instead hit Autocompact is thrashing, compaction is working and something oversized keeps refilling the window — see Troubleshooting Claude Code.
:::
- /clear wipes the conversation for a fresh start — use it for unrelated tasks
- /compact summarizes the session to free space — use it to continue the same task when the window fills
- Auto-compaction is a safety net; proactive /clear between tasks gives better results
- Keep context lean: one task per session, delegate heavy reading to subagents, reference files instead of pasting, and watch the budget via a statusline
- Forgetting or repetition means a full window — /compact (same task) or /clear (new task) fixes it
Check yourself
0/4Next
- Checkpoints & Rewind —
/rewindto undo edits or compress context from any point - Tokens, Context & Memory
- Subagents & Parallel Agents
- Statusline Customization