Claude Code /clear vs. /compact: When to Use Each
Claude Code /clear vs. /compact: When to Use Each
Most advice about Claude Code's context window boils down to one line: use /compact when it's full and /clear when you switch tasks. That rule is fine as far as it goes, but it hides two things that changed the trade-off. Context windows are now large enough that "full" rarely arrives before quality slips, and /clear is no longer the irreversible wipe most guides still describe.
This guide gives you a decision you can make in five seconds, explains what each command actually keeps, and covers the two lesser-known tools (/rewind and /autocompact) that handle the cases /clear and /compact handle badly.
Key Takeaways
- Run
/clearwhen the next task is unrelated to the current one. Run/compactwhen you're mid-task and the thread still matters. Run/compactwith a focus instruction when you know what must survive.- Quality can degrade well before the window is full. Chroma's research on "context rot" found that model performance varies with input length even on simple tasks, so waiting for a full window is the wrong trigger.
/clearis recoverable. On Claude Code v2.1.191 and later,/rewindoffers a/resumeentry for the session you just cleared.- Put anything that must never be lost in
CLAUDE.md. It is re-injected from disk after compaction; instructions you only typed into the chat are summarized and can be lost.
[INTERNAL-LINK: getting started with Claude Code → beginner guide to installing and using Claude Code]
The Five-Second Decision
Use /clear when you're switching to unrelated work, and /compact when you're continuing the same work. If you only remember one thing, remember that split.
The official Claude Code documentation says the same thing in different words. It advises running /clear "when switching to unrelated work" because old conversation crowds out the files you need next and costs tokens on every message (Claude Code docs: Explore the context window, retrieved 2026-09-21). Compaction is the tool for the opposite situation: you want the model to keep the thread of a long task while shedding the bulk.
| Your situation | Use | Why |
|---|---|---|
| Finished a bug fix, starting a different feature | /clear |
Nothing from the old task helps the new one |
| Halfway through a refactor, session feels sluggish | /compact |
You need the plan and decisions, not the file dumps |
| About to start a long task and know what matters | /compact <focus> |
You choose what the summary keeps |
| A side discussion went nowhere but early context is good | /rewind → Summarize from here |
Drops the detour, keeps the setup in full |
| Early setup is bloated but recent work is precious | /rewind → Summarize up to here |
Compresses the old, keeps the recent |
| Claude keeps repeating a wrong idea from earlier | /clear and restate |
A summary would preserve the bad idea |
[INTERNAL-LINK: reading Claude Code's built-in commands → cheat sheet of Claude Code slash commands]
Why Context Fills Up Faster Than You Think
Before you can choose between the commands, it helps to see what is in the window, because most of it is not your conversation. Claude Code's documentation shows that a lot loads before you type anything: CLAUDE.md files, auto memory, MCP tool names, and skill descriptions are all in context before your first prompt.
After that, file reads dominate. The same page notes that file reads dominate context usage and recommends being specific in prompts so Claude reads fewer files. For research-heavy tasks it suggests delegating to a subagent, whose separate context window keeps the file contents out of yours and returns only a summary.
You can see your own numbers at any time. Run /context for a live breakdown by category with optimization suggestions, and /memory to open the CLAUDE.md and auto memory files that loaded. The visualization in the docs uses representative numbers, so treat your own /context output as the real measurement.
What /compact Does (and What Survives)
/compact replaces the conversation with a structured summary, then continues your session from that compressed state. According to the official docs, the summary keeps your requests and intent, key technical concepts, files examined or modified, errors and their fixes, pending tasks, and current work. It replaces the verbatim conversation, so full tool outputs and intermediate reasoning are gone.
Not everything is summarized. The docs include a table of what survives, and the practical version looks like this:
| Content | After compaction |
|---|---|
Project-root CLAUDE.md and unscoped rules |
Re-injected from disk |
| Auto memory | Re-injected from disk |
| The plan Claude wrote in plan mode | Re-injected from disk |
| Files Claude read or edited | Up to five re-read, most recently modified first |
| Skills you invoked | Re-injected, capped at 5,000 tokens each and 25,000 total |
Path-scoped rules and nested CLAUDE.md files |
Reloaded only when Claude reads a matching file again |
| Skill descriptions (the startup index) | Not re-injected |
| Hook output from earlier | Summarized with everything else |
Source: Claude Code docs, "What survives compaction", retrieved 2026-09-21. Behavior can change between versions, so confirm against the current page.
Two consequences are worth acting on:
- Anything critical belongs in
CLAUDE.md, not in chat. Instructions you gave only in conversation get summarized and can be dropped, whileCLAUDE.mdis re-read from disk every time. - Path-scoped rules can quietly disappear. The docs say a rule with
paths:frontmatter loads into message history when its trigger file is read, so compaction summarizes it away. If a rule must persist, drop thepaths:frontmatter or move it to the project-rootCLAUDE.md.
Steer the Summary Instead of Trusting It
The automatic pass decides for itself what matters. When you run /compact yourself, you can tell it. The docs give this example:
/compact focus on the auth bug fix
Doing this before a long new task means the summary keeps what you choose rather than what the automatic pass guesses is important. It is the most useful habit in this article, because most "Claude forgot what we were doing" complaints come from compaction that had no guidance.
What /clear Does (and Why It's Less Scary Now)
/clear wipes the conversation and starts a fresh session. Your CLAUDE.md still loads at the start of the new session, but everything from the conversation is gone, including decisions you'd agreed on and the state of the current task. The next message is effectively the first message of a new session.
Older guides call this destructive and stop there. That is no longer the full picture. Per the official checkpointing docs, if you ran /clear earlier in the same Claude Code process, the /rewind menu shows an extra entry at the top labeled /resume <session-id> (previous session), which returns you to the conversation that was active before the clear. The entry stays available until you exit Claude Code or resume a different session, and it requires v2.1.191 or later. On earlier versions, the docs say to run /resume and pick the previous session from the list (Claude Code docs: Checkpointing, retrieved 2026-09-21).
That changes how aggressively you can clear. You are not betting your context on a clean break, because there is a way back. Two caveats keep this honest:
- Rewinding does not undo everything. The same docs note that checkpoints track edits made through Claude's file-editing tools, and changes made by shell commands like
rm,mv, orcpare not captured. Checkpoints are not a replacement for version control. - Recoverable is not the same as useful. Returning to the old session also returns you to its bloated context. Clear because you want a clean slate, and treat the recovery path as insurance.
The Third Option: /rewind and "Summarize"
Sometimes neither command fits, because you want to compact part of the conversation rather than all of it. That is what /rewind is for. Run /rewind, or press Esc twice with an empty prompt, to open the menu.
The docs describe two summarize options that leave your files untouched:
- Summarize from here keeps the messages before the selected point in full and replaces the selected message and everything after it with a summary. Use it to discard a side discussion while keeping early context in detail.
- Summarize up to here replaces the messages before the selected point with a summary and keeps everything after it intact. Use it to compress early setup while keeping recent work in full.
In both cases the original messages are preserved in the session transcript, so Claude can reference the details if needed. This is the right tool when a long debugging detour has bloated the middle of a session but the beginning and end are both valuable.
You can steer these summaries too. The checkpointing docs say to highlight a Summarize option with the arrow keys and type instructions where the row reads "add context (optional)", then press Enter. Selecting the option by its number key summarizes immediately without instructions. If you would rather try a different approach while keeping the original session intact, the same page points to /branch (or claude --continue --fork-session) instead, since Summarize keeps you in the same session.
Compact Before You're Forced To
Waiting for the window to fill is the wrong trigger. There are two reasons, one about quality and one about mechanics.
The quality reason: context rot
Chroma's 2025 research on "context rot" evaluated 18 large language models and found that performance varies with input length even on simple tasks, contradicting the assumption that a model handles the 10,000th token as reliably as the 100th (Chroma Research, Context Rot, Hong, Troynikov and Huber, 2025). The degradation was non-uniform: it depended on how similar the target information was to the question, whether distractors were present, and how the input was structured.
Read that carefully before you quote it. Chroma's own report says the evaluation is not exhaustive of real-world use cases, and the models it tested predate the ones you are using today. The defensible claim is that the mechanism is documented and that a longer, noisier context gives the model more to sort through. The claim you cannot make is that quality drops at a specific token count, because no source here supports one.
For a coding session, noise accumulates in predictable ways: exploratory file reads you no longer need, failed attempts, verbose command output. Clearing or compacting removes that noise, which is why it helps even when the window has plenty of room.
The mechanical reason: automatic compaction is a guess
Claude Code compacts automatically as you approach the limit, so a full window doesn't end your session. But the automatic pass chooses what to keep without your input. The thresholds also depend on your setup:
- On models with a native 1M window, such as Sonnet 5 and the Fable models, Claude Code compacts at about 967K tokens by default.
- Some configurations budget the window at 200K instead, including LLM gateways, where Claude Code can't verify 1M support, and sessions with
CLAUDE_CODE_DISABLE_1M_CONTEXT=1set.
(Both from Claude Code docs: Model configuration, retrieved 2026-09-21.)
That first number is the real reason to act early. If your window is 1M tokens and automatic compaction waits until about 967K, a session can carry a huge amount of stale context for a very long time before anything is summarized.
Move the threshold yourself
You can set how full the window gets before the automatic pass runs. Per the model-configuration docs, /autocompact takes a window size from 100K to 1M tokens:
/autocompact 500k
That saves to your user settings and applies immediately, and /autocompact auto returns to the window tuned for your model. For one launch only, pass --autocompact at startup. Be aware that CLAUDE_CODE_AUTO_COMPACT_WINDOW, when set, takes precedence over the command, the flag, and the setting, so an old environment variable in a shell profile can silently override what you typed.
A Workflow That Holds Up
Put it together as habits rather than rules:
- One task, one context. When you finish a task and commit, run
/clearbefore the next one. This is the default move and costs nothing. - Compact at breakpoints, with a focus. After finishing a feature or fixing a bug, and before starting something long in the same area, run
/compactwith an instruction naming what to keep. - Delegate reads. For research-heavy work, ask Claude to use a subagent so the file contents stay out of your main window.
- Fix the setup, not just the symptom. Keep
CLAUDE.mdshort and move reference material to skills or path-scoped rules so it only loads when needed. The docs suggest keepingCLAUDE.mdunder 200 lines. - Use
/contextwhen in doubt. Check where the tokens actually went before deciding.
Frequently Asked Questions
Does /compact cost tokens?
Yes. Compaction is a summarization request, so it uses tokens to produce the summary. The saving comes afterward, because every later message carries a smaller context. The docs also note that, as of v2.1.198, the summarization request inherits your session's extended thinking configuration. If you want the cheapest possible reset between unrelated tasks, /clear involves no summarization at all.
Can I get back a conversation I cleared?
Usually, yes. On v2.1.191 or later, /rewind shows a /resume <session-id> (previous session) entry at the top after a clear, available until you exit Claude Code or resume a different session. On earlier versions, use /resume and pick the earlier session from the list. Files changed by shell commands are not restored by rewinding.
Why did Claude forget a rule I gave it earlier?
Most likely the rule lived only in the conversation, or in a path-scoped rule file, and compaction summarized it away. Move must-keep instructions into the project-root CLAUDE.md, which is re-injected from disk after every compaction.
Should I turn off auto-compact?
The docs don't describe a switch to disable it entirely, so this guide doesn't recommend a workaround. Community requests for one exist on the Claude Code issue tracker, which is a signal that behavior here may change. Instead, take control the supported way: compact manually at breakpoints with a focus instruction, and set your own threshold with /autocompact.
Is a bigger context window a reason to compact less?
It is a reason not to compact in a panic, but not a reason to stop managing context. A larger window raises the ceiling without removing the accumulation of stale reads and dead ends. Compaction works the same way at the larger limit, according to the docs.
Where to Go Next
Try this on your next session: finish a task, commit, and run /clear instead of continuing in the same window. Then, the next time you're mid-task and things feel slow, run /compact with a one-line focus and compare how the session behaves. Once you've felt the difference, tune /autocompact to a window that suits how you work.
Recap:
/clearfor unrelated work,/compactfor continuing work,/compact <focus>when you know what matters./rewindwith Summarize compresses part of a session, and it also recovers a cleared one on recent versions.- Put critical rules in the project-root
CLAUDE.md, because it survives compaction and chat-only instructions may not. - Compact early, since automatic compaction may not run until the window is nearly full.