Learn Claude Code: Cost & Context Mastery /clear vs /compact — Knowing When to Reset vs Summarize

/clear vs /compact — Knowing When to Reset vs Summarize

Intermediate 🕐 11 min Lesson 5 of 11
What you'll learn
  • Apply the decision heuristic: when to use /clear vs /compact based on session state and what you need to preserve
  • Write effective custom compaction instructions that tell Claude what to prioritize in the summary
  • Explain what CLAUDE.md content does and does not survive auto-compaction, and why

The Two Resets

When your context grows large or performance degrades, you have two options. Choosing the wrong one wastes tokens or throws away information you needed. The right choice depends on what you actually need to carry forward.

/clear: The Clean Start

Running /clear starts a new session with an empty context. Claude Code saves the previous conversation — you can return to it with /resume. The session cost counter resets to zero. The cache resets with the context, so your first turn in the new session re-caches from scratch.

Use /clear when:

  • You are switching to an unrelated task
  • Claude has gotten confused and corrections are not sticking
  • The session is old and the accumulated context is no longer relevant to what you need
  • You want a fresh perspective on a problem without prior assumptions

The key insight: /clear costs nothing. It is free to start fresh. The only thing you lose is accumulated context — and if that context is working against you, losing it is the point.

/compact: Summarize and Continue

Running /compact replaces earlier conversation history with a summary while preserving recent exchanges and critical context. Use it when the accumulated file reads and intermediate work are genuinely valuable and you want to continue in the same thread.

The command accepts custom instructions that tell the summarizer what to prioritize:

/compact Focus on the API changes we agreed on and the test failures

Without instructions, the summarizer makes its own choices about what to preserve. With instructions, you direct its attention to what matters most for your next steps.

You can also set project-level compaction instructions in your CLAUDE.md:

# Compact instructions
When compacting, preserve all code samples, API signatures, and test output.
Focus on what changed, not what was considered and rejected.

What Survives Compaction

After compaction, the conversation history is replaced with a summary plus:

  • Your most recent exchanges (preserved verbatim)
  • Up to five recently read files (restored to context)
  • CLAUDE.md files (re-injected automatically on every compaction)
  • Skills you actually invoked (preserved in the summary)

What does not survive:

  • The skill listing (one-line descriptions are not re-injected after compaction)
  • Instructions you gave only in conversation, not in CLAUDE.md
  • Detailed intermediate steps and exploration that was not captured in a decision

This is why the rule exists: put anything you need Claude to remember throughout the session in CLAUDE.md, not in messages. A message-only instruction will not survive the first compaction.

Auto-Compaction

When the context approaches the session's auto-compact window, Claude Code triggers compaction automatically. You do not need to do anything — but you should be aware it happened and that the cache was invalidated. The /usage prompt cache stats line will show an expected rebuild.

The Decision Heuristic

Use /clear when

You are switching tasks, the context is working against you, or you want a genuinely fresh start. It is free and reversible — you can always /resume the old session.

Use /compact when

You are deep in a complex problem and the accumulated context is genuinely valuable. Include custom instructions to direct what is preserved.

When in doubt, prefer /clear. The cost of starting fresh is near zero. The cost of carrying a confused context forward is harder to quantify and often much higher.

Key takeaways
  • /clear is free — it costs nothing in tokens and the old session is saved for /resume; when in doubt about whether to clear, clear.
  • /compact with custom instructions is more effective than /compact alone — tell the summarizer what to focus on before it runs, not after.
  • CLAUDE.md is re-injected automatically after every compaction; conversation-only instructions are not — this is the most important structural rule for session continuity.
  • Auto-compaction triggers near the context limit and is visible as an expected rebuild in /usage cache stats; add compaction hints to CLAUDE.md so the summarizer knows what matters even without your guidance.
  • The skill listing (one-line descriptions) is not re-injected after compaction — only skills you actually invoked are preserved in the summary.