Skip to content
Mastering Claude

Home / Context and cost

Context and cost7 minApplication

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.

Figure 1

Before choosing between compact and clear

01
Read just the useful slice
Before reaching the limit, ask Claude to consult only the portion of a large file that actually serves the question asked.
02
Subject continues: /compact
The message history is replaced with a summary, and the same conversation carries on with that summary at the front.
03
Subject changes: /clear
The history is wiped and a fresh conversation starts, with no summary of the old subject.
The sequence shows the shared upstream move, then the two possible outcomes depending on whether work continues on the same subject or changes completely.
Calibrate it yourself

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 to remember
  • /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.
Do this now

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.

Check the source

Every datable claim in this lesson links here to the public text behind it. A source that does not open proves nothing.