In short.
Compaction in the background is a Claude API guide for developers who want conversations to continue while older messages are summarized, but correct coordination of the requests and history remains their application's responsibility. The application records the number of messages submitted for summarization, continues appending turns and replaces exactly the submitted messages when the summary arrives. The feature is in beta, uses an additional concurrent request and needs spare context capacity until the replacement happens. The page provides six language examples but establishes no pricing, measured performance benefit or summary-quality results.
Researched and written by an AI model and checked by a second AI model. How it works
Coverage is the complete selected page at [https://platform.claude.com/docs/en/build-with-claude/compaction-background.md], including all embedded language examples, beta and availability notices, the synchronous PHP SDK limitation and preserved-thinking caveat. Linked pages and separately hosted image contents are excluded. No code or API request was executed. Runtime correctness, performance, summary fidelity, pricing and account-specific availability remain unverified.
The overview
Resource identity
This Claude documentation page teaches background compaction, also called async compaction. Compaction produces a summary of earlier conversation messages; the background pattern lets normal conversation requests continue using the full history while that summary is generated.
The original document address is [https://platform.claude.com/docs/en/build-with-claude/compaction-background.md]. Its declared documentation URL is [https://platform.claude.com/docs/en/build-with-claude/compaction-background]. It is an implementation guide rather than a standalone application or installable library.
Practical assessment
The guide is useful when waiting for a conversation summary would interrupt an application's work. Its strongest contribution is the precise replacement rule: replace only the messages included in the summary request, leaving every subsequently appended turn in place.
The tradeoff is additional coordination and temporary resource use. Conversation history continues growing during summarization, and two requests can be open at once. The page explains the mechanism clearly but does not demonstrate measured latency improvements, compression ratios or retention of important details.
Who it suits
The intended users are developers who control a Claude application's message history and need to manage long conversations. They must be able to issue API requests, retain application state and coordinate concurrent work.
Beginners get a concrete explanation of which messages survive the replacement. Experienced developers get examples using futures, promises, tasks, channels and threads. This is a programming pattern to implement in an application, so readers need familiarity with their language's request and concurrency behavior.
What it covers
The page shows how to start an on-demand summary without waiting for it before continuing the conversation, detect completion, preserve intervening turns and apply the returned message before sending the next conversation request.
It includes examples in Python, TypeScript, C#, Go, Java and Ruby. Each example limits the application to one pending compaction request and waits for any remaining summary before finishing. A separate note says the PHP SDK sends requests synchronously and cannot support the illustrated background behavior while the conversation continues.
Using it
Requirements
The feature requires a supported model and platform through the Messages API, with the compact-2026-09-04 beta header. The examples use claude-opus-5-5. The availability table lists beta support on Claude API, Claude Platform on AWS, Google-managed Claude Models on Google Cloud, Microsoft Foundry and Amazon Bedrock.
Model availability differs by platform; the Bedrock list is narrower than the list for the other platforms. The application also needs concurrent request support and enough unused context capacity for turns added before the summary arrives. Minimum SDK versions, account-specific access requirements and numerical rate limits are not provided.
How it works
Copy the current message history, record its message count and submit that snapshot with compaction set to type summarize. While the request is pending, append new turns to the live history without editing earlier messages. Do not start another compaction request until the pending one has been applied or has failed.
When the response has stop_reason equal to compaction, replace exactly the recorded number of messages at the front of the live history with the returned assistant message content. Keep all later messages after it and use the replaced history on the first request after the summary arrives. A response with any other stop reason leaves the full history intact.
Implementation setup
The examples maintain a live history, a pending request handle and the count of messages submitted for summarization. At the beginning of each turn, they check whether the pending request has completed and apply its result before sending the next conversation request.
The demonstration starts compaction after the preceding response's input_tokens plus output_tokens exceeds 2,500, provided more turns remain and no summary is pending. The page explicitly describes this threshold as deliberately low for a short example. Conversation requests allow up to 8,192 output tokens and summary requests up to 4,096; these are example settings, not measured usage or general sizing recommendations.
Concrete example
Suppose the application submits messages 1 through 5 for summarization and then adds messages 6 through 8 while waiting. Once a successful summary arrives, the next history consists of the returned summary message followed by messages 6 through 8. Replacing the entire live history would discard those newer turns.
The supplied programs illustrate the pattern with questions about a recipe application's data model, including entities, fields, indexes and defaults. They are illustrative code; no execution results are supplied, and none of the examples was run for this report.
Assessment & evidence
Limits and failure handling
Background execution does not prevent the context window from filling while a summary is pending. Compaction must start early enough to leave room for intervening turns. The pattern also requires earlier history to remain unchanged and permits only one pending compaction request.
For a response without the compaction stop reason, the guide says to keep the full history. Complete recovery instructions are delegated to a linked page. The examples expose request exceptions through their concurrency mechanisms or terminate on errors rather than supplying a complete recovery implementation.
For models with preserved thinking, the page says thinking in retained turns stays valid only while additional conditions hold. Those conditions are on another page and are not established here. Summary accuracy, failure frequency and behavior under heavy concurrency are not assessed.
Why the details matter
Recording a message count binds the arriving summary to the exact history it represents. Preserving everything after that boundary prevents conversation turns added during summarization from disappearing. These rules explain why copying the submitted history and keeping the live history append-only are central to the pattern.
The practical tradeoff is inferred from the documented behavior: overlapping requests can remove the summary wait from the normal conversation path, while full-history requests and concurrent capacity remain necessary until replacement. The page provides no evidence that the resulting summary preserves every task-relevant detail.
Alternative approach
The directly described alternative is an on-demand compaction loop that waits for the summary before continuing. Background compaction moves that same request off the conversation's path and changes replacement so that intervening turns survive.
The related guide is linked at [https://platform.claude.com/docs/en/build-with-claude/compaction-on-demand#compact-in-a-loop]. Its full contents are outside the supplied evidence. This page does not compare competing services or quantify the tradeoffs between waiting and background execution.
Evidence basis
The evidence is the complete supplied documentation page, including its explanatory text, embedded code examples, availability table, beta notice and PHP limitation. It contains no observed API responses, benchmark dataset or independent execution results.
The original source is [https://platform.claude.com/docs/en/build-with-claude/compaction-background.md]. Its recorded source revision is sha256:dcb87b3fb7906b799f06e4d31b90968fcef0c10e53c8f7a61c27b899b3405aef. Linked documentation and the separately hosted diagram's contents are outside this evidence.
Access & freshness
Costs and resource use
Pricing is unknown from this page. It states that compaction requests count against rate limits like other requests and that the application has two requests open while conversation and summarization overlap.
Normal turns continue using the full history until the summary is applied. The page provides no billing example, token-price schedule, measured savings or total-cost comparison. The example's output-token limits do not establish actual token consumption or cost.
Rights and licensing
The supplied page contains no explicit licence or redistribution grant for its prose, diagram or code examples. Rights to redistribute those materials are therefore unknown from this evidence. Applicable API terms and data-handling terms are also not included.
Dates and availability
The supplied capture is dated 2026-11-25T01:03:36.963Z. The page labels background compaction as beta and specifies compact-2026-09-04. That header identifies the beta interface; it does not establish the document's publication or last-update date.
No publication date, update history or minimum SDK release is supplied. Model and platform availability are documented for this capture; subsequent changes are unknown.
Next steps for adoption
Confirm that your chosen model, hosting platform and SDK support the documented beta interface. Set a compaction threshold with room for conversation growth during summarization, and implement snapshot copying, message counting, append-only updates and replacement before the next request.
Before deployment, validate delayed summaries, intervening turns, non-compaction responses, request exceptions and pending work at shutdown or save time. Consult the linked recovery and preserved-thinking documentation for the conditions omitted here, and establish pricing and summary quality for your workload. These are recommended validation steps, not completed tests.
