Source: Compaction overview (Claude API docs)

Anthropic's server-side summarisation of older turns, offered on demand or at a token threshold, as an alternative to writing your own summariser.

Contents

Summary

Compaction replaces older turns with a summary Claude writes server-side. It keeps long conversations and agent runs inside the window and keeps active context small, since the docs note response quality degrades as a conversation grows. Three options are compared: on-demand compaction, compaction at a token threshold, and your own summariser.

Key claims

  • On-demand: the application requests a summary block and places it first in messages, replacing the turns it covers. It can keep recent turns verbatim and can run in the background.
  • Threshold: the API compacts inside the request that crosses a trigger you set; you append the response as usual and the API drops what came before the block.
  • Own summariser: you write the summarisation call, prompt and history rewrite.
  • The docs recommend on-demand compaction wherever it is available; a custom summarisation prompt is supported when the default drops something later turns need.
  • Context editing is the rule-based alternative (clear tool results or thinking) when summarising is not wanted.

Feeds

Agent memory

Suggest changes →