Claude Code /compact vs /clear: what actually happens to your context
/compact replaces your conversation with a summary Claude writes and keeps the same session going. /clear starts a new conversation with an empty context. Your project memory, like CLAUDE.md, still loads, and the old conversation stays available through /resume . That's the short version. The longer version matters, because the two commands look alike in the prompt bar and behave very…
Claude Code offers two commands, /compact and /clear, that significantly alter your conversation context. /compact replaces the current conversation with a summary Claude writes, while /clear starts a brand new conversation with an empty context. Despite their similar appearances, the two commands function quite differently and can lead to major loss of information if used interchangeably.
When you use /compact, Claude summarizes the conversation up to that point, freeing up context. This operation is automatic and happens near the conversation limit. The system prompt and output style remain the same, but only the summarized information persists, excluding the rest of the conversation including path-scoped rules, nested CLAUDE.md files, and additional context hooks.
On the other hand, /clear initiates a completely fresh conversation with no context whatsoever. While it requires no costs, it also requires manual effort to ensure important details are documented before executing the command. The key difference between the two lies in the level of lossiness. /compact results in lossy summary, meaning a significant portion of the conversation is discarded. Conversely, /clear allows you to retain what you deem important, starting the new conversation only with the relevant context.
To determine which command to use, Anthropic suggests using /compact when the session is bloated and you're mid-task. Conversely, /clear is recommended when starting a completely new task, as it allows you to decide what information to retain. For long tasks, some users employ workarounds such as requesting handoff notes, using tools like claude-auto-handoff or claude-mem, or employing context-mode to reduce the amount of tool output in the context.
Aigent-OS, a tool I developed, automates the clean-window process by checking a context threshold and prompting Claude to write a capsule, a checkpoint file containing the work state and next steps. If the acknowledgement is received, /clear is executed, and the session resumes from the capsule. If not, the session remains intact, and memory is saved in markdown format in git for future reference.
However, it's essential to note that /clear does not delete your CLAUDE.md or project files; it only clears the conversation. And although /compact costs more due to the need to read the entire conversation, it employs Claude's model-writing summary.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.
This story
This is one outlet's version. Read the fullest account.