Claude Code /clear vs /compact: What Each Does and When to Use It
What /clear and /compact do in Claude Code, what each keeps and loses, how auto-compact works and how to turn it off, how big the context window is, and when to use which. Checked against the docs and tested on Claude Code 2.1.319.

The context window is everything Claude Code can see at once: your chat, the files it has read and the instructions it loads. /clear empties it and starts a new conversation, and /compact shrinks it into a summary and keeps the same conversation going. We checked every command and setting below against Anthropic's docs, then tested compaction and the main settings on Claude Code 2.1.319.
/clear vs /compact at a glance
/clear | /compact | |
|---|---|---|
| What it does | Starts a new conversation with an empty window | Replaces the chat so far with a summary and keeps going |
| What stays | Your project's CLAUDE.md and auto memory, loaded again from disk | The summary, your project's CLAUDE.md, auto memory, skills and up to five recent files |
| What goes | Every message and every file Claude read | Exact wording, tool output and early detail |
| Your old chat | Saved, back with /resume | Replaced by the summary |
| Cost | Nothing | One model call that reads the whole chat |
| Use it when | You switch to unrelated work | One long task still needs its history |
What /clear does
/clear starts a new conversation with an empty context. The old conversation is not deleted: it is saved and /resume brings it back. /reset and /new do the same thing. Pass a name and it labels the chat you are leaving, not the new one, so /clear oauth-migration saves the old session under that name.
Your project's CLAUDE.md and auto memory, the notes Claude keeps for itself, load again, because a new conversation starts like any new session. In our test a new session knew none of the ten facts from the old chat and still followed the CLAUDE.md rule.
Clear often, because every request sends the whole conversation. A chat with three unrelated tasks in it re-reads all three on every turn of the fourth, at a discount while the prompt cache, a temporary store that makes repeated text cheaper, is warm and full price after it expires. Anthropic's API docs add a quality reason: accuracy and recall degrade as the token count grows, which they call context rot. After two failed corrections, Anthropic's advice is to /clear and write one better prompt, not a third correction.
What /compact does
/compact summarizes the conversation so far and carries on in the same session. Claude still has the plan and the decisions, in the summary's words rather than yours. Run it bare and Claude decides what matters, or add a focus and the summary protects what you name: /compact keep the API changes and the test commands. For a standing focus, add a Compact instructions section to your project's CLAUDE.md.
Anthropic's own caveat: the summary keeps your requests and key code snippets, but detailed instructions from early in the conversation may be lost. Anything Claude must never forget belongs in CLAUDE.md, not in the chat.
The summary costs a model call that reads the whole conversation. It is cheap while the prompt cache is warm and full price once it expires, which is why a compact costs the most on an old session you resumed. The cache lasts about an hour on a subscription and five minutes on an API key. Compact at a natural break, such as between tasks, not mid-task.
What survives a /compact
The docs list what happens to each kind of content:
| What | After a compact |
|---|---|
| CLAUDE.md in the project root, unscoped rules, auto memory | Re-injected from disk |
| Skills | Descriptions rebuilt; invoked skill bodies re-injected, up to 5,000 tokens each and 25,000 in total |
| Files Claude read or edited | Up to five re-read, newest first; a file over 5,000 tokens comes back as a path only |
| Path-scoped rules (limited to certain files) and nested CLAUDE.md files | Summarized away, loaded again when Claude touches a matching file |
| Your messages, Claude's replies and tool output | Replaced by the summary |
The quiet row is the path-scoped one. If a rule must survive a compact, drop its paths: filter or move it into the project-root CLAUDE.md.
We tested what a compact keeps
We ran Claude Code from a script, with no chat window, on Sonnet 5.5, with tools and MCP (the connectors to other apps) switched off. Claude got two made-up project documents of about 6,600 words each, with six details buried in them: an invoice number, a tracking number, a photographer, a phone extension, a press embargo time and a barcode prefix. We then typed four decisions into the chat (a hex colour, a dropped font, a corner radius and a file name), about 25,000 tokens in all. We ran /compact, started a new session in the same folder to stand in for /clear, and asked each for all ten facts from memory.
Before, tokens of chat
After /clear, a new session
After /compact, a summary
| What we ran | Chat size after | Facts Claude knew, of 10 |
|---|---|---|
| Nothing | 25k tokens | 10, in both runs |
A new session, as after /clear | 0 | 0, and the CLAUDE.md rule still applied |
| The old session, resumed | 25k tokens | 10, in both runs |
/compact | 2.4k to 2.8k | 10 in 5 of 7 runs, 4 in the other 2 |
/compact with a focus on the details | 2.6k to 3.0k | 10 in 7 of 7 runs |
What the test showed
- It was fast and small. In this 25k-token chat a compact took 13 to 20 seconds and cut the chat by about 90 percent.
- A plain compact usually works and sometimes drops what you pasted. In the two misses it kept the four decisions we typed and lost all six document details.
- A focus that names the details protects them. Ours listed the kinds of detail we then asked about, and all ten facts survived in seven runs out of seven. It will not save a detail you forgot to name.
- The messy part. Both misses came from our first batch, where auto memory was on and the two summaries mentioned the memory system. With auto memory off, four of four plain compacts kept everything. We cannot say that was the cause, and it is a small test: one model, made-up documents, seven runs each.
Treat a plain /compact as probably fine and possibly lossy. When a detail matters, name it in the focus or put it in CLAUDE.md.
When auto-compact runs
Claude Code compacts for you as the window fills, with the same kind of summary as /compact. It is on by default, so a full window does not end your session. It starts at about 967K tokens on the 1M models and at the limit on a 200K window.
Two other things happen on their own:
- Idle compaction. After about an hour away, a conversation past 200,000 tokens on the one-hour cache is compacted before the cache expires, so your next message sends a summary. Turn it off with
idleCompactionset to false. - A thrashing stop. If one huge file or tool output refills the window after every summary, Claude Code gives up after a few tries and shows
Autocompact is thrashing. Read the file in pieces, run/compactwith a focus that drops the output, hand it to a subagent (a helper with its own window), or/clear.
How to change auto-compact or turn it off
The main switches the docs list, and which one wins:
/autocompact 500k(in a session, Claude Code 2.1.221 or later): saves a window for the current model and applies it now./autocompact autoresets it.--autocompact 500k(launch flag): changes the window for that launch only.autoCompactWindow(settings.json): one window for every model, 100000 to 1000000.CLAUDE_CODE_AUTO_COMPACT_WINDOW(environment): beats the three above. Made for scripts and cloud runs.autoCompactEnabled(settings.json or/config):falseturns auto-compact off. The default istrue.DISABLE_AUTO_COMPACT=1(environment): turns it off for one session and beats the setting.DISABLE_COMPACT=1(environment): turns off all compaction,/compactincluded.CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=50(environment): compacts at 50 percent of the window. It can lower the trigger but not raise it, and applies only to sessions that compact before the model's limit.
A window can be written as 200000, 200k or 1M. To turn auto-compact off, put this in ~/.claude/settings.json:
{ "autoCompactEnabled": false }
With it off, /compact still works, and a full window ends in Context limit reached · /compact or /clear to continue, with a note that auto-compact is off.
We checked most of these names against Claude Code 2.1.319 by reading /context. The flag, CLAUDE_CODE_AUTO_COMPACT_WINDOW, autoCompactWindow and CLAUDE_CODE_DISABLE_1M_CONTEXT=1 each changed the window it showed, and turning auto-compact off swapped the 33k Autocompact buffer for a 3k Compact buffer. The /autocompact command and CLAUDE_AUTOCOMPACT_PCT_OVERRIDE come from the docs only: we did not run the command, and the variable changed nothing /context shows.
How big is the context window?
Current Claude models have a 1M-token window. A token is a chunk of text a little over half a word on the current tokenizer, so that is roughly 555,000 words. In Claude Code, which window you get depends on the model:
| Model | Window in Claude Code | Auto-compact starts |
|---|---|---|
| Opus 4.7 and later, including Opus 5.5 | 1M tokens | About 967K |
| Sonnet 5 and later, including Sonnet 5.5 | 1M tokens | About 967K |
| Haiku 5.5, Fable 5 and Fable 5.1 | 1M tokens | About 967K |
| Opus 4.6 and Sonnet 4.6 | 200K, or 1M with the [1m] variant on plans that allow it | At the limit |
Set CLAUDE_CODE_DISABLE_1M_CONTEXT=1 to hold every model to 200K.
See what fills the window with /context
Run /context to see what is using the window: a colored grid with hints for heavy tools, memory bloat and capacity warnings. This is a fresh session on Opus 5.5, as claude -p "/context" printed it on Claude Code 2.1.319:
| Category | Tokens | Share of 1M |
|---|---|---|
| System prompt | 1.8k | 0.2% |
| System tools | 6.6k | 0.7% |
| Skills | 2.3k | 0.2% |
| Messages | 10 | 0.0% |
| Free space | 956.3k | 95.6% |
| Autocompact buffer | 33k | 3.3% |
A fresh session already holds about 10.7k tokens, nearly all of it Claude Code's own prompt, tools and skills. /context reserves a 33k Autocompact buffer on every window we read, and on a 1M window, 1M minus 33k is the 967K where the docs say auto-compact starts. With auto-compact off, that row shrinks to a 3k Compact buffer.
MCP tool definitions are deferred by default and load only when Claude uses a tool, so a long list of servers costs little up front. In two runs on our own machine, /context listed 259.6k and then 544.1k tokens of MCP tools as deferred, while MCP counted under 5k at the start: tool names and server instructions.
A slow session is not always a full window: a high effort level thinks longer. /usage shows cost and plan use, and /export saves the chat as plain text before you clear.
Which command for which moment
| Situation | Run | Why |
|---|---|---|
| You finished a task and start an unrelated one | /clear | Old chat crowds out what you need next and costs tokens on every message |
| You corrected Claude twice and it is still wrong | /clear, then one better prompt | A third correction piles onto two failed attempts |
| A long task still needs its history | /compact with a focus | The summary keeps what you name |
| You took a wrong turn | /rewind | Rolls the chat, the code or both back to an earlier prompt |
| A long debugging stretch swamped the chat | /rewind, then Summarize from here | Compresses everything after the message you pick and keeps your early instructions |
| You want an old chat back | /resume | Brings back any saved chat, including one you just cleared |
| You retype the same rule every session | Your project's CLAUDE.md, edited with /memory | Both commands leave it alone |
| A big read would flood the chat | A subagent | It reads in its own window and only the summary comes back |
Default to /clear between tasks. Reach for /compact when continuity inside one task is the point, and give it a focus. If you want the fundamentals first, here is what a context window actually is.
FAQ
What does /clear do in Claude Code?
It starts a new conversation with an empty context window. The old conversation is saved, so /resume brings it back, and CLAUDE.md and auto memory load again. /reset and /new do the same thing.
What is /compact for in Claude Code?
It frees up context by replacing the conversation so far with a summary, so you keep working in the same session. Add instructions, such as /compact keep the API changes, to steer what the summary protects.
Should I use /clear or /compact?
Use /clear when you switch to unrelated work or a correction has failed twice. Use /compact, with a focus, when one long task still needs its history.
Can I undo /clear in Claude Code?
Yes. Run /resume and pick the old conversation, which stays saved for 30 days by default. In the same Claude Code window, the /rewind menu also lists the previous session at the top.
How do I turn off auto-compact in Claude Code (autoCompactEnabled)?
Set autoCompactEnabled to false in settings.json, switch off Auto-compact in /config, or set DISABLE_AUTO_COMPACT=1 for one session. The environment variable wins over the setting, and /compact still works either way.
How do I change when Claude Code auto-compacts?
Run /autocompact 500k to set the window for the current model, or use --autocompact, autoCompactWindow or CLAUDE_CODE_AUTO_COMPACT_WINDOW. Any value from 100K to 1M tokens works, up to the model's own window, and /autocompact auto resets it.
How big is the context window in Claude Code?
1M tokens on Opus 4.7 and later, Sonnet 5 and later, Haiku 5.5 and Fable 5 and later. Opus 4.6 and Sonnet 4.6 run 200K unless you pick the [1m] variant.
What does "Context limit reached" mean in Claude Code?
The conversation plus attached files no longer fits the model's window. Run /compact for a summary or /clear to start fresh. If the line says auto-compact is off, /config turns it back on.
Sources
- Claude Code docs, Commands: every command and alias above.
- Claude Code docs, Explore the context window: what survives compaction, what runs when context fills up.
- Claude Code docs, Model configuration: window sizes, the auto-compact window, default thresholds.
- Claude Code docs, Settings and Environment variables:
autoCompactEnabled,autoCompactWindow,idleCompactionand the variables above. - Claude Code docs, Checkpointing and Sessions: the rewind menu, how
/clearnames and saves a session. - Claude Code docs, Best practices, Reduce token usage and Prompt caching: when to clear, what a compact costs, Compact instructions.
- Claude Code docs, Error reference and Troubleshooting: the
Context limit reachedline and the thrashing stop. - Claude API docs, Context windows and Models overview: window sizes by model, context rot.
- Our runs: Claude Code 2.1.319, headless with
claude -p, Sonnet 5.5 for the compaction test and Opus 5.5 for the/contextreadings, run on 6 November 2026. Fourteen compaction runs, four controls, and/contextread under each setting named above.





