Compacting, clearing, reading just what is needed
The /compact command replaces the message history with a summary and carries on the same conversation, the /clear command wipes that history and starts from scratch, and in both cases the project files on disk do not move: the move that saves the most remains getting Claude to read only the relevant slice of a file.
A Claude Code conversation nearing the limit of its context window offers two commands to keep working, and they do not do the same thing. The /compact command replaces the message history with a summary and resumes the same conversation with that summary at the front. The /clear command wipes that history and starts a fresh conversation, with no summary at all.
What neither command ever touches
Neither command modifies a file on disk. Both act only on what is sent to the model with each message, never on the content Claude has read or written in the project. Choosing between the two therefore amounts to choosing what Claude's next reply still needs to know, not to deciding what stays on the computer.
/compact suits a case where work continues on the same subject: the summary keeps the thread of what has already been decided. /clear suits a case where the subject changes completely, a new task with no link to the previous one, since keeping a summary of the old subject would not help the new conversation at all and would keep taking up space.
The most economical move still comes before either command
Even before needing /compact or /clear, one simple move delays the moment the limit is reached: asking Claude to consult only the portion of a large file that actually serves the question asked, rather than the whole document. Searching for the right passage before a full read avoids loading an entire context window with lines that do not serve the current reply. This move needs no extra configuration: it is enough to phrase the request to Claude by specifying the portion sought, for example a named function or a section identified by its heading, rather than attaching the whole file to the conversation.
/compact
History replaced with a summary, the conversation continues.
/clear
History cleared, new conversation.
Content placed right at the start of a conversation is worth keeping stable for as long as possible, including across compactions: prompt cache and the Batch API, two discounts worth knowing explains why that stability also earns a discount on price.
Before choosing between compact and clear
A user has been working on the same project for three hours in a Claude Code conversation. The displayed context is nearing the limit. They type the /compact command and immediately resume work on the same file.
Write, in one sentence, what this situation establishes, and in one sentence what it does not establish.
What this establishes: This move establishes that the message history has been replaced with a summary and that work continues in the same conversation, on the same project.
What this does not establish: It does not establish that the project files on disk have been modified, a compaction acts only on what is sent to the model.
The three most common miscalibrations
- Too broad This command deleted the entire conversation history and restarted the session from scratch.
- Too narrow Nothing can be affirmed since the exact content of the summary the command produced is not known.
- Off target The user worked for three hours straight on the same subject before taking a break.
- /compact replaces the message history with a summary and carries on the same conversation, /clear wipes the history and opens a new one.
- Neither /compact nor /clear modifies a file on disk, both commands act only on what is sent to the model.
- /compact suits a case where work continues on the same subject, /clear suits a case where the subject changes completely.
- Asking for the useful portion of a large file rather than reading it in full delays the moment the context limit is reached.
The next time you ask Claude to consult a large file, ask it to search for the useful passage first before reading the whole file, rather than loading the document all at once.
Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.
- Managing costs in Claude Code consultée le 2026-09-02
- Prompt caching, the mechanics of compaction consultée le 2026-09-02