๐Ÿ—œ๏ธ

/compact โ€” Context Compression

Claude Code

Compress conversation context to save tokens

/compact is a command that has Claude automatically summarize and compress the conversation so far.

Why is it needed?

As conversations in Claude Code grow longer, they approach the context window (token limit). When the limit is reached, earlier conversation content may be truncated or response quality may degrade. Running /compact compresses the conversation to only the essentials, allowing you to continue working without starting a new session.

When to use

  • When switching to a different task after a long debugging session

  • When context becomes heavy after modifying multiple files

  • When Claude starts forgetting previous instructions

  • When remaining context shown in the status bar is running low

Custom prompt

You can emphasize specific content when compressing with /compact <prompt>.

/compact Focus on the ongoing refactoring work

This makes Claude prioritize preserving that context.

How to Use

1

/compact โ€” automatically summarize and compress the entire conversation

2

/compact <prompt> โ€” compress while emphasizing specific context (e.g., /compact Focus on DB migration work)

3

Key decisions, changed file lists, and current work status are preserved after compression

4

Unlike starting a new session (/clear), the workflow is not interrupted

Tags

#compact #context #compression #token #efficiency

Source

Anthropic Docs