Why /compact and /clear Exist: Managing the Context Window
A Claude Code session's context window is not infinite.
Search across all documentation pages
A Claude Code session's context window is not infinite.
Every prompt, file read, tool output, and response adds up, and a long enough conversation eventually fills that space.
/compact and /clear exist to manage that budget deliberately instead of letting a session either grind to a halt or drag stale history into work that no longer needs it.
/compact condenses a conversation's history to free space while keeping what's still relevant, while /clear discards the conversation entirely and starts fresh./compact when a task is still in progress and the conversation has gotten long. /clear when switching to something unrelated to what came before./compact is a summary, not a perfect copy - fine detail can get smoothed over. /clear loses everything from the old conversation, including detail you might still have wanted.Think of a Claude Code session's context window as a workbench with a fixed amount of surface area.
Every file you open, every command's output, and every message you send takes up some of that space.
Early in a session there's plenty of room, so nothing feels constrained.
As the conversation runs longer, though, the bench fills up with things from earlier in the task, some of which are still useful and some of which are not.
/compact and /clear are the two tools for managing that surface area once it starts to feel crowded.
/compact is like tidying the workbench: it summarizes what's there, keeps the parts that still matter, and clears away the rest, so you can keep working on the same project.
/clear is like clearing the whole bench for a new project: everything from before is gone, and you start with an empty surface.
Neither tool touches CLAUDE.md, because CLAUDE.md is not part of the conversation's history - it is project memory that gets reloaded fresh at the start of every session regardless of what happens to that session's context.
The core distinction between the two commands is what happens to the conversation's prior content.
/compact produces a condensed summary of the conversation so far, and that summary - not the full original exchange - becomes the new starting point going forward.
This keeps the gist of what happened (decisions made, files touched, the state of the task) while shrinking the amount of context space it occupies.
/clear does not summarize anything. It removes the conversation history outright, and the next message starts a genuinely new session, with CLAUDE.md still loading exactly as it would for any new session.
The decision between them comes down to one question: is there still a task in progress that needs the accumulated context, or is what's next unrelated to what came before?
# still working on the same task, context is getting full:
/compact
# switching to a completely different, unrelated task:
/clearA few mechanical details worth internalizing:
/compact is a summarization step, which means some specificity is inevitably lost - a very precise earlier detail can get smoothed into a more general statement./clear is closer to closing one conversation and opening a brand new one - nothing carries forward except whatever CLAUDE.md and the files on disk still represent.The deeper reason these commands matter is that context bloat is rarely one dramatic event - it's usually gradual accumulation.
Large files read in full, a string of @mentions across a long session, and verbose tool output (a big test run, a long build log) all add up quietly, and by the time a session feels sluggish, a fair amount of that budget is often occupied by things that stopped being relevant several turns ago.
Recognizing why a session has gotten heavy is what makes the choice between /compact and /clear an informed one rather than a reflex.
If the bloat is incidental noise around a task that's still active - verbose output from commands you no longer need to see, exploratory searches that didn't pan out - /compact is usually the right call, since the task itself is still live and benefits from the condensed history.
If the bloat is really a sign that the current task has finished, or that you're pivoting to something the old conversation has nothing to do with, /clear is the more honest move, since dragging irrelevant history forward, even summarized, adds noise rather than value.
| Approach | Strength | Weakness | Best Fit |
|---|---|---|---|
/compact | Preserves the gist of an in-progress task while freeing space | Summarization can lose fine-grained detail | Long sessions on a task that isn't finished yet |
/clear | Fully resets the context, nothing stale carries over | Loses everything from the prior conversation, even useful detail | Starting a genuinely new, unrelated task |
| Doing neither | No effort required | Context keeps filling until the window is exhausted or responses degrade | Short sessions that never approach the limit |
In practice, a habit worth building is treating /clear as the default between unrelated tasks - much like closing a browser tab you're done with - and reaching for /compact specifically when you want to keep momentum on something still in flight but the conversation has simply gotten long in the process.
/compact preserves a condensed version of history for an ongoing task; /clear removes history entirely for a fresh start./clear or /compact./compact proactively, once a session feels long, tends to produce a better summary than waiting until things are already crowded./compact condenses the conversation into a summary and keeps working from that. /clear removes the conversation history entirely and starts over.
No. CLAUDE.md is reloaded automatically at the start of every session regardless of whether you've run /clear - it isn't part of the conversation history these commands manage.
When the task you're working on is still in progress and you want to keep going, but the conversation has grown long enough that you want to free up space without losing the thread.
When you're switching to a task that's unrelated to what came before, so dragging even a summarized version of the old conversation forward would just add noise.
It can. Summarization keeps the gist and drops or generalizes fine-grained detail, which is the trade-off for reclaiming context space.
Large files read in full, a string of @mentions over a long session, and verbose tool output (long logs, big test runs) are common contributors, alongside the conversation itself.
Yes. /compact is meant for exactly that - you keep the same session going, now with a condensed history instead of the full prior conversation.
Yes, but you're effectively starting a new session. Nothing from the prior conversation carries forward, so anything still relevant needs to be restated or re-referenced.
The main cost is losing useful context you might have wanted to keep - if you clear mid-task, you'll need to re-explain things Claude Code already understood a moment ago.
Repeated compaction on an already-summarized history can compound the loss of fine detail over several rounds, since each pass condenses what's already a condensed version.
There's no single universal signal, but a session that's been running a long time, has read several large files, or has accumulated many tool outputs is a reasonable cue to consider /compact or /clear before things get crowded.
/clear generally fits better - a new feature is usually unrelated enough to the prior conversation that a clean start is more useful than a condensed summary of unrelated work.
Stack versions: Written against the Claude model lineup current as of ~June 2026 - Claude Fable 5, Claude Opus 4.8, Claude Sonnet 5 (the default), and Claude Haiku 4.5. Model names, pricing, and product features move quickly - verify current specifics at platform.claude.com/docs before relying on them.
Reviewed by Chris St. John·Last updated Jul 16, 2026