Get featured

Claude Code /compact vs /clear: which one to use

Guide · checked against the docs on

Long Claude Code sessions fill up. Old messages, file reads and command output all take space. Claude Code gives you two commands to deal with that: /compact and /clear. They sound alike, but they do different jobs. Everything below comes from Anthropic's Claude Code docs, read on October 16, 2026. We haven't tested these commands ourselves.

Not affiliated with or endorsed by Anthropic. Commands change, so check the docs and your version with claude --version.

What fills the context window

Claude only sees what's in its context window. Anthropic's commands reference says: "When the conversation gets long, /context shows what's filling the window and /compact summarizes it to free space." (checked Oct 2026)

Run /context to look before you act. The same page says it will "Visualize current context usage as a colored grid. Shows optimization suggestions for context-heavy tools, memory bloat, and capacity warnings." (checked Oct 2026)

What /compact does

/compact keeps your conversation going, but shorter. The commands reference says: "Free up context by summarizing the conversation so far. Optionally pass focus instructions for the summary." (checked Oct 2026)

The context window page adds that it "replaces the conversation with a structured summary. Most startup content reloads automatically" (checked Oct 2026)

Tell it what to keep

You can add a focus after the command. Anthropic's How Claude Code works page says: "To control what's preserved during compaction, add a "Compact Instructions" section to CLAUDE.md or run /compact with a focus (like /compact focus on the API changes)." (checked Oct 2026)

The costs page shows this CLAUDE.md example (checked Oct 2026):

# Compact instructions

When you are using compact, please focus on test output and code changes

The two pages write the heading a little differently ("Compact Instructions" and "Compact instructions"). The docs don't say whether the capital letters matter.

What survives a compact

Your CLAUDE.md file comes back. The context window page lists "Project-root CLAUDE.md and unscoped rules | Re-injected from disk" and "Auto memory | Re-injected from disk". For files, it says Claude Code "re-reads up to five, most recently modified first". (checked Oct 2026)

Some things don't stay as they were. The same table says "Context that hooks added earlier | Summarized with the rest of the conversation". And for rules tied to certain folders: "If a rule must persist across compaction, drop the paths: frontmatter or move it to the project-root CLAUDE.md." (checked Oct 2026)

If you were using a skill, the skills page says: "invoke the skill again to restore its full content. After compaction, Claude Code can keep only the start of an invoked skill" (checked Oct 2026)

It isn't free

The costs page warns: "/compact reads the conversation it summarizes, so compacting a large context is itself a large request." (checked Oct 2026)

What /clear does

/clear starts over. The commands reference says: "Start a new conversation with empty context. Pass a name to label the previous conversation in the /resume picker. To free up context while continuing the same conversation, use /compact instead." (checked Oct 2026) Its other names are "/reset, /new".

"Empty context" doesn't mean your project setup is gone. The same page says "/clear starts fresh on a new task while keeping project memory." (checked Oct 2026) Our advice, not a vendor quote: this is because CLAUDE.md is loaded again when the new conversation starts, so put rules you always want there.

Your old chat isn't lost either: "Resume the previous conversation with /resume, or, in the same Claude Code process, restore it from the rewind menu's previous-session entry." (checked Oct 2026)

The costs page gives a tip: "Use /rename before clearing so you can find the session later, then /resume to return to it." It also says: "When you want a fresh start instead of continuity, /clear costs nothing" (checked Oct 2026)

Auto-compact: when Claude Code does it for you

You don't have to compact by hand. The How Claude Code works page says: "Claude Code manages context automatically as you approach the limit. It clears older tool outputs first, then summarizes the conversation if needed. Your requests and key code snippets are preserved; detailed instructions from early in the conversation may be lost. Put persistent rules in CLAUDE.md rather than relying on conversation history." (checked Oct 2026)

What Anthropic's docs we read don't say: the exact point (a percentage or token count) where auto-compact starts. They point to a separate thresholds section. We don't give a number here.

You can change it with /autocompact. The commands reference says it sets "how full the context window gets before Claude Code compacts automatically. Pass a size such as 500k, or auto to return to the window tuned for your model." It "Requires Claude Code v2.1.221 or later" (checked Oct 2026), so run claude --version first.

If one huge file or output keeps filling the window, the same How it works page says Claude Code "stops auto-compacting after a few attempts and shows an error instead of looping." (checked Oct 2026)

Signs your context is filling up

The costs page describes "A context or auto-compact warning: not a usage limit. The conversation has grown close to the session's auto-compact window, the threshold where Claude Code summarizes older history to free space." (checked Oct 2026)

What Anthropic's docs we read don't say: the exact words of that warning. So we can't show you what it looks like. Run /context to check for yourself.

Our advice, not a vendor quote: another sign is Claude forgetting a rule you gave early in the chat. That matches the docs' note that early instructions "may be lost", so move those rules into CLAUDE.md.

Which one should I use?

Our advice, not a vendor quote: a simple rule.

Anthropic backs the second one. The context window page says: "Clear between tasks: run /clear when switching to unrelated work. Old conversation crowds out the files you need next and costs tokens on every message." (checked Oct 2026)

Our advice, not a vendor quote: commit your work with git before a big compact or clear. It costs nothing and gives you a safe point.

We haven't tested these commands hands-on. This guide collects what Anthropic's docs say.

Not affiliated with or endorsed by Anthropic. Commands change, so check the docs and your version with claude --version.