Learning resourcesReviewed · Anthropic

Claude: Compaction at a token threshold

This guide explains automatic conversation summarization for developers building long Claude chats and agents; the main catch is that a billable summary replaces older context. It covers a beta Messages API feature with a default trigger of 150,000 input tokens, a minimum of 50,000, and application logic for carrying summaries into later requests.

Researched 15 Nov 2026

In short.

This guide teaches developers how to continue long Claude conversations through automatic summaries; its main catch is dependence on a billable summary in place of older history. Messages API applications enable the beta, retain compaction blocks and handle cases where no summary is produced. The page also explains caching, streaming, token accounting and model-specific restrictions on preserving earlier thinking blocks. Summary accuracy, runtime reliability, latency and net savings are not assessed.

Researched and written by an AI model and checked by a second AI model. How it works

Coverage is the complete page at [https://platform.claude.com/docs/en/build-with-claude/compaction-threshold.md], including its examples, beta notices, availability tables, billing guidance, limitations and data-handling statements. Linked documentation, SDK packages, image assets and Cookbook recipes are excluded. Cloud-specific integration, actual API behavior, summary fidelity, failure rates, latency, prices and net savings are not assessed. The page's model-support discrepancy and differences between its short pause examples and fuller failure-handling guidance remain explicit.

The overview

What the guide covers

Compaction at a token threshold is Claude documentation about automatically shortening conversation history during ordinary API requests. The original source is [https://platform.claude.com/docs/en/build-with-claude/compaction-threshold.md]. It is an implementation guide for a hosted API feature.

The page distinguishes two products: Messages API applications opt in through context_management.edits, while Managed Agents always compact session history to fit the context window. Managed Agents emit an agent.thread_context_compacted event for each compaction.

When it is useful

The guide is useful when an application must continue a long conversation without keeping every earlier message in the model's active context. Its strongest practical coverage concerns retaining summaries, handling pauses and accounting for the additional model work.

The page says compaction helps address quality degradation in growing contexts, but supplies no comparative measurements. Because older content is replaced, preserving the details needed for later work is a central adoption question. Reliable recall and overall savings are not established.

Who it is for

The intended users are developers building persistent chats, assistants with many follow-up requests, and agents that accumulate substantial tool output. Beginners get examples in several languages; experienced developers get details about response blocks, serialization, streaming and usage accounting.

Applications that require exact access to every earlier exchange need to consider what must remain outside the summary. The page does not establish that summaries preserve complete transcripts, exact quotations or every technical decision.

Available controls

The compact_20260112 edit supports an input_tokens trigger, defaulting to 150,000 tokens with a minimum value of 50,000. Developers can replace the summarization instructions and enable pause_after_compaction to adjust the conversation before generation continues.

Compaction blocks support cache_control breakpoints. The guide also describes caching the system prompt separately so a new summary does not require that prompt to be cached again.

Streaming delivers the complete summary in one compaction_delta event, without incremental summary text. The token-counting endpoint applies existing compaction blocks but does not generate new summaries. With server tools, compaction can occur more than once within a request.

Using it

Access and compatibility

Messages API use requires API credentials, a supported model, the compact-2026-01-12 beta header and a compact_20260112 edit in context_management.edits. The examples use claude-opus-5-5 and API version 2026-10-21. Minimum SDK versions are not supplied.

The availability tables cover Claude API, two Amazon Bedrock routes, Claude Platform on AWS, Google-managed Claude and Microsoft Foundry, with different model lists. Platform-specific setup is not fully explained on this page.

Messages API support for Haiku 4.5 is unclear: the page-wide metadata includes it, but the detailed Messages API table omits it. The Managed Agents table explicitly includes it. These product-specific lists should not be treated as interchangeable.

How history is shortened

When input reaches the configured threshold, the API uses the requested model to summarize the conversation, returns a compaction block and normally continues generating with the shortened context.

The application must return that block in subsequent requests. A usable compaction block causes preceding content blocks to be ignored. Applications can retain the original message list or remove the compacted portion themselves.

A block whose content is null is ignored and does not shorten history. Original messages must therefore remain available in that case. Earlier thinking blocks are not carried forward through compaction; the summary supplies continuity for that earlier work.

Integration details

The basic integration adds {"edits":[{"type":"compact_20260112"}]} as context_management, enables the required beta and appends the complete assistant response to the next request's messages. Preserving only visible text would omit the compaction block.

For paused requests, inspect whether a compaction block exists and whether its content is non-null. A blocked summary can return stop_reason refusal, so checking only for stop_reason compaction misses that path. Keep the original history whenever no summary was generated.

The Python guidance uses client.beta.messages. It warns that serializing through client.messages with plain model_dump() can add invalid null fields and cause a 400 error. The documented alternatives are to_dict() or model_dump(exclude_none=True).

Documented conversation example

The page illustrates a chat that starts with a Python web scraper, adds JavaScript-rendered page support, then adds rate limiting and error handling. Its chat function uses a 100,000-input-token trigger and max_tokens of 4096, saves the entire assistant response and returns a text block to the caller.

A more detailed example pauses after compaction and places the previous exchange plus the current user message after the summary. It removes thinking blocks from the preserved assistant turn. These are illustrative examples; successful execution and summary quality are not established.

Assessment & evidence

Failure cases and restrictions

When tools are defined, the summarizing model can call a tool instead of writing a summary, producing a compaction block with null content. The documented mitigation is custom instructions that require a text-only summary and prohibit tool calls. Custom instructions completely replace the default prompt, so necessary preservation requirements must be included.

Reinserting earlier assistant turns can fail thinking-block prefix checks on Fable 5.1 and 5.2, Mythos 5.1 and 5.2, Opus 5.5, Sonnet 5.5 and Haiku 5.5. The page recommends removing thinking and redacted_thinking blocks, letting the API summarize everything, or using thinking.block_binding.prefix_mismatch_behavior set to drop_block with the thinking-binding-controls-2026-08-01 beta. On Sonnet 5.5 and Haiku 5.5, that binding control requires adaptive thinking.

Several short pause and budget examples check only the compaction stop reason, while later guidance explicitly requires inspecting the block to handle refusals. The more complete preservation example accounts for both missing summaries and refusal stop reasons. Failure frequency and recovery reliability are unknown.

The central tradeoff

Automatic triggering reduces the application's responsibility for deciding when to summarize. Its corresponding dependency is the summary: earlier requirements, decisions and tool findings remain useful only to the extent they are retained or deliberately reinserted.

This implies that applications needing exact identifiers, unresolved tasks or detailed technical state should define those preservation requirements explicitly. That is an inference from the replacement mechanism, not a measured guarantee of accuracy. The page provides no benchmark showing which threshold or instructions best preserve task performance.

Other approaches mentioned

The page contrasts threshold compaction with on-demand compaction. Threshold compaction runs automatically inside ordinary requests once the configured input size is reached; on-demand compaction lets the application decide when the summary is written.

It also links to context editing and a session-memory compaction recipe. Those linked resources are excluded here, so their detailed behavior, requirements and comparative results are unknown. Managed Agents provide an always-on compaction route, with different integration behavior from Messages API opt-in.

Source and evidence limits

The source is the complete Claude documentation page at [https://platform.claude.com/docs/en/build-with-claude/compaction-threshold.md], captured on 2026-11-15 at 02:57:19.562 UTC. Its recorded source revision is sha256:936c502762e2b7bf66104482222ee86eca3a7e97148a42670b35de32b4574630.

The page supplies configuration examples, illustrative responses, availability tables and explicit limitations. It supplies no independent measurements of summary fidelity, failure rates, latency or savings. No code or API requests were executed; runtime behavior is not assessed.

Access & freshness

Billing and token accounting

Generating a summary requires an additional sampling step that contributes to billing and rate limits. The requested model also performs summarization; developers cannot select a separate cheaper model for that step. Dollar prices and net savings are unknown from this page.

Top-level usage.input_tokens and usage.output_tokens exclude compaction work and sum the non-compaction iterations. Total request token consumption must be calculated across usage.iterations. With the beta enabled, this array appears even when no new compaction occurs. Returning an existing compaction block causes no additional compaction charge.

The page's compaction counter multiplied by the trigger threshold is an estimate for prompting a task to finish. It does not establish an exact billing total or a hard spending limit. Cache pricing and actual latency overhead are also unspecified.

Rights and data handling

The page supplies no explicit licence or redistribution terms for its documentation or embedded examples. Permission to redistribute those materials and the service's full usage terms are unknown from this page.

Threshold compaction is described as eligible for zero data retention, excluding Covered Models. The excluded models are defined on a linked page and are not identified here. Compaction results are returned through the API response and carried back statelessly by the application. The data-handling table marks the feature as not HIPAA eligible.

Version and availability caveats

The captured page describes threshold compaction as a beta feature. It gives no explicit publication or last-updated date. The compact-2026-01-12 beta identifier and the examples' 2026-10-21 API version do not establish when the documentation last changed.

Model and platform availability are the states described in the capture. Subsequent changes are unknown, and the Haiku 4.5 discrepancy leaves that model's Messages API support unresolved within this page.

What to establish before adoption

Confirm support for the intended model, API product and cloud route. Implement full compaction-block retention, preserve history on null summaries and handle refusal responses. If preserving earlier assistant turns, apply the documented thinking-block restrictions.

Evaluate representative long conversations for retention of requirements, exact identifiers, unresolved work and tool state. Include tool-related summarization failures and paused continuation in that evaluation. Measure latency and calculate usage across every iteration before estimating operating cost.

If replacing the default summary instructions, explicitly state what must survive and prohibit tool calls during summarization. For data-retention requirements, establish whether the chosen model falls under the documented exclusion.

Evidence for this report

selected-page.txtselected · checked 2026-11-15