/compact โ Context Compression
Claude CodeCompress 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
/compact โ automatically summarize and compress the entire conversation
/compact <prompt> โ compress while emphasizing specific context (e.g., /compact Focus on DB migration work)
Key decisions, changed file lists, and current work status are preserved after compression
Unlike starting a new session (/clear), the workflow is not interrupted
Tags
Source
Anthropic Docs