chat-recall

/clear vs /compact in Claude Code

Both commands free up context and the menu gives you one line each, so people pick by feel. They do different things to different files, and the difference decides whether tomorrow you can still find what you did.

The short answer

/compactSummarizes the conversation so far and continues in the same session. The assistant still knows roughly what you have been doing. Reach for it mid-task.
/clearStarts fresh. Nothing carries over, which is the point when you have finished one thing and are starting another. Claude Code's own tip is to use it when switching topics.

Same task, keep going: compact. Different task: clear. That covers most days, and two cases below break it.

What each one does to the file on disk

This is the part neither help string mentions, and it is the part that matters a week later. Both commands are recorded, and neither deletes anything.

/compact stays in the same file. It appends a boundary record and carries on appending after it:

same session, same .jsonl
{"type":"system","subtype":"compact_boundary",
 "content":"Conversation compacted",
 "compactMetadata":{"trigger":"manual","preTokens":205229}}

In a session I checked, that boundary sat at line 1588 of a 2257-line file: 1587 records before it, all still there, all still in order. The record immediately after it is a user message flagged isCompactSummary, which is the summary the model reads from then on. Everything the summary dropped is sitting a thousand lines above it.

/clear opens a new file. The old session's .jsonl is closed and left exactly as it is, and a new one starts with a new session id. In the new file, the first thing recorded is the clear itself:

line 4 of a brand new .jsonl
<command-name>/clear</command-name>

So neither command loses your history in the sense people worry about. What you lose is reach: after a compact the model holds a summary, and after a clear it holds nothing at all.

Which one to reach for

Long refactor, context filling up/compact. You want the thread. Give it instructions while you are there so it keeps the right half.
Finished the bug, starting a feature/clear. A summary of the bug is dead weight on the feature, and it costs you window on every turn that follows.
The session has gone wrong/clear. Compaction would carry the confusion forward in condensed form. This is the case where the rule of thumb gets it wrong.
You are about to hit the limit/compact, now, with instructions. Auto-compact fires on its own shortly after and picks for you.

Turning them off

One environment variable covers both, and it is worth knowing which. DISABLE_AUTO_COMPACT stops the automatic one and leaves you the manual command. DISABLE_COMPACT disables manual /compact as well, so a session that fills up has nowhere to go.

Getting back what /clear left behind

The previous transcript is a complete file on your disk, and the one thing that cannot read it is the assistant that wrote it. An index over those files closes that:

in the session after the clear
> what did we settle on for the pooler yesterday?
  recall_search reads the earlier transcript and quotes
  the exchange, including the two options that were dropped

It works the same across a compact boundary, which is the harder case: the file holds both halves, so the reasoning the summary discarded is still retrievable even though the model can no longer see it.

Claude Code keeps transcripts for 30 days by default, set by cleanupPeriodDays. After that the file is gone and no search helps.

Start free, no card What a compact costs you

Questions

What is the difference between /clear and /compact in Claude Code?/compact summarizes the conversation so far and continues in the same session, so the assistant keeps a condensed version of what you have been doing. /clear starts a fresh conversation with nothing carried over. Use compact to keep going on the same task, and clear when you are switching to a different one.
Does /clear delete my conversation history?No. It closes the current transcript file and opens a new one with a new session id. The previous .jsonl stays on disk untouched, under ~/.claude/projects/. What is cleared is the model's view, not the record.
Does /compact lose information?From the model's context, yes: it keeps the conclusions and drops most of the reasoning that produced them. From the file, no. The transcript gets a compact_boundary record and keeps growing in the same file, so every message before the boundary is still there in order.
Should I use /clear or /compact when switching tasks?/clear. A summary of finished work is dead weight on the next task and costs you window on every turn. Claude Code's own tip says to use /clear when switching topics.
Can I recover a conversation after running /clear?The file is intact, so the content is recoverable by anything that can read it, but Claude Code itself will not reopen it as the current session. --resume can reopen it in the same directory, and an index over the transcripts lets the assistant search it mid-task instead. Transcripts are deleted after cleanupPeriodDays, 30 by default.
Can I disable /compact?DISABLE_AUTO_COMPACT turns off automatic compaction and leaves the manual command working. DISABLE_COMPACT disables manual /compact too, which means a session that fills its context window has no way to continue.

More notes

Compacting conversation: what Claude Code keeps and dropsWhat auto-compact does to a long session, why the assistant starts contradicting itself afterwards, and how to get the lost detail back instead of retyping it.
Context left until auto-compact: what the number countsThe percentage in the status line, what makes it fall, how to move the threshold, and what actually happens to your conversation when it reaches zero.
Compact instructions: tell /compact what to keepCompaction decides what survives unless you decide for it. Passing instructions to /compact, and the PreCompact hook that supplies them every time.