DEV Community

Will Gwyn
Will Gwyn

Posted on

Claude Code /compact vs /clear: what actually happens to your context

/compact replaces your conversation with a summary Claude writes and keeps the same session going. /clear starts a new conversation with an empty context. Your project memory, like CLAUDE.md, still loads, and the old conversation stays available through /resume.

That's the short version. The longer version matters, because the two commands look alike in the prompt bar and behave very differently, and I've watched people (me included) pick the wrong one mid-task and lose a decision that took an hour to reach.

What /compact does

Anthropic's command reference describes /compact [instructions] as freeing up context "by summarizing the conversation so far," with optional focus instructions. Run /compact focus on the API changes and the summary leans toward what you named. You can also compact part of a conversation from /rewind with "Summarize from here" or "Summarize up to here." The automatic pass Claude Code runs near the limit is the same operation. You just don't get to steer it.

After a compaction, the docs list what comes back on its own. The system prompt and output style still apply. Project-root CLAUDE.md, unscoped rules and auto memory get re-injected from disk. Up to five recently modified files Claude touched get re-read, and a file over 5,000 tokens comes back only as a path. Invoked skills return within a per-skill cap. The rest of the conversation, including path-scoped rules, nested CLAUDE.md files and context that hooks added, lives on only as whatever the summary kept.

There's a cost detail people miss. The costs page notes that /compact "reads the conversation it summarizes, so compacting a large context is itself a large request."

What /clear does

/clear (aliases /reset and /new) starts a new conversation with empty context. The commands overview says it "starts fresh on a new task while keeping project memory," so CLAUDE.md and auto memory load as usual in the new session. The same costs page says that when you want a fresh start instead of continuity, "/clear costs nothing."

The question I get most is whether /clear is permanent. Anthropic's sources don't quite agree here. The help center article on models and limits warns that /clear can't be undone. The command reference says you can return to the previous conversation with /resume, and that in the same Claude Code process the rewind menu shows a "previous session" entry. My reading: the old transcript is still there to go back to, but nothing from it carries into the new session unless you bring it. If something matters, write it down first.

How to tell which one happened

If you write hooks, the two commands are easy to tell apart. SessionStart fires with source set to compact after a compaction and clear after /clear, and PreCompact fires first with a manual or auto trigger. That's how tools that manage context, mine included, know which boundary they just crossed.

Which one should you use?

Anthropic's own session management guide on claude.com gives the trade-off better than I can. Compaction is "lossy, but you didn't have to write anything yourself." With /clear you write down what matters and start clean, which is more work, but "the resulting context is what you decided was relevant." Their rule of thumb is /compact when you're mid-task and the session is bloated, and /clear when you're starting something new.

That leaves a gap for long tasks where you want both: a clean window, plus the decisions from the last two hours. That's where most of the community tooling lives. Some people do it by hand: ask for a handoff note, /clear, paste it back. claude-auto-handoff automates that by having Haiku write the brief before running /clear. claude-mem works from the memory side, capturing what your agent did and injecting relevant context into later sessions, so a fresh window starts less empty. context-mode reduces how much tool output lands in your context in the first place, which means you hit either command less often.

Where aigent-OS fits (I built this)

I built aigent-OS, so take this as the author's description. It automates the clean-window path. At a context threshold (80% by default) it asks Claude to write a capsule, a checkpoint file with the work state and next step. It waits for one exact acknowledgement, sends a single /clear, confirms through SessionStart that a new session really started, and resumes from the capsule. If the acknowledgement never comes, it never clears. Memory is plain markdown in git, so you can diff what the agent remembers. It's MIT licensed, runs locally and needs Node 18+: https://github.com/wrg32786/aigent-os

The honest status: Managed Auto-Refresh is in the v1.1.0-rc.1 release candidate. The public evidence is 11 of 11 clean cycles on one machine. On rc.1 a long session can still stall at the clear step and need a manual /clear. The fixes are merged on master and ship in the next release, and two smaller acknowledgement edge cases (#90 and #91) are still open. I don't claim it's better than compaction. It trades a model-written summary for a checkpoint you can open and read.

FAQ

Does /clear delete my CLAUDE.md or project files?
No. It clears the conversation. Project memory loads again in the new session, and your files aren't touched.

Can I get back to a conversation after /clear?
According to the command reference, yes, through /resume or the rewind menu's previous-session entry in the same process.

Which is cheaper?
/clear. Compacting has to read the whole conversation to summarize it.

Does /compact keep my files in context?
It re-reads up to five recently modified files Claude worked on. Larger ones come back as a path reference only.

Top comments (0)