Blog

Claude Code /compact vs /clear: when to use each, and why auto-compact forgets things

Use /compact mid-task when Claude needs the thread: it swaps the conversation for a summary and carries on. Use /clear when you switch tasks or the session went stale: it starts fresh with only CLAUDE.md and your files. Auto-compact forgets because it summarizes on its own schedule, so steer it with instructions and keep durable decisions in CLAUDE.md.

94.2%
of facts kept by Adeline 1
90.2%
token reduction
95.0%
kept by Claude Opus 4.7 at 87.6%

/compact vs /clear at a glance

/compact/clear
Conversation historyReplaced by a summaryRemoved
CLAUDE.md and project filesKeptKept
Good forLong tasks you are in the middle ofSwitching tasks, dead ends
RiskSummary drops details you neededYou lose anything not written down
Prompt cacheNext request writes the summary freshNext request starts from the base prefix

Both free the window. If it is nearly full, see Claude Code context window full for what is taking the space.

What Claude Code /compact does

/compact replaces the history with a model-written summary; the system prompt, tools and CLAUDE.md are untouched. Auto-compact is the same thing, fired for you when the window is nearly full.

Context carried per turn
Illustrative session
auto-compactturn 1turn 40
  • default
  • with condense
Auto-compact resets context when the window fills, on window size rather than task boundaries.

Why Claude Code forgets things after auto-compact

After a compaction Claude retries a ruled-out fix, drops a constraint or loses the error it was chasing. Four reasons:

  • It fires at the worst moment, often mid-debugging, where details matter most.
  • It has no instructions unless you gave standing guidance.
  • Negative knowledge is easy to drop. “We tried X and it broke Y” reads like history, yet it is what stops the agent looping.
  • Losses compound. A second compaction summarizes a summary.

How to write /compact instructions that keep what matters

  1. 1
    Name what a summary usually drops

    /compact keep: files changed so far, the failing test names and their exact errors, approaches we rejected and why, and the decision to keep the v1 API

  2. 2
    Add standing guidance to CLAUDE.md

    A few lines on what any compaction must keep, such as the test command, modified files and open questions. It applies to auto-compact too.

  3. 3
    Compact at a natural break

    After a test passes or a subtask lands. The summary is better when the state is clean.

When /clear beats /compact

  • You are switching tasks. A summary of the last task is noise for the next.
  • The session hit a dead end. A summary keeps the wrong theory. See context rot.
  • You already compacted twice. It is mostly summary of summary by now.

Hand off instead: have Claude write done, broken, ruled out and next step to HANDOFF.md, check it, /clear, then “read HANDOFF.md and continue.”

A simple routine for long Claude Code sessions

  1. 1
    Start with a brief

    Goal, the constraint that matters most, and how you will know it is done.

  2. 2
    Watch the meter

    Check context left or run /context at each milestone.

  3. 3
    Compact at milestones

    When tests pass, /compact with what the next step needs.

  4. 4
    Clear at task boundaries

    Handoff note, commit, /clear, start from the note.

  5. 5
    Promote lessons

    A correction you repeat after every compaction is a rule. Add one line to CLAUDE.md.

Put durable decisions in CLAUDE.md, not chat

Rules like “never touch the generated client” belong in CLAUDE.md. Keep it lean, since every line is sent on every request; see CLAUDE.md and MCP overhead.

Where it livesAfter /compactAfter /clear
Chat historySummarizedGone
CLAUDE.mdKeptKept
Notes or handoff fileKeptKept

A different approach to compaction

condense, our proxy, compacts continuously on the way to the model. Adeline 1 rewrites finished agent loops into short packs that keep intents, file paths, identifiers, errors and code; the recent working set stays verbatim.

Facts kept after compaction
Agent coding traces
Claude Opus 4.7
95.0%
Adeline 1
94.2%
Adeline 1 kept 94.2% of facts at a 90.2% reduction, within a point of Claude Opus 4.7 at 87.6%. From Adeline 1.
WhenWhat it rewritesYour transcript
Built-in /compactWhen you run it or the window fillsThe whole conversation, into one summaryReplaced
condenseContinuously, on the way to the modelFinished agent loops; never the system prompt, your messages or final answersUnchanged; /compact and /clear still work

Run dense claude to try it.

Frequently asked questions

Why does Claude Code forget things after compacting?

A summary has to leave things out, and one-off details, rejected approaches and exact errors go first. Tell /compact what to keep, or write it to a file.

Can I tell /compact what to keep?

Yes. Text after the command is used as instructions, for example /compact keep the list of changed files and the failing test names. Standing guidance can go in CLAUDE.md.

Does /clear delete my CLAUDE.md or code changes?

No. It only resets the conversation; files, git state and CLAUDE.md are untouched, and CLAUDE.md loads again.

Is it better to compact early or wait for auto-compact?

Compact early, at a natural break, with instructions. Auto-compact fires when the window is nearly full, often mid-task.

How often should I use /clear in Claude Code?

At least once per task. Old context costs tokens every turn and gives the model more to get confused by.

All posts