What is the difference between /clear and /compact in Claude Code?
Both commands free up room in the context window, but they do opposite things with your conversation. /clear throws the whole conversation away and gives you a blank slate - the agent no longer remembers a single thing you said in that session. /compact keeps the conversation alive by replacing it with a short summary of what happened, so the agent still knows what you were working on but takes up far less room doing it.
Put simply: /clear is a reset, /compact is a save-and-shrink. You reach for /clear when you are done with one thing and moving to something unrelated. You reach for /compact when you are in the middle of a task, the window is filling up, and you want to keep the thread without losing your place.
What /clear actually does
/clear empties the conversation history for the current session. After you run it, the agent behaves as if you just opened the project - it has no memory of the questions you asked, the files it read, or the decisions you made a moment ago. What it does NOT wipe is your project setup: your CLAUDE.md file, your settings, and any files you point it at are all still there to be reloaded when the next task needs them.
This is why a reset costs less than most beginners assume. You are not deleting your project or your instructions. You are clearing the short-term chatter of one task so the next task starts clean, with a full window and no leftover context nudging the agent in the wrong direction.
What /compact actually does
/compact asks the agent to write a concise summary of the conversation so far, then replaces the full back-and-forth with that summary. The result is a much smaller footprint that still carries the important thread: what you are building, what has been tried, and where you left off. You keep working in the same session, on the same task, with room to spare.
The tradeoff is fidelity. A summary is not the full transcript, so fine detail can get flattened - an exact variable name, a subtle edge case you discussed once, a specific line the agent quoted earlier. For most work the summary keeps enough to continue smoothly. For work where a precise detail matters, restate that detail in your next prompt right after compacting so it survives the shrink.
The rule I use to decide, every session
I do not overthink it. The decision comes down to one question: am I still on the same task, or have I moved to a new one?
- New, unrelated task = /clear. I finished the login page and now I am writing a cold email. Nothing from the login work helps the email, and leftover context only risks confusing the agent. Blank slate.
- Same task, window filling up = /compact. I am halfway through a feature, the agent has read a dozen files, and the window is getting tight. I want to keep going without losing the thread, so I summarize and continue.
- Same task, plenty of room left = do nothing. Compacting early throws away detail you did not need to lose. Only compact when you are actually running low.
I call this the CCC context reset habit: clear between tasks by default, compact only mid-task under pressure. It keeps every session starting sharp and stops the slow drift that happens when one long conversation tries to hold three unrelated jobs at once.
Why a bloated conversation hurts output
As a conversation grows, two things get worse. First, you run out of room - a full window forces the agent to drop older context on its own, often the exact context you wanted kept. Second, and more subtle, a long thread full of half-finished tangents makes the agent slower and less focused, because it is weighing every past message when it decides what to do next. Managing context deliberately is a core part of keeping long sessions on track - see [Claude Code context management: how to keep long sessions on track](/blog/claude-code-context-management).
Which command fits the moment
| Situation | Use | Why |
|---|---|---|
| Switching to an unrelated task | /clear | Leftover context only confuses the new task; start fresh |
| Mid-task, window filling up | /compact | Keep the thread, drop the bulk, keep going |
| Mid-task, plenty of room | Neither | Compacting early loses detail you still have room to keep |
| Agent keeps citing outdated info | /clear | Stale conversation is the cause; a reset removes it |
Make context resets a habit before your next build
Start every new task with a clean window and you will notice the agent stays sharper for longer. Clear between unrelated jobs, compact when a single task outgrows its window, and restate any critical detail right after you compact. It is a thirty-second habit that removes a whole category of confusing, off-target output.
Short, practical drops on skills, MCP, agents, prompts, and more. No spam, unsubscribe anytime.
Frequently asked questions
What is the difference between /clear and /compact in Claude Code?
/clear wipes the conversation to a blank slate - the agent forgets everything you discussed in that session. /compact summarizes the conversation and keeps going, so the agent remembers the gist while using far less of the context window. Use /clear between unrelated tasks and /compact mid-task when the window is filling up.
Does /clear delete my project or my CLAUDE.md file?
No. /clear only empties the current conversation history. Your project files, settings, and CLAUDE.md are untouched and reload when your next task needs them. That is why a reset is cheaper than it feels - you are clearing one task's chatter, not your setup.
When should I use /compact instead of /clear?
Use /compact when you are still on the same task and want to keep the thread but the context window is running low. It summarizes what has happened so far and lets you continue with room to spare. If you were switching to an unrelated task instead, /clear is the better choice.
Does /compact lose information?
Some. A summary is not the full transcript, so fine detail can get flattened - an exact variable name or a subtle edge case discussed once. For most work the summary keeps enough to continue. If a precise detail matters, restate it in your next prompt right after compacting so it survives.
Last reviewed by David Iya on September 14, 2026


