/compact

/compact is the Claude Code command that replaces the current conversation’s history with a summary, freeing room in the context window without starting from scratch. You can add instructions about what the summary should keep, for example /compact keep the decisions about the API. Claude Code runs a similar compaction on its own when the conversation gets close to the context limit.

The command that summarizes the long conversation so far, to free up room. You can say what to keep, for example “/compact keep the decisions about the API”.

How it shows up in Claude Code

You type /compact in the conversation, with or without instructions after it. Claude summarizes the conversation and carries on from there. After compaction some things come back automatically: the CLAUDE.md in the project root is reloaded from disk, the plan written in plan mode is kept, and Claude re-reads up to five of the files it worked on most recently. Everything else survives only as the summary. You can also put compaction rules in CLAUDE.md, for example “when compacting, keep the list of changed files and the test commands”. To summarize only part of the conversation, use /rewind and pick “Summarize from here” or “Summarize up to here”.

Example

You’ve been working on an online ordering page for a long time and Claude has read many files. You want to continue the same task, but with free room:

/compact keep the structure of the order form and the bugs still to fix

The long discussion becomes a short summary, and Claude keeps working without dragging all the old details along.

Common mistakes

  • /compact instead of /clear for a new task. If you’re moving on to something else, you don’t need a summary. /clear fits better and costs nothing.
  • Compacting without instructions when certain details matter. Say what to keep, or the summary may leave out exactly what you needed.
  • Forgetting that compaction has a cost too. To summarize, Claude reads the whole conversation, so compacting a large one is itself a large request.
  • Important rules only in the conversation. Anything that must always survive belongs in CLAUDE.md.

Related terms and where you learn it

/compact frees context and cuts the tokens used on each message; to start from zero there is /clear. The summary stays in the same session. You learn it in the lesson “How do you look after the conversation memory?” in module 04, The working method, step by step.

Source: Claude Code documentation: Explore the context window

How it appears in the course

For example, /compact keep the decisions about the API makes the summary and keeps the decisions about the API.

How do you look after the conversation memory? · Module 04, The working method, step by step

Use /clear often. For long tasks, /compact.

Key takeaways · Module 04, The working method, step by step

Use /compact (it summarizes the conversation) or /clear (it empties it).

What do you do when something goes wrong? · Module 11, Pro tips

Learn Claude Code from zero, in plain English

12 modules with 1–2 minute lessons, which you can also do on your phone. The first two modules are free.