ai for designersJune 25, 20269 min read

Claude Code Context Management: /clear vs /compact and the Rest

How to manage Claude Code's context window. The real difference between /clear and /compact, plus /context, /rewind, auto-compaction, and the memory files that outlive every reset.

By Boone
XLinkedIn
claude code context management

Two commands do the real work. /clear starts a fresh conversation with an empty window. /compact squeezes the current conversation into a summary and keeps going. Every other context command in Claude Code is either looking at what fills the window or recovering when it goes wrong.

That is the whole map. The skill is knowing which one you need before the indicator turns red.

If you want the fundamentals first, here is what a context window actually is. This piece is the operator's version: which command, when, and what it costs you.

A retro voxel terminal glows with stacked orange blocks, a visual stand-in for a context window pushing its limits.
A retro voxel terminal glows with stacked orange blocks, a visual stand-in for a context window pushing its limits.

What actually fills your context window

It is not just your chat. Claude Code packs the window with file reads, your project CLAUDE.md, memory entries, invoked skill bodies, MCP tool definitions, hook output, and the conversation itself.

Run /context (or /context all) to see it. It draws a colored grid of token usage by category, plus optimization hints and capacity warnings.

Here is why that matters. If your MCP servers and skill definitions are eating half the window before you type a word, compacting the conversation will barely help. You have to know what is heavy before you decide how to cut it.

Voxel diagram showing multiple input types stacking to fill a context window.
Voxel diagram showing multiple input types stacking to fill a context window.

/clear vs /compact, the only fork that matters

/clear forgets. /compact remembers a summary.

/clear starts a brand-new conversation with an empty context window. Your previous chat is not destroyed. It stays reachable through /resume.

Pass a name with /clear <name> to label the fresh session. Your project CLAUDE.md and memory reload from disk into the new session.

/compact keeps you in the same session. It summarizes everything so far into a condensed baseline and continues from there. According to the official Claude Code documentation, that is the split: clear for a new task, compact to free tokens inside the current one.

The default should be /clear. It is faster and cleaner than dragging accumulated noise from one task into the next. The Claude Code team agrees loudly. "STOP COMPACTING, use /clear," wrote @trq212 of the Claude Code team, who framed the gap between how the team works and how the community works as mostly a matter of how often each one clears.

Medium author Mubashar lands on the same rule: "default to clear, reach for compact when continuity matters."

Clear forgets. Compact remembers a summary. Knowing which one you need is the whole skill.

Putting AI to work in a design practice? Brainy helps designers do it without losing the craft. See what we are building for creators.

How to steer a compact

/compact takes free-text instructions. Use them.

Plain /compact lets Claude decide what matters. /compact focus on the auth bug or /compact keep the database schema tells it what to protect. A guided summary is far more reliable than a generic one.

This matters because compaction is lossy by design. A blind compact can drop detail you needed, which is why a handoff often beats a cleanup: dump what you need to a markdown file, run /clear, then point the new session at that file.

For most same-task work, a focused /compact is enough. For a critical handoff where you cannot afford to lose detail, write it down first.

Voxel split showing /clear starting empty versus /compact preserving a summary.
Voxel split showing /clear starting empty versus /compact preserving a summary.

What survives a compact, and what quietly disappears

Some things get re-injected after the summary. Others vanish until you trigger them again.

WhatAfter a /compact
System prompt and output styleRe-injected (they never lived in message history)
Project-root CLAUDE.md and unscoped rulesRe-injected
Auto-memory entriesRe-injected
Invoked skill bodiesRe-injected
Path-scoped rules (rules with a paths filter)Dropped until a matching file is read again
Nested CLAUDE.md in subdirectoriesDropped until a matching file is read again
Verbatim conversation, exact tool outputs, precise wordingLost, crushed into the summary

The dangerous rows are the quiet ones. Path-scoped rules and nested CLAUDE.md files drop out of the window after a compact and only return when you read a matching file again. If your project leans on scoped rules, a compact can change Claude's behavior without telling you.

Auto-compaction, the safety net you can turn off

When the conversation nears the context limit, Claude Code compacts on its own. Same behavior as a manual /compact.

You can disable it, though most people should not. It is on by default. To turn it off, run /config and toggle Auto-compact off, set autoCompactEnabled to false in settings.json, or set the DISABLE_AUTO_COMPACT environment variable. Leaving it on is the safer default, a backstop rather than a nuisance.

Whether you keep it on or off, the better instinct is to compact early rather than at the edge. An analysis at hyperdev.matsuoka.com reports that compacting proactively around 60% capacity, instead of waiting until 95%, plus better context editing, delivered up to 39% better performance against baseline.

The lesson is simple. Do not ride the window to the wall. A clean /clear or an early /compact beats a panicked auto-compact mid-thought.

Stacked red cubes topped by a glowing wireframe cage, the tension between accumulating context and the window ceiling made tangible.
Stacked red cubes topped by a glowing wireframe cage, the tension between accumulating context and the window ceiling made tangible.

See and save: /context, /cost, and /export

Three commands to inspect and preserve before you cut.

/context shows the token grid by category. Run it whenever Claude feels slow. Slowness is usually a full window, not a dumb model.

/cost (alias /usage) shows session cost and plan-usage stats. On Pro, Max, Team, and Enterprise plans it breaks usage down by skill, subagent, plugin, and MCP server. The dollar figure is a local estimate, not your actual bill, and for Max and Pro subscribers usage is included in the subscription anyway.

/export [filename] writes the transcript to plain text, either to a named file or through a save dialog. Run it before a /clear when you want a record.

/rewind and /resume, recover without starting over

When you took a wrong turn, you do not have to start over.

/rewind (aliases /checkpoint, /undo) rolls back to an earlier checkpoint. It can restore conversation state, code state, or both, or summarize from a message you pick. There is a keyboard shortcut for it. Run /keybindings to see the current binding rather than guessing.

/resume (alias /continue) brings a past conversation back, by picker, session ID, or name. This is the safety net under /clear. Clearing never deletes, so a wrong clear is one /resume away.

Voxel checkpoint stack showing conversation rollback to an earlier session state.
Voxel checkpoint stack showing conversation rollback to an earlier session state.

Memory files outlive both clear and compact

CLAUDE.md is the durable layer. It survives everything.

Your project CLAUDE.md and memory files reload after a /clear and get re-injected after a /compact. Anything you re-explain every session belongs there, not in the chat. /memory opens those files for editing and lets you enable, disable, or view auto-memory entries.

According to the Claude Code docs, this is why CLAUDE.md is the right home for invariants. Rules like "always run the tests" or "never touch the schema" persist across resets and shape future summaries. Push facts down into it and you stop paying the re-explanation tax every session.

When the window is still too tight

Cutting the conversation is not your only lever. Three moves handle the rest.

Subagents are the big one. Hand a self-contained job to a subagent that runs in its own fresh context and returns only the result. The main thread stays lean while the heavy work happens elsewhere. For a large task, nothing else frees up as much room.

Path-scoped CLAUDE.md and nested memory keep rules near the files they govern, so they load only when relevant instead of sitting in the window all session.

A bigger window helps but does not excuse sloppiness. Claude's newest models, the Opus 4.x and Sonnet 4.x family and Fable 5, support up to a 1M-token context window. A full window is still slower and more expensive to read, so management still matters. That is the same reason it pays to use a context window efficiently no matter how big it gets.

The decision rule, in one table

One table. Copy it.

SituationCommand
Finished a task, starting an unrelated one/clear
Need to keep going on the same long task, space is tight/compact
Want the summary to keep a specific thing/compact <instructions>
Things feel slow, not sure what is eating the window/context
Took a wrong turn, want to undo code or conversation/rewind
Need a previous conversation back/resume
Want a record before clearing/export
Same fact re-explained every sessionPut it in CLAUDE.md via /memory
Big self-contained job bloating the threadDelegate to a subagent

Default to /clear. Reach for /compact only when continuity inside one task is the point. Run /context when things drag, because if MCP servers and skills are the problem, no amount of compacting the chat will fix it.

FAQ

Should I use /clear or /compact more often?

/clear, by a wide margin. The Claude Code team's stated habit, echoed across r/ClaudeCode and a LinkedIn note from jdfiscus, is to clear on task completion and keep /compact for staying inside one long task. Long-running chats that lean on repeated compaction lose detail every pass.

Does /clear delete my conversation?

No. /clear starts a fresh window but leaves the previous conversation intact and reachable through /resume. Nothing is destroyed.

Can I turn off auto-compaction?

Yes. It is on by default, but you can turn it off in /config (toggle Auto-compact), by setting autoCompactEnabled to false in settings.json, or with the DISABLE_AUTO_COMPACT environment variable. Most people should leave it on and just clear or compact deliberately before hitting the limit.

What does /compact actually lose?

Verbatim detail. Exact tool outputs, long file dumps, and precise earlier wording get crushed into a summary. A blind compact can lose detail you needed, which is why a guided /compact <instructions> or a markdown handoff beats the default.

How do I see what is filling my context?

Run /context (or /context all). It shows a colored grid of token usage by category: file reads, CLAUDE.md, memory, skills, MCP definitions, hook output, and the conversation, with optimization hints.

Where should I put rules so they survive resets?

CLAUDE.md, edited via /memory. Project CLAUDE.md and memory reload after /clear and re-inject after /compact, so they are the only context guaranteed to persist.

Stop letting your context rot

The window fills whether you manage it or not. The only question is whether you cut it on purpose or let an auto-compact do it for you mid-thought.

Default to /clear between tasks. Use /compact with instructions inside one. Run /context when it drags, push durable facts into CLAUDE.md, and lean on subagents for the heavy jobs. That is the entire discipline.

If you are wiring AI into a design practice, the same instinct applies everywhere: keep the machine focused and keep the craft yours. That is the bet behind Claude Code for designers, and there is more on AI for designers if you want the rest.

Brainy helps designers put AI to work without losing the craft. See what we are building for creators.

Brainy helps designers put AI to work without losing the craft. See what we are building for creators.

Get Started

Not ready to hire? Run the free Business Genome, an 11-dimension diagnostic for your venture.

Get your free Genome

Get new papers by email

New Brainy papers in your inbox. Confirm once, unsubscribe anytime.

More from Brainy Papers

Keep reading