All field notes

Context · 6 min read ·

Claude Code /compact vs /clear: manage context

Claude Code /compact vs /clear: what each does to your context window, what survives compaction, how auto-compact works, and when to use which.

What is the difference between /compact and /clear?

In Claude Code, /clear starts a new conversation with empty context. /compact keeps the conversation going but replaces its history with a summary. Use /clear when you switch to unrelated work, and /compact when you are still on the same task and the context window is filling up. That matches Anthropic’s command reference, which sends you to /compact to “free up context while continuing the same conversation.”

Both exist because the context window is everything Claude knows about your session: your instructions, the files it reads, its own responses and content that never appears in your terminal, per Anthropic’s context window page. Claude Code sends your whole conversation with every request, so a bloated window costs usage on each message, not once, according to the cost docs.

What does /compact do, and what survives it?

/compact summarizes the conversation so far and replaces the history with the summary. Add focus instructions to steer it, such as /compact focus on the auth bug fix. Without them the summary keeps what Claude Code guesses is important, according to the context window page.

Not everything is summarized. As of October 2026, Anthropic’s table of what survives compaction says the system prompt still applies, and the project-root CLAUDE.md, unscoped rules and auto memory are re-injected from disk. Claude Code re-reads up to five files Claude read or edited, most recently modified first, and a file over 5,000 tokens comes back as a path reference only. Invoked skills come back capped at 5,000 tokens each and 25,000 in total. Background commands and subagents keep running.

What gets lost is mostly what you only said in conversation. Anthropic says detailed instructions from early in the conversation may be lost and that persistent rules belong in CLAUDE.md, per how Claude Code works. Path-scoped rules and nested CLAUDE.md files are summarized away until Claude touches a matching file again, so a rule that must always hold goes in the project-root file. Our guide to AGENTS.md vs CLAUDE.md vs GEMINI.md covers what to put there.

To shape the summary, add a “Compact instructions” section to CLAUDE.md. Anthropic’s cost docs show “When you are using compact, please focus on test output and code changes.” Its best practices suggest “When compacting, always preserve the full list of modified files and any test commands.” For context you want back after every compaction, a SessionStart hook with the matcher compact can print it again, as the hooks guide shows.

What does /clear do, and when should you use it?

/clear discards the conversation and starts again with empty context, and it costs nothing, per the cost docs. Name the session first if you may want it back: /rename, then /clear, and /resume later. In the same Claude Code process you can also restore it from the rewind menu’s previous-session entry, per the checkpointing docs.

A new conversation re-reads your project-root and user-level CLAUDE.md files, so an edit you made mid-session applies after /clear (or /compact), per the prompt caching docs. The session cost totals in /usage reset too. Anthropic says old conversation crowds out the files you need next and costs tokens on every message, which makes /clear the right default between tasks.

Use it when a session has gone wrong, too. Anthropic’s best practices say that if you have corrected Claude more than twice on the same issue, the context is cluttered with failed approaches, and a fresh session with a more specific prompt almost always beats the long one.

How big is the context window, and when does auto-compact run?

It depends on the model. Anthropic’s model docs say the Fable models, Sonnet 5 and later, Haiku 5.5 and Opus 4.7 and later run with a 1 million token window by default. Sessions on those models auto-compact at about 967K tokens unless you set a smaller window, per the default thresholds.

Claude Code compacts on its own as you near the limit, so a full window does not end the session. It clears older tool outputs first, then summarizes the conversation if needed, per how Claude Code works. To compact earlier, run /autocompact with a size, such as /autocompact 500k; it accepts 100K to 1M, per set the auto-compact window. A bigger window is not a free pass, though: the whole conversation is sent with each request.

You can turn auto-compact off in /config, and /compact still works by hand, per the settings reference. A full window then ends in “Context limit reached · /compact or /clear to continue,” the message on Anthropic’s errors page.

Two behaviors surprise people. Claude Code also compacts a long conversation you leave idle, shortly before its prompt cache expires. Under the conditions the idleCompaction setting lists, such as an interactive session on the one-hour cache, context past 200,000 tokens and about 54 minutes idle, that is on by default. And if one file or tool output refills the window after every summary, Claude Code stops after a few attempts with an “Autocompact is thrashing” error instead of looping. Read the file in chunks, compact with a focus that drops it, or hand it to a subagent, per troubleshooting.

What does compacting cost?

Compacting is a request too. Anthropic’s cost docs say /compact reads the conversation it summarizes, so compacting a large context is itself a large request. The prompt caching docs explain the range: while the cache is warm, a mid-session /compact costs a fraction of what the context size suggests. After a break longer than the cache lifetime, the summary request reprocesses the whole history, and that is when /compact costs the most. The main conversation’s cache lasts an hour within your plan’s included usage and five minutes once you draw on pay-as-you-go usage, per which TTL each request gets.

So compact at natural breaks, between tasks, rather than waiting for auto-compact to fire mid-task, the same docs advise. If you went down a path you want to abandon, /rewind to an earlier turn instead: it truncates back to a prefix that is already cached.

How do you compact part of a session, or avoid compacting?

Summarize part of it. Run /rewind (or press Esc twice on an empty prompt), pick a message, and choose Summarize from here or Summarize up to here. The first condenses everything after that point. The second condenses everything before it and keeps later messages in full. You can type guidance before you press Enter, and files on disk are untouched. See rewind and summarize.

Delegate large reads. A subagent works in its own context window, so file contents stay out of yours and only a summary returns. See Claude Code subagents.

Ask side questions with /btw. It sees your context but has no tools, and the answer is not added to history, per the subagent docs.

Watch the window. /context shows a live breakdown by category with optimization suggestions, and a custom status line can show context_window.used_percentage all the time.

Load less at the start. CLAUDE.md, auto memory, MCP tool names and skill descriptions all load before you type, per the context window page, and Anthropic’s memory docs suggest keeping each CLAUDE.md under 200 lines. For the cost side, see controlling AI coding costs and what to do when Claude Code hits its limit.

Put numbers on it

/compact and /clear are Claude Code commands, and SwarmPane runs Claude Code in a real terminal pane, so you use them as you always do. What SwarmPane adds is measurement. Usage shows one row per CLI from its own reports, with estimates labelled as estimates. Token Guardian counts only usage your CLIs report, stops runs at a daily budget before they overspend, and stops a run that loops on one failure, with the evidence.

SwarmPane runs the agent CLIs and accounts you already have, so Anthropic bills its plan separately. Start with a 7-day trial for $1 and cancel before it ends if it is not for you.