Learning resourcesReviewed · Anthropic

Compaction and preserved thinking

Compaction and preserved thinking is a guide for Claude API developers shortening conversations, with strict rules for keeping earlier thinking blocks valid. It explains API-written summaries, unchanged retained messages, configuration constraints and how to detect thinking blocks that fail validation.

Researched 25 Nov 2026

In short.

Compaction and preserved thinking is a guide for Claude API developers managing long conversations, where retaining earlier thinking requires strict message and configuration consistency. It explains when API-written summaries preserve thinking blocks, why application-written summaries invalidate retained thinking, and how subsequent responses reveal failures. Seven SDK examples illustrate the process. The features are documented as beta; the examples were not executed, and prices, performance and minimum SDK versions are unknown.

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-thinking-blocks.md], including its prose, embedded SDK examples, illustrated output, availability table and beta-header notices. Linked documentation, pricing, licences and external terms are excluded. No code was executed; runtime preservation, SDK compatibility, performance, actual costs and summary quality were not assessed.

The overview

identity

This Claude documentation page explains the interaction between conversation compaction and preserved thinking. Compaction replaces earlier messages with a summary; preserved thinking concerns thinking blocks returned by the model and sent back on later requests. The exact source address is [https://platform.claude.com/docs/en/build-with-claude/compaction-thinking-blocks.md].

Its scope is narrow: thinking in messages retained after a compaction block, an application-written summary or a cut in conversation history. It is implementation guidance rather than a standalone tool.

assessment

The guide is useful when an application summarizes older conversation history while retaining newer messages containing thinking blocks. Its strongest contribution is distinguishing an accepted compaction block from valid retained thinking: the API can accept the summary while later rejecting or dropping thinking in the messages after it.

The documented response checks give developers a concrete way to investigate preservation failures. They establish whether thinking blocks passed the prefix check or were dropped; they do not establish summary accuracy, answer quality or application reliability. Runtime behavior was not assessed.

users

The intended readers are developers maintaining Claude API conversation histories, particularly applications that retain recent turns or receive new turns while a summary is being generated. The advice also applies when application code writes summaries or removes older messages.

Beginners need familiarity with API requests, message roles and content blocks. Experienced developers get details about message boundaries, repeated compaction, tool configuration and failure monitoring. Applications that never send earlier thinking blocks back have little need for this page's preservation rules.

capabilities

The page covers preserving thinking through repeated API compactions, changing system prompts or tools safely, handling application-written summaries, and detecting discarded thinking. It explains both strict failure with prefix_mismatch_behavior set to error and continued requests with drop_block.

Examples are supplied for Python, TypeScript, C#, Go, Java, PHP and Ruby. The cURL and CLI entries direct readers to an SDK because the workflow needs more logic than a single shell command.

Using it

requirements

Every compaction performed since a retained thinking block was produced must use a model with preserved thinking. Retained messages must remain unchanged and directly follow the summarized messages, without repeated summarized content, inserted messages or omitted messages at the boundary. The first retained message must have a different role from the last summarized message and cannot be a mid-conversation system message, because the API otherwise merges it into the preceding message.

The system and tools fields must match the requests that produced the retained thinking, the compaction request and subsequent requests. An unreferenced tool marked defer_loading: true is the documented exception.

The availability table lists beta support through the Messages API on Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Google managed) and Microsoft Foundry, across selected Fable, Mythos, Opus, Sonnet and Haiku models. Preservation checks require a model that actually enforces the prefix check; the guide warns that a model unable to read a thinking block can silently drop it.

mechanism

A prefix check compares earlier thinking blocks with the conversation that produced them. According to the page, this check recognizes a summary written by the API as an acceptable replacement for the summarized history. Thinking in unchanged retained turns can therefore remain valid after that replacement.

A later compaction summarizes the previous summary and all following messages included in that compaction request. Messages left outside the request become the new retained turns. Every compaction after a thinking block was produced matters to its validity; compactions before its production do not.

setup

The examples use compact-2026-09-04 for compaction and thinking-binding-controls-2026-08-01 for thinking.block_binding.prefix_mismatch_behavior. They enable adaptive thinking and set the mismatch behavior to error. SDK installation, authentication instructions and minimum SDK versions are not specified on this page.

To change system or tools without invalidating retained thinking, the documented approach is to compact the whole conversation first, retaining no turns, and change configuration on the next request. Another documented approach is to append instruction or tool changes through messages rather than changing those request fields.

Summarized mid-conversation system messages lose their instruction text and per-message effort effects. Their tool changes can persist through the returned block's tool_changes field when inline-tools-2026-09-15 is sent on the compaction request and every request containing that unmodified block. To restate instructions, effort or tools, the page places a system message directly after the next new user message, following any retained turns.

example

The SDK examples use claude-fable-5-1 for every step. They obtain two conversation responses, summarize only the first user-and-assistant exchange, and retain the second exchange. A subsequent request sends the compaction block first, the retained exchange next and a new user message last.

The program counts thinking blocks in the retained response and examines input_transformations on the subsequent response. The page illustrates one retained thinking block and zero dropped blocks. Its documented success condition is a 200 response with an empty input_transformations array; a conversation-binding mismatch under error produces a 400 response identifying the first failing block. These are supplied examples and expected signals, not observed execution results.

Assessment & evidence

limitations

When application code writes a summary or cuts earlier history, retained thinking fails the prefix check wherever that check is enforced. The documented options are to have the API write the summary, remove thinking and redacted_thinking blocks while retaining other content, or use drop_block on every request carrying the affected turns.

A compaction response cannot confirm preservation of thinking in turns left outside its request. That outcome appears on the subsequent request. The compaction request can itself fail if thinking it carries no longer matches edited messages or changed configuration.

On Claude Sonnet 5.5 and Claude Haiku 5.5, block_binding works only with adaptive thinking. With other thinking settings, the page requires the preservation conditions to hold or the affected thinking blocks to be removed. Latency, summary fidelity and behavior across SDK or platform versions were not assessed.

reasoning

The practical distinction is between retaining message content and retaining its associated thinking. A summary and the visible retained conversation can remain usable even when thinking is rejected or discarded. This explains why successful requests alone are insufficient evidence of preservation, and why the guide combines strict mismatch errors with inspection of transformation records.

alternatives

The page offers several approaches within the same API. Keeping recent thinking uses API-written compaction and unchanged retained turns. Compacting the entire conversation before changing configuration avoids leaving retained turns whose thinking could be invalidated.

An application can instead keep its own summary and remove affected thinking blocks, or request drop_block behavior. Sending only the summary and next instruction together as one user message sends no earlier thinking, and the page says later thinking is valid. Other vendors and summarization libraries are not compared.

evidence

The evidence is the complete documentation page captured from [https://platform.claude.com/docs/en/build-with-claude/compaction-thinking-blocks.md] on 2026-11-25 at 01:07:29.904 UTC. It includes explanatory text, seven SDK examples, illustrated output, availability information and beta-header requirements.

The findings describe the behavior documented by that source. Nothing was executed. The illustrated output is not an independent test receipt, and linked reference pages were not assessed.

Access & freshness

costs

Prices, compaction charges, token savings and operating costs are unknown from this page. The illustrated workflow makes four API requests, but it provides no billing calculation. The page warns that removing or dropping retained thinking can increase output tokens; it does not quantify that increase or establish whether preserving thinking reduces total cost.

rights

The selected page contains no explicit licence or redistribution terms for its documentation or example code. Permission to redistribute either is unknown from this evidence. API contractual terms, data retention and commercial-use conditions are also not established here.

freshness

At capture, compaction and preserved thinking were explicitly marked beta. The page names compact-2026-09-04, thinking-binding-controls-2026-08-01 and, for recorded inline tool changes, inline-tools-2026-09-15. Those dates identify beta interfaces; they do not establish the page's publication or revision date.

No explicit last-updated date or SDK version pin is supplied. Availability and behavior after the capture date are unknown.

actions

Before adopting this pattern, establish whether the application sends earlier thinking blocks back and retains messages after summarization. Map every summary path, including background summaries and repeated compaction, to the documented model, message-boundary and configuration requirements.

For validation, follow the documented strict-error example on a model that enforces prefix checks, confirm that the retained turn actually contains thinking, and inspect the first response after replacing the history. If using drop_block in production, monitor input_transformations for reason prefix_binding_mismatch and use each entry's path to identify affected retained turns. These are recommended next steps; they were not performed.

Evidence for this report

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