Commands

/compact

Summarizes the conversation to free up context.

/compact replaces the conversation so far with a summary to free up context. Use it when you want to keep working on the same task but make the conversation lighter.

How it works

When you run /compact [instructions], Claude Code replaces the conversation so far with a structured summary. It is the same conversation, so the working context stays in summarized form. Claude Code also does the same thing automatically when the context gets close to its limit, so a full context does not end the session right away.

Here is what the official docs say about the state after compaction, trimmed to the parts you need to know as a user.

  • Project-root CLAUDE.md and rules without path conditions: re-injected from disk.
  • Auto memory: re-injected from disk.
  • CLAUDE.md files in subdirectories and rules with paths: conditions: reloaded when needed.
  • Files you read or edited: up to 5 are re-read, most recently modified first. Files over 5,000 tokens come back as a path reference only, without contents.
  • Instructions you only gave in conversation: may be lost if they are not included in the summary. If something must last, put it in CLAUDE.md.

How to use it

Type /compact in the input box. If you add instructions after it, you can decide what the summary keeps. The official docs give the example /compact focus on the auth bug fix. If you compact by hand before starting a long new task, what remains is what you chose, not what automatic compaction guessed was important.

You can also write what to focus on during compaction in CLAUDE.md, under a heading like "Compact instructions." The costs doc shows this approach as an example.

/compact
/compact keep the auth logic and the failing tests

# Putting it in CLAUDE.md
# Compact instructions
When you are using compact, please focus on test output and code changes

Other options

  • In /rewind, pick a message and choose "Summarize from here" or "Summarize up to here" to summarize only part of the conversation.
  • /autocompact <token count> (for example /autocompact 500k) sets when automatic compaction starts. Pass auto to return to the model-specific default. Available in v2.1.221 and later.
  • Hand research work that reads large files to a subagent, and the file contents do not pile up in your context.

How it differs from /clear and /context

/clear starts a new conversation with an empty context. The previous conversation is saved and you can return to it with /resume. /compact summarizes the same conversation and continues it. If the topic changes, /clear is right. If you are continuing the same topic, /compact is right.

/context is a diagnostic command that shows what is taking up the context. Checking it before you compact helps you tell whether compaction is what you need or something else is the cause.

There is a cost note too. /compact has to read the conversation it is summarizing, so compacting a large context is itself a large request. If you want a fresh start with no continuity, /clear costs nothing.

Real examples

You debugged a login bug for a long time, the conversation got long, and now you are moving on to the fix

/compact keep the root cause analysis and the list of files to change

The earlier conversation is replaced with a summary, and what you asked for is prioritized in it. You can go straight into the fix in the same conversation.

After compaction, Claude seems to have forgotten a rule you gave it in conversation

Add "never run tests in parallel" to the rules section of CLAUDE.md, then /compact

The project-root CLAUDE.md is re-injected from disk after compaction, so the rule survives. A rule given only in conversation has no such guarantee.

You are moving to a completely different feature and do not need the earlier conversation

/clear payments

A new conversation starts with an empty context, and the previous one is named "payments" so you can find it in the /resume list. Clearing fits better than compacting here.

Common mistakes and when not to use it

  • Using /compact when the topic has completely changed. The summary of the old work follows you into the new work. /clear is the right tool here.
  • Assuming an instruction given only in conversation will survive compaction. Put rules that need to last in CLAUDE.md.
  • Assuming Claude knows file contents after compaction. Large files (over 5,000 tokens) come back as a path only, so they may need to be read again.
  • Waiting until the limit and leaving it to automatic compaction. If you want to decide what is kept, compact by hand at the end of each stretch of work with instructions.

FAQ

Does /compact erase the whole conversation?

The conversation is replaced with a summary, so the details go away and only the summarized context remains. If you do not need the earlier conversation at all, starting fresh with /clear is cleaner.

Does it compact automatically?

Yes. Claude Code compacts automatically when the context gets close to its limit. You can adjust the timing with /autocompact.

Does CLAUDE.md survive /compact?

The project-root CLAUDE.md is re-injected from disk after compaction. CLAUDE.md files in subdirectories load again when Claude works on files in those directories.

Checked against the official docs on 2026-10-30. Sources: Claude Code docs: Commands, Claude Code docs: Explore the context window, Claude Code docs: Manage costs effectively, Claude Code docs: How Claude remembers your project. How we write

Usage

/compact 인증 로직 위주로 남겨줘

When to use it

When a long conversation gets slow or the context fills up.

Related

/clearStarts a new conversation with an empty context; if you give it a name, the previous conversation gets that label.Claude CodeCommands/contextShows context usage as a colored grid and suggests ways to optimize it.Claude CodeCommands/autocompactSets when automatic compaction kicks in.Claude CodeCommands

More Claude Code commands

/helpShows help and the commands you can use.Commands/clearStarts a new conversation with an empty context; if you give it a name, the previous conversation gets that label.Commands/contextShows context usage as a colored grid and suggests ways to optimize it.Commands/autocompactSets when automatic compaction kicks in.Commands/configOpens the settings screen, or sets a value directly with key=value.Commands/statusShows version, model, account, and connection status on the Status tab of Settings.Commands
All Claude Code