Skip to main content

Context Management

Intermediate
What you'll learn
  • 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.

Press Enter or Space to flip the card. Use the left and right arrow keys to move between cards.Term shown.
1 / 2

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.

Pro tip
  • 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.

Guided walkthrough1 of 4
  1. Don't let an afternoon of unrelated work pile into one context.

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. :::

Key takeaways
  • /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/4
  1. You finish a task and switch to something completely unrelated. Which command?
  2. You're mid-task and the context window is getting full, but you want to keep going on the same work. Which command?
  3. What is the right way to think about auto-compaction?
  4. Claude starts forgetting an earlier instruction or repeating itself. What's the likely cause and fix?

Next