Compaction

Keep a long Claude session useful by summarizing older history while carrying forward the facts that later turns need.

Select how compaction is triggered

Server-managed compaction can summarize history during a regular API workflow. The platform also documents on-demand approaches for applications that need direct control over when summaries are created or recent messages are retained. Choose based on when you can pause and which turns need to remain exact.

Test what survives

Ask a long-running conversation to preserve an approved decision, a pending question and a timestamped reference. Trigger compaction and verify the next turn can continue from those items. Store durable state in the application and tailor the summary instructions when the default loses a critical detail.

Source documentation

Official Claude documentation