Claude preserved thinking migration guide
Preserved Thinking is a guide in Anthropic's claude-api skill for developers whose conversations replay earlier thinking blocks on models with preserved thinking. It explains how one edit to an earlier turn invalidates every thinking block after it, and walks through finding and fixing the code that breaks reasoning.
What it does
It measures damage per conversation, asking whether a conversation broke and at which turn, since counting failed requests overstates the problem. Through /claude-api preserved-thinking-migration Claude runs the steps in order and delivers a break profile plus the changes.
How to use it
Start at Step 0, setting scope, a quality bar and a baseline, and keep conversation history append-only.
Requirements and limits
It applies to the models listed on the Preserved thinking page, which also names the enforced accounts.
More in Guides and the Claude Code library.
Full text
Preserved Thinking - Keeping Earlier Reasoning Valid Across a Conversation
If you arrived via /claude-api preserved-thinking-migration (or opened this file directly): this is the right file. Execute the steps below in order rather than summarizing the guide back to the user - presenting the break profile, the ranked causes, and the measured result of each fix IS part of the execution. Start with Step 0 (scope, quality bar, baseline) and finish with Step 4's two deliverables: the break profile and the changes.Preserved thinking is measured in units of conversations that keep their reasoning, not requests that pass. One edit to an earlier turn invalidates every thinking block after it, and the same stale block fails again on every later request that replays it - so a per-request count overstates the damage and a per-conversation count (did this conversation break, and at which turn) is the number that tells you whether a fix worked.
What the check is, in one paragraph. On models with preserved thinking (Claude Fable 5.1, Claude Opus 5.5, Claude Sonnet 5.5, and Claude Haiku 5.5 today; the Preserved thinking page lists the models and the enforced accounts, and says to go append-only regardless of the account's age), each thinking block's signature records the conversation that produced it - the top-level system prompt, the set of tools, and every message before the block - and the model that produced it. When the transcript comes back, the API recomputes that record from what you sent and requires a match (a separate model check decides whether the current model can read the block at all; see "Switching models mid-conversation" in shared/preserved-thinking-migration/causes.md). Integrations that keep the history append-only never notice. Integrations that rewrite earlier turns between requests - truncation, client-side compaction, a re-rendered system prompt, a tool list that grows when a plugin connects, a per-turn reminder that is injected and then stripped, old tool results trimmed after the fact, media dropped by a size cap, a lossy round trip through the app's own message types - lose the reasoning after the edit point (drop_block) or fail the request (error). The check compares the conversation as you sent it, before any server-side edit, so Anthropic's own server-side compaction and context editing never count as edits. The published explanation lives in shared/model-migration.md -> Migrating to Claude Fable 5.1 from Claude Fable 5 -> Breaking change 3 (the three-step check and the append-only form of each edit; read it first if the check is new to you) - this workflow restates the rules only as a lookup, the cause table and keep list in shared/preserved-thinking-migration/causes.md; it finds which edits this harness makes, proves them with the API's own response, fixes them one at a time, and proves the fix the same way.
Where this workflow sits: the migrate subcommand explains the check and lists the append-only form of each edit; this workflow is its executable form - scan, measure, fix, re-measure - for a harness that already exists. cost-optimize is a sibling, not a prerequisite: a history that invalidates its own thinking also restarts the prompt cache at the same point, so a fix here usually shows up in its cache-hit numbers too, and a prefix edit found there ("audit for mid-task cache-breakers") is the same finding as a break found here. Cache discipline and preserved-thinking discipline are very nearly the same discipline, so a harness that is already append-only for caching pays nothing extra here. Once the project has an eval, Step 3 runs as a hill-climb whose metric is the drop count - one change per round, measured, kept or reverted - and the hillclimb subcommand is the loop to use.
Two scripts ship with this guide, extracted beside it under shared/preserved-thinking-migration/, and are used by Steps 1 and 2. Both are dependency-free Python 3; neither needs credentials except the probe's live modes, and neither prints them. The commands below give their paths relative to this skill's base directory (the line at the top of the prompt); run them with that directory prefixed, from the user's project directory, so that relative capture paths resolve there. A reference file is extracted beside them, shared/preserved-thinking-migration/causes.md: the rules for a conversation that switches models, the "Cause -> detection -> fix" table, the keep list, and the failure modes to avoid. It is a separate file so that this guide fits in one Read; Read it when a step below sends you there (Step 1.4 at the latest), not before.
shared/preserved-thinking-migration/prefix_diff.py- diff consecutive request bodies in the parts the check compares, and name the difference in the API's own vocabulary;--scangreps a repository for the usual culprits.shared/preserved-thinking-migration/drop_block_probe.py- replay a captured conversation with the controls turned on and record what the API dropped and why, per turn and per conversation;--self-testis the three-request proof that the check is running (Step 0.5) and exits non-zero when it is not.
Severity tiers - one-off vs. recurring
Tier every cause before planning the work. Tiers 0-2 are one-time fixes: apply them once and the harness stops breaking. Tiers 3-4 keep costing - they recur on every conversation that reaches them, which is why they are the ones to measure before deciding.
| Tier | Meaning | Causes | What to do |
|---|---|---|---|
| 0 | Fine - not an edit | cache_control markers; reordering the tools array; server-side compaction and context editing; a retry; a regenerate, rewind, restored checkpoint or branch; the latest turn edited and resubmitted; a model switch (the model check is separate and is not a prefix edit) | Nothing. None of these change the compared prefix - keep them out of the report |
| 1 | Accidental | The system prompt re-rendered with per-request content (a date, a counter, live state); drift from an SDK or domain-model round trip | Remove the edit. Nothing about the product needs it |
| 2 | Fixable | The tool set changed mid-conversation; a same-name tool's description or schema rebuilt; a per-turn reminder injected then stripped; tail state re-rendered every turn | Apply the append-only recipe (Step 3). Adding or withdrawing a tool has an append-only form (tool_addition / tool_removal, with the entry left in tools). A same-name description or schema change has one only under the inline-tools-2026-09-15 beta (Claude API), where a tool_addition carries the new definition (Step 3); without it, keep the first-sent bytes for the life of the conversation and accept the stale definition, or offer the changed text under a new name. Append tail state as new turns rather than rewriting it |
| 3 | Recurring | Tail-kept compaction; background compaction (a second request writes the summary while the session continues, then it is swapped in); rolling truncation; a pinned document rewritten every turn | Measure the drops and decide. Without the compact-2026-09-04 beta (on-demand compaction) no append-only client-side form exists for these: send drop_block from the swap onward, or strip the thinking from the kept turns; the recommended shape is simple compaction, done synchronously. With the beta, keep-tail and background compaction become append-only - see Step 3 |
| 4 | Stop | Prefix surgery - snipping, redacting, pruning old tool results, or removing content after a cache breakpoint to save cost; a missing predecessor; an unrecorded strip-and-retry | No workaround exists. The reasoning after the edit point is lost; the fix is to stop doing it |
A tier is a property of the cause, not of one conversation: rank by tier first, then by reasoning lost within a tier (Step 3).
Step 0: Establish scope, quality bar, and baseline
Does your harness change earlier turns, the system prompt, or the tool list? If not, stop - there is nothing to migrate, and saying so plainly is the finding.
When a replayed thinking block no longer matches, the default is a 400 error. Dropping the thinking instead is opt-in, and it is not a fix: it trades a visible failure for the silent loss of that reasoning, and it is not free - dropped blocks aren't billed, but the session's token usage might still increase because Claude can sometimes think more to re-create the dropped thinking ("Failure modes to avoid" in causes.md).
First, establish three things - from the request and the repository where they answer it, and from the user where they don't. This workflow is interactive by design: a capture of real request bodies, a test slice, and every live replay need the user's involvement or approval, and "which of these edits is deliberate" is a question only they can answer. State all three at the top of the report (the baseline may read "pending Step 2" at first).
- Scope. If an official Claude product or SDK (Claude Code, claude.ai, Claude Managed Agents, the Claude Agent SDK) manages the conversation history, there is nothing to migrate - say so and stop. Otherwise: if the request names files or directories, that is the scope. Otherwise it is every place the project builds the three parts of a request the check compares - the
systemprompt, thetoolsarray, and themessagesarray - across every path that touches them between two requests of one conversation: the request builder, compaction or truncation, reminder or context injection, media handling, persistence and resume (anything that re-reads the conversation from a store and re-renders it), process restart and deploy, plugin or MCP connection, sub-agent transcripts, and model switching. Note distinct traffic classes (an interactive chat path and a background agent loop are different harnesses even on one key): the profile, the fixes, and every validation later run per class. A capture taken on an older model may carry request shapes Claude Fable 5.1 rejects before any check runs -thinking.typeenabledordisabled, a forcedtool_choice(anyortool), an assistant prefill as the last message,temperature,top_portop_kwith a thinking configuration - so list them now as things to convert before measuring (Step 2.1 lists what the probe converts; it leaves a prefill alone, and that 400 shows in its "not evaluated" line). Also establish which platform the code targets (Claude API, Claude Platform on AWS, Amazon Bedrock, Google Cloud Vertex AI, or Microsoft Foundry) and which model it runs: the check applies only to models with preserved thinking. The Preserved thinking page states that beta names are the same on Amazon Bedrock and Google Cloud wherever the beta is available there; for any other platform, read that platform's own documentation andshared/platform-availability.mdrather than assuming. Finally establish whether the organization is enforced today. The rule, as the Preserved thinking page reads on 2026-09-29: on Claude Fable 5.1, Claude Opus 5.5 and Claude Sonnet 5.5 the check is enforced by default for accounts created on or after August 31, 2026, 00:00 UTC, with the same definition on the Claude API and on the cloud platforms; a request that setsprefix_mismatch_behavioropts in regardless of account age; and the page says to go append-only either way, so the same code works on every account. Confirm it from the responses production already gets: an enforced account seesinput_transformationsentries (with the header) or 400s whose text says "bound to a different conversation"; an account that is not enforced yet sees no dropped blocks and no 400s until a request sets the field; with the beta header alone, its responses list each block that would fail as athinking_mismatch_allowedentry (Step 2.2). The page's own probe - send an edited history without the beta header: a 400 that names the header means the account is enforced by default, a 200 means it is not (the Message Batches API returns 200 either way). To confirm a 200, resend with the beta header and still no field: the response lists every thinking block after the edit asthinking_mismatch_allowed. Step 0.5 proves the enforced path - run it with a test key, never against production traffic. - Quality bar. Find the project's eval, test suite, or outcome checks for its model calls. The fixes in this workflow are behavior-preserving by construction (they change how the history is carried, not what the model is told), but two of them are not: replacing a compaction scheme, and choosing to drop thinking at a boundary. Those need the eval. If none exists, say so prominently in the report and do not stop: the drop count itself is a measurement, every fix that removes an edit is safe to propose, and the minimal eval recipe in Step 3 is the next step for the two that aren't.
- Baseline. Two numbers, both from Step 2's probe on the same test slice: the share of conversations with at least one prefix break, and the turn at which each one first breaks. Record them before any fix. The three-arm protocol in Step 2 also asks for the eval score with the current harness and preserved thinking off (that is the eval's existing number) - write it down now if it exists.
Step 0.5: Prove the mechanism is wired
Before trusting any measurement, run one deliberately broken conversation and confirm the API reports it. The probe's self-test sends three requests - one mint and two replays: it mints a thinking block with a one-turn conversation, replays it honestly as turn two (expect input_transformations: []), then replays it with the first user message edited (expect one {"type": "thinking_dropped", ...} entry with reason: "prefix_binding_mismatch", and - on the Claude API - the diagnosis header naming pattern=first_message_rewritten):
python3 shared/preserved-thinking-migration/drop_block_probe.py --self-test --model <the target model id> --yes
python3 shared/preserved-thinking-migration/drop_block_probe.py --self-test --model <the target model id> --yes --mode error # expect the 400 insteadThe probe always sends the thinking-binding-controls-2026-08-01 beta value; add --beta <value> for any other beta your production requests carry (the bare command is enough on the Claude API). The probe is first-party only: it authenticates against /v1/messages with ANTHROPIC_API_KEY (sent as x-api-key) or ANTHROPIC_AUTH_TOKEN (sent as a bearer token; when both variables are set only the token is sent, because the API rejects a request carrying both headers) and cannot replay captures taken on Amazon Bedrock or Google Cloud Vertex AI - there, run the account's own client and read input_transformations from its responses.
Three short requests (one mint, two replays), billed at the model's normal rates - state the cost and get the user's approval first, as for every run that exercises the model. If the edited replay comes back with no drop (the probe prints NOT WIRED and exits 1), stop: the check is not running for this request (the wrong model id, a platform without the controls, the header missing, the field misspelled, or a gateway or proxy between the harness and the API that drops the anthropic-beta header or the block_binding field - run the self-test through the same path production uses) and every later number would be meaningless. If the honest replay reports a drop, stop too: something in the probe's path is already editing the history - a proxy, an SDK middleware, a serializer - and that is finding number one. Record both responses in the report.
Step 1: Find the edits
Finding the edits has three sources, in order of evidence: the API's own diagnosis (Step 2), the diff of consecutive request bodies, and the code. Do the diff and the code read in this step; they tell you where to look before spending money on replays, and they are what localizes a break to a line of code after the API has named its shape.
1.1 Capture what the harness actually sends
Capture the exact request bodies of a few normal conversations - every request, in send order, JSON as it went over the wire, including the assistant turns with their thinking blocks and signature values exactly as the API returned them. Include one conversation long enough to trigger compaction or truncation, one that connects a plugin or tool mid-session, and one resumed from storage or after a restart, where the product has them. Capture at the HTTP layer where possible (an SDK hook, a logging transport, a proxy) rather than from the application's own message objects - the second kind of capture hides exactly the re-serialization this check catches. If requests pass through a gateway, proxy, or model router on the way to the API, capture them as they leave that layer: a router can rewrite the system prompt, the tools, or the history after your code has built the request. Store one conversation per .jsonl file, one request body per line. Ten to thirty conversations are enough; they are also Step 2's test slice.
Capture the request body and the anthropic-beta header only - never x-api-key or Authorization; an MCP server's authorization_token in the body is sent as the harness sent it (the connector's tools are part of what the check compares), so capture with a test-scoped token and rotate it afterwards. The probe reads nothing else and warns when a capture carries a credential.
Handling captures. A capture is the conversation as the end users had it, and it cannot be redacted without breaking the measurement (the check compares the bytes). Keep captures outside the repository (or ignored by version control), never commit them or an eval set derived from them, run the scripts on a machine that may hold that data, and delete them when the work is done. The probe's --json output is safe to share - it holds request ids, statuses, entries, headers, digests, token counts and file names, no message content; error text for the conversation check's own 400s is stored as a reconstruction of their fixed form (the block path, the fixed clause, and the first-changed-message diagnostic - never the server line itself), and every other error is reduced to its type and field path because API validation messages can echo request values (the full text still prints on the terminal); prefix_diff.py's output is not, because its attribution lines quote excerpts of the changed content.
If the application cannot capture bodies yet, adding that capture is itself the first diff of this workflow: it is the measurement channel for everything after it.
1.2 Diff consecutive pairs
python3 shared/preserved-thinking-migration/prefix_diff.py captures/conversation-0001.jsonlFor each pair of consecutive requests the script reports MATCH, MISMATCH with a verdict in the API's vocabulary - kind=system_changed; pattern=system_rerendered; sections=system; changed_validated=system.0 - and an attribution line that names the site and the first changed character:
system[0] changed at char 53: "... Be concise." -> "... Be concise. Current time: 2026-09-02T15:04:05Z."
tools: lookup_order description changed at char 23: "...order by id." -> "...order by id. Today is 2026-09-02."
messages[2] (user) content[1] (text) removed: {"text":"<reminder>Answer in one sentenc...
messages[1..2] removed (assistant, user)Two lines matter as much as the verdict. replayed thinking blocks in the later request: N - when N is 0 the pair proves nothing about preserved thinking (there was no block to check), which is common for the first pair of every conversation and for harnesses that strip thinking; and the ! chain line (printed as CHAIN-BREAK, counted in the exit status), which is a break, not a warning - it fires when the already-sent turns come back with their thinking blocks changed in a way the API rejects: the kept blocks must be a contiguous window of the original sequence (dropping from the front, from the back, or both is fine), so a block removed from the middle, or a reorder, fails the block after the gap even though the rest of the prefix is untouched.
The comparison ignores what the API ignores: cache_control markers, string content versus a single text block, leading and trailing whitespace of a text block, whitespace-only text blocks, key order, the order of tools in the array (they are compared as a name-keyed set), a defer_loading tool that no tool result, tool-search result, or tool_addition has named yet, request parameters outside system / tools / messages, everything before the last server-side compaction block (the check restarts there; the diff says when it compared from one), and the thinking blocks themselves. Interior whitespace, tool_use.input bytes, tool-result text, image bytes, and everything else count. Treat the script's pattern as a guess in the API's words - the API's own header in Step 2 is the authority when the two differ.
1.3 Read the code
python3 shared/preserved-thinking-migration/prefix_diff.py --scan path/to/repoThe scan prints file:line leads grouped by cause - timestamps and environment reads inside prompt builders, slicing of the messages array, tool lists mutated after session start, the opening message rebuilt from state, tool results trimmed after the fact, reminder tags stripped with a regex, thinking blocks filtered out, round trips through the app's own message model, media caps and URL re-signing. They are regex leads, not findings: read each one, and confirm it with the pair diff or the API's response before it goes in the report. The scan is optional; the checklist below is not. An application can always express an edit in words the patterns do not know, so a scan with no leads is not proof of compliance, and a scan with leads is a reading list - the pair diff is the instrument.
Whatever the scan finds, read these by hand - this checklist is the mandatory part of Step 1.3; they are where the edits hide:
- Prompt assembly: is anything in
systemor in the first user message computed per request - date or time, working directory, account or user line, git status, memory or instruction files re-read from disk, feature flags, model or client version strings, a token or turn counter? - Tool declaration: is
toolsbuilt from live state (connected MCP servers, plugins, permissions, a feature flag) so that it can differ between request 1 and request 2? Are descriptions or schemas rendered with anything dynamic? - History management: any path that shortens, summarizes, reorders, or rewrites messages already sent - sliding windows, keep-last-N, client-side summaries, "micro-compaction" of old tool results, media caps, context-length recovery after an error - and whether any turns are replayed verbatim after a summary (that decides which recipe applies - Step 3's, or the betas section of
shared/preserved-thinking-migration/causes.md). - Injection: anything appended to a user turn for one request only (reminders, status lines, token counts) and removed or rebuilt on the next.
- Modes: does entering a mode (plan, read-only) swap the tool list or the system prompt in place? Withdraw and re-offer tools with
tool_removal/tool_addition, and deliver the mode's instructions as an appended message. - Tools listed in the prompt: are the callable tools named in the system prompt, behind one generic dispatcher tool? Then adding or removing one is a system prompt edit: keep the prompt fixed and announce each change in an appended message ("You can now call X").
- Persistence and resume: does the conversation round-trip through a database or an ORM, and does the replay rebuild messages from those objects rather than from the stored wire JSON? Does a restart, a resume, a deploy, or a new template version re-render the system prompt or the opening message?
- Thinking handling: does any code filter
thinking/redacted_thinkingblocks (a serializer that skips a block with emptythinkingtext counts: the text is empty by default and thesignaturecarries the reasoning), reorder them, store their text truncated or re-wrapped (a modified thinking block is its own 400), or retry a 400 by stripping them without recording that it did? - Sessions: can a thinking block from one conversation be replayed under another (shared session keys, multiplexed users)?
1.4 Name each edit and decide whether it is deliberate
For every pair-diff verdict and every confirmed lead, record: the cause in the API's words (the pattern), the site in the code, which traffic class it is on, and whether the edit is deliberate (a compaction the product relies on; a user-invoked reset that starts a new conversation) or accidental (a timestamp nobody needed in the system prompt; a plugin landing inline on request 2). Accidental edits are removed outright in Step 3. Deliberate ones are replaced by their append-only form, or - where none exists yet - measured and decided (Step 2's caveats, Step 3's last section). The table under "Cause -> detection -> fix" in shared/preserved-thinking-migration/causes.md is the lookup for both: Read that file now if you have not yet, and check every candidate against its "Keep list" before it goes in the report.
Step 2: Measure with drop_block on a test slice
The API's response is the only ground truth. The client-side diff can miss what it cannot see (media bytes behind a URL, an edit in a part of the request the capture didn't include) and can flag what the API tolerates; the response cannot.
2.1 The request shape
Every request in the test slice carries the beta header and sets the behavior explicitly - this is what turns the check on for an organization that is not enforced by default, and it is what adds the report to the response:
POST /v1/messages
anthropic-beta: thinking-binding-controls-2026-08-01
{"model": "<the target model>", "max_tokens": 4096,
"thinking": {"type": "adaptive", "block_binding": {"prefix_mismatch_behavior": "drop_block"}},
"system": ..., "tools": [...],
"messages": [ ...the full history with thinking blocks replayed verbatim... ]}Rules that save a debugging hour:
- The field without the header is, today, a 400 ending in
block_binding: Extra inputs are not permitted. That is a different 400 from the one an enforced account gets when it replays an edited history without the header, whose text says the block is "bound to a different conversation" and ends by naming the beta value the setting requires; you will meet both, and only the second one means the check ran. The header without the field does not turn enforcement on for an organization that is not enforced yet: no block is dropped and nothing fails. The API records the check instead and lists each block that would have failed as athinking_mismatch_allowedentry (2.2) - the zero-risk way to find edits in production traffic. To measure what enforcement costs, set the field; it is the per-request opt-in. prefix_mismatch_behaviortakes"error"or"drop_block". Write exactly that field name; the probe removes any other key it finds underblock_bindingand says which.- The object is accepted, under the header, on every model that accepts
thinking, so one request body works before and after a model switch, provided the thinking configuration is one every model in the route accepts (enabledis a 400 on Claude Fable 5.1; Claude Sonnet 5.5's"between_tools"rejectsblock_binding, so the probe replays it asadaptive); on a model without preserved thinking it is a no-op that still reports model-check drops. - Keep everything else in the request exactly as production sends it. The probe touches only fields outside the compared prefix and prints each change: the header, this field,
max_tokens(capped, see 2.3),stream(off unless asked),tool_choice(set tonone, see 2.3), and the thinking configuration - a request with nothinkingconfiguration is given{"type": "adaptive"}(on Claude Fable 5.1 that is what a request without the key already runs with),enabledis rewritten toadaptive,temperaturebecomes 1 andtop_p/top_kare removed; none of those changes the verdict. Thinking disabled is skipped.system,toolsandmessagesgo out exactly as captured.
2.2 What the response tells you
Detect drops from the request diff. prefix_diff.py over consecutive requests (Step 1.2) is the detector: it reads only what your harness sent, so it works whatever shape the response takes. The surfaces below confirm and explain what it finds.
Three surfaces, in order of reliability:
The text continues at the source. Read the rest.
Source and license
Author: anthropics, Anthropic skills. License: Apache-2.0.
Shown here with formatting for the web. Keep the author and license notice when you reuse it.
Related entries
- Model Migration Guide (shared) (Anthropic skills)
- cs-reflect (reflect) (Alireza Rezvani skills and agents) (productivity) (4357)
- reflect (productivity) (Alireza Rezvani skills and agents) (4359)
- Hill-Climbing on an Eval
- Model Migration Guide (shared) (Claude Code templates (davila7))
- /cs-interview-mapper - Transcript coding + reliability council + insight synthesis
There are more like this in the members library
The Claude Code library holds 13,843 entries. Members can search all of them by meaning and read every one in full.