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.
/compact vs /clear at a glance
| /compact | /clear | |
|---|---|---|
| Conversation history | Replaced by a summary | Removed |
| CLAUDE.md and project files | Kept | Kept |
| Good for | Long tasks you are in the middle of | Switching tasks, dead ends |
| Risk | Summary drops details you needed | You lose anything not written down |
| Prompt cache | Next request writes the summary fresh | Next 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.
- default
- with condense
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
- 1Name 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 - 2Add 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.
- 3Compact 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
- 1Start with a brief
Goal, the constraint that matters most, and how you will know it is done.
- 2Watch the meter
Check context left or run
/contextat each milestone. - 3Compact at milestones
When tests pass,
/compactwith what the next step needs. - 4Clear at task boundaries
Handoff note, commit,
/clear, start from the note. - 5Promote 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 lives | After /compact | After /clear |
|---|---|---|
| Chat history | Summarized | Gone |
| CLAUDE.md | Kept | Kept |
| Notes or handoff file | Kept | Kept |
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.
| When | What it rewrites | Your transcript | |
|---|---|---|---|
| Built-in /compact | When you run it or the window fills | The whole conversation, into one summary | Replaced |
| condense | Continuously, on the way to the model | Finished agent loops; never the system prompt, your messages or final answers | Unchanged; /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.