Claude Code /compact vs /clear, and what each one costs
/clear starts over with an empty context and costs nothing. /compact keeps a summary of the conversation instead, and writing that summary is itself a request over everything the session has accumulated.
/clear starts a new conversation with an empty context. /compact keeps the current conversation but replaces its history with a summary. The rule follows from that: /clear when the next task is unrelated to what came before, /compact when you are partway through one task and the history still matters.
Both exist because a Claude Code session gets more expensive and less reliable as its conversation grows. They are opposite answers to that problem, and they do not cost the same.
What each command does to the context
/clear ends the conversation and opens a new one with an empty history. Project memory lives outside that history, so it survives: CLAUDE.md and auto memory load again at the start of the new conversation.
Nothing is deleted either. The old conversation is saved, /resume brings it back, and passing a name, as in /clear release-prep, labels it for the resume picker. /reset and /new are aliases.
/clearA new conversation with an empty context; the old one stays available through /resume.
/compact replaces the message history with a structured summary and carries on in the same session. According to the Claude Code documentation, the summary keeps your requests, key technical concepts, the files examined or changed with their important snippets, errors and how they were fixed, and pending work. The verbatim record goes: full tool outputs and intermediate reasoning. Instructions you gave only in conversation may go with it.
Some things are rebuilt rather than summarised: the project-root CLAUDE.md and auto memory are re-read from disk, up to five of the files Claude read or edited come back, most recently modified first, and invoked skills are re-injected up to a size cap. Path-scoped rules and CLAUDE.md files in subdirectories are summarised away until Claude next reads a file they apply to.
/compact focus on the auth bug fixFocus instructions tell the summary what to keep instead of leaving it to guess.
To make a focus permanent, add a # Compact instructions section to the project CLAUDE.md, for example asking it to always preserve the list of modified files and the test commands.
Why a long session costs more on every turn
The model remembers nothing between requests. Each time you send a message, Claude Code makes a new API request and re-sends the full context: the system prompt, your project context, every earlier message and tool result, then your new message. Each time Claude uses a tool, another request goes out carrying the whole conversation again. A one-line question late in a long session is a one-line question plus everything before it.
Prompt caching softens this without removing it. The unchanged part of each request is read from a cache and billed at a fraction of the normal input price (a tenth or less on current Claude models, as of September 2026). A fraction of a large number, paid on every request, still grows with the conversation, and on a subscription it still draws on your usage limits.
The cache also expires. As of September 2026, the documentation puts its lifetime at an hour on a subscription and five minutes by default on an API key, and the first request after a longer break reprocesses the whole history from scratch.
Cost is not the only thing that degrades. The Claude Code best-practices guide says performance drops as the context window fills: Claude may start forgetting earlier instructions or making more mistakes. That is context rot, and a history full of failed attempts makes it worse.
What /compact and /clear actually cost
/clear is free. The Claude Code documentation on costs says it in as many words: when you want a fresh start rather than continuity, /clear costs nothing. The first message afterwards carries the fixed part of the context (system prompt, tool definitions, CLAUDE.md and memory) plus what you type.
/compact is a model request, and on a long session a large one. To write the summary, Claude Code sends a separate request with the same system prompt, tools and full history as your conversation, with a summarisation instruction appended at the end. Its input is everything the session has accumulated. Its output is the summary, and output is the most expensive kind of token.
When you compact decides what it costs. Mid-session the cache is warm, so the history is read at the cached rate: in the documentation's words, a mid-session /compact costs a fraction of what the context size suggests. After a break longer than the cache lifetime, the whole history is reprocessed as uncached input, which makes compacting a session you have just resumed the most expensive case.
What you buy is cheaper requests afterwards: every later request carries the summary instead of the history. Compaction pays off when the session goes on long enough and when what it discards is material you no longer need. To abandon a wrong turn entirely, /rewind is cheaper still: it truncates the conversation back to a prefix that is already cached instead of building a new one.
Automatic compaction, and when it runs
Auto-compaction is on by default. As the conversation approaches the limit, Claude Code first clears older tool outputs, then summarises the conversation if that is not enough, the same way /compact does. It keeps a session alive when the window fills. It does not keep it cheap.
By default it runs late. As of September 2026, the documentation says a session compacts when the conversation reaches the model's context limit, or at about 967,000 tokens on models that run with a one-million-token window on the Anthropic API (such as Sonnet 5, the Fable models, and Opus 4.7 and later). The exact point depends on the model, the provider and your settings. By then every earlier request has carried the growing history, and the compaction itself reads a nearly full window, often in the middle of a task.
You can move the threshold: /autocompact 500k sets how full the window gets before the automatic pass runs, and /autocompact auto restores your model's default (the command needs Claude Code v2.1.221 or later). The Auto-compact setting in /config turns the automatic pass off; /compact still works by hand.
How to see how full the context is
/context shows current usage as a coloured grid, broken down by category and including which CLAUDE.md and memory files loaded, with suggestions when something takes more room than it should. Run it before deciding anything.
/contextWhat is in the window right now, and what is taking the space.
For a continuous reading, put the percentage in your status line: /statusline sets one up from a description, and a script can read the context_window.used_percentage field directly. /usage answers a different question: what the session has spent, and where you stand against your plan limits.
Which one to use
- The next task is unrelated:
/clear. Old conversation crowds out the files the new task needs, and it is paid for on every message. - Same task, long history, and the thread still matters:
/compactwith focus instructions, at a natural break such as a finished subtask, not in the middle of a step. - Part of the session is dead weight:
/rewind. Pick a message before a wrong turn and choose Restore conversation to drop it while keeping your code, or choose Summarize up to here to condense everything older and keep the recent messages intact. - Two failed corrections on the same issue:
/clearand restate the task with what you learned. Anthropic's guidance is that a clean session with a better prompt almost always beats a long one full of corrections. - A side question:
/btw, whose answer never enters the conversation history. - Unsure:
/clearis the cheaper mistake. It costs nothing, and/resumebrings the old conversation back.
The habit that beats both: one session per task
Both commands are repairs. The cheaper habit is not needing them: one conversation per task, started when the task starts and cleared when it ends.
Whatever must outlive the conversation belongs in a file, not in the history: rules in CLAUDE.md, which reloads after every /clear and every compaction, and the state of a long piece of work in a notes file you ask Claude to write before you clear. Writing it costs a turn, like a compaction, but you choose what it keeps and it survives the session.
If you would rather have that discipline built in than remembered, capsul drives the Claude Code you are already signed into and treats each capsul ask as its own task, under a token budget you set. It sends what the task needs, not the repository, and stops at the budget with a note of what it left out.
capsul ask 'fix the flaky checkout test' --budget 3000One task per command, under a ceiling you set.
Questions
Should I use /compact or /clear in Claude Code?
Use /clear when the next task is unrelated to the conversation so far: it costs nothing, gives Claude a clean context, and the old conversation stays available through /resume. Use /compact when you are partway through one task and the history still matters, ideally at a natural break and with focus instructions such as /compact focus on the auth bug fix. When in doubt, /clear is the cheaper mistake.
Does /compact use tokens?
Yes. To write the summary, Claude Code sends a separate request containing the whole conversation plus a summarisation instruction, and the summary comes back as output tokens. Mid-session most of that input is read from the prompt cache at a reduced rate, but after a break longer than the cache lifetime the full history is reprocessed, so compacting a freshly resumed session costs the most. Later requests are cheaper because they carry the summary instead of the history.
When does Claude Code compact automatically?
Auto-compaction is on by default and runs as the conversation approaches the auto-compact window, which by default sits close to the model's full context window. As of September 2026 the documentation gives about 967,000 tokens for models that run with a one-million-token window on the Anthropic API. /autocompact sets a different size, and the Auto-compact setting in /config turns the automatic pass off while leaving /compact available.
Does /clear delete CLAUDE.md or my previous conversation?
No. /clear empties the conversation, not the project: CLAUDE.md and auto memory load again at the start of the new conversation. The previous conversation is saved locally and /resume reopens it, and passing a name, as in /clear release-prep, labels it in the resume picker first.
How do I see how full the Claude Code context window is?
Run /context, which shows current usage as a coloured grid by category, with suggestions when something takes too much room. For a continuous reading, set up a status line that displays context_window.used_percentage; /statusline can configure one for you. /usage shows what the session has spent and where you stand against your plan limits, which is a different measurement.
$ npm i -g @penra/capsul