---
title: 保留思考
url: https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking
description: 在會執行前綴檢查的 Claude 模型上，保留思考決定模型是否能使用您從先前輪次傳回的思考區塊。
featureMetadata:
  status: stable
  supportedModels:
    - claude-fable-5-2
    - claude-mythos-5-2
    - claude-fable-5-1
    - claude-mythos-5-1
    - claude-opus-5-5
    - claude-sonnet-5-5
    - claude-haiku-5-5
  supportedPlatforms:
    Claude API: stable
    Amazon Bedrock: stable
    Amazon Bedrock (bedrock-runtime): stable
    Claude Platform on AWS: stable
    Claude Models on Google Cloud (Anthropic managed): stable
    Claude Models on Google Cloud (Google managed): stable
    Microsoft Foundry: stable
---

當您的程式碼將思考區塊傳回時，Claude 可以在先前輪次的推理基礎上繼續進行。*「Preserved thinking」（保留思考）*&#x6C7A;定它能使用其中哪些區塊。在[具備保留思考的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#outcomes)上，可使用的區塊會留在上下文中，並以輸入計費。請[原封不動地傳回助理輪次](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions#append-assistant-turns-exactly-as-returned)，與 API 傳回時完全相同。

如果請求已因 `The block is bound to a different conversation` 而失敗，請從[修正綁定到不同對話的思考區塊](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/fix-bound-to-a-different-conversation)開始。

## 思考區塊與什麼綁定

在這些模型上，思考區塊與下列項目綁定：

* **它之前的內容：**`system`、`tools` 以及每則較早的訊息。如果其中任何一項變更，該區塊就會無法通過[「prefix check」（前綴檢查）](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#prefix-check)，而請求可能會收到 400 錯誤。因此請只在對話中新增內容（請參閱[變更工具或指示而不使前綴檢查失敗](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions)）。
* **模型：**&#x6A21;型只會讀取部分其他模型的思考區塊（請參閱[在 Claude API 上哪些模型切換會保留推理](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#which-model-switches-keep-reasoning)）。
* **帳戶：**&#x4F86;自部分模型的區塊會綁定到帳戶（請參閱[帳戶與雲端平台](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#account-bound-thinking)）。

[`prefix_mismatch_behavior`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#preserved-thinking-controls) 決定無法通過前綴檢查的請求會收到 400 錯誤，還是由 API 捨棄無法通過前綴檢查的區塊。回應的 [`input_transformations`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/fix-bound-to-a-different-conversation#input-transformations) 會列出 API 捨棄或放行的思考區塊。捨棄思考會有代價（請參閱[捨棄思考的代價](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/fix-bound-to-a-different-conversation#drop-block-cost)）。

## 切換模型再切換回來

變更 `model`，並持續傳送整個對話。新模型或帳戶無法使用的思考區塊永遠不會導致錯誤。API 會在該次請求中將其捨棄且不計費，而 Claude 會在不具備該推理的情況下回答。

在[具備保留思考的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#outcomes)上，[`thinking: {"type": "enabled"}`](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#thinking-type-on-switch) 會導致 400 錯誤，而無法通過[前綴檢查](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#prefix-check)的請求也可能收到 400 錯誤。

<Frame>
  ![同一份歷史記錄依序傳送到 Claude Fable 5.1、Claude Opus 5.5，再回到 Claude Fable 5.1：其區塊被捨棄一次，之後再次被讀取](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/images/preserved-thinking-switch-and-back.svg)
</Frame>

Claude Opus 5.5 無法讀取 Claude Fable 5.1 的區塊，因此 API 會在它的請求中將其捨棄。回到 Claude Fable 5.1 時，這些區塊會再次被讀取，因為 API 絕不會變更您的 `messages`。切換模型時，只有在您的程式碼移除推理時，推理才會永久遺失。因此請不要移除思考，也不要為每個模型各自保存一份歷史記錄。

被捨棄的區塊不算是對對話的變更，因此兩個模型的區塊都保持有效。

## 非由您的程式碼進行的切換

路由器、[拒絕後的後備](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#after-a-refusal)或伺服器端後備都可能為您切換模型，而且[其他供應商的模型也可能接手一個輪次](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#other-provider-turns)。請持續傳送整個對話。含有 `fallback` 區塊的輪次有其自身的規則。關於應省略哪些區塊，請參閱[延續對話](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#continuing-the-conversation)。

任何切換都可能選到不接受系統訊息的模型。請參閱[當模型不接受系統訊息時](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#unchosen-switches-details)。

## 帳戶與雲端平台

移到另一個帳戶或雲端平台的運作方式相同：請持續傳送完整的歷史記錄。

來自 Claude Fable 5.2、Claude Mythos 5.2、Claude Sonnet 5.5 和 Claude Haiku 5.5 的思考區塊，只能在產生它們的帳戶或已連結的帳戶中使用。在任何其他帳戶中，API 會將其捨棄，且不產生錯誤。

[什麼算是您的帳戶](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#accounts-by-platform)取決於平台。

## 機密與不受信任的文字

請只在 `tool_result` 區塊中傳送[您的使用者不會預期 Claude 信任的檔案](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions#untrusted-text)。當您從歷史記錄中[移除機密、個人資料或注入的文字](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions#remove-sensitive-content)時，也請移除它們首次出現位置之後的每個思考區塊。之後 Claude 會在不具備該推理的情況下運作。

## 讓代理程式檢查您的程式碼

在 Claude Code 中，請執行 `claude update`，然後在建立您請求的儲存庫中執行此提示：

讓 Claude Code 為您檢查程式碼

```text
/claude-api preserved-thinking-migration
```

若使用其他代理程式，請將[變更工具或指示而不使前綴檢查失敗](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions)提供給它，並請它修正您的程式碼在請求之間變更 `system`、`tools` 或較早訊息的每一處。

## 技術細節

### 在 Claude API 上哪些模型切換會保留推理

破折號表示您切換到的模型無法讀取這些區塊。經過多次切換後，請針對歷史記錄中的每個模型各讀取一列。

| 切換前的模型 | 切換到 Claude Fable 5.2 或 Claude Mythos 5.2 | 切換到 Claude Fable 5.1 或 Claude Mythos 5.1 | 切換到 Claude Opus 5.5 | 切換到 Claude Sonnet 5.5 | 切換到 Claude Haiku 5.5 |
| ----- | ----- | ----- | ----- | ----- | ----- |
| Claude Haiku 5.5 | ✅ | — | ✅ | ✅ | ✅ |
| Claude Sonnet 5.5 | ✅ | — | ✅ | ✅ | — |
| Claude Opus 5 | ✅ | ✅ | ✅ | — | — |
| Claude Opus 5.5 | ✅ | ✅ | ✅ | — | — |
| Claude Fable 5 或 Claude Mythos 5 | ✅ | ✅ | — | — | — |
| Claude Fable 5.1 或 Claude Mythos 5.1 | ✅ | ✅ | — | — | — |
| Claude Fable 5.2 或 Claude Mythos 5.2 | ✅ | — | — | — | — |

如果某個模型沒有對應的列或欄，請參閱[較早的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking#earlier-models)。

### 較早的模型，例如 Claude Opus 5 和 Claude Sonnet 5

每個 Claude 模型都會讀取來自 Claude Opus 4.8、Claude Sonnet 5、Claude Haiku 4.5 以及較早的 Claude Opus、Claude Sonnet 和 Claude Haiku 模型的區塊。

| 您切換到的模型 | 僅讀取來自下列模型的區塊 |
| ----- | ----- |
| Claude Opus 4.8、Claude Sonnet 5、Claude Haiku 4.5 以及較早的 Claude Opus、Claude Sonnet 和 Claude Haiku 模型 | 彼此 |
| Claude Opus 5 | 自身，以及第一列中的模型 |
| Claude Fable 5 和 Claude Mythos 5 | 彼此、Claude Mythos Preview、Claude Opus 5，以及第一列中的模型 |

### 新模型上的思考設定

[具備保留思考的模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#outcomes)會以 400 錯誤拒絕 `thinking: {"type": "enabled"}`。當您將對話從請求設定 `"enabled"` 的模型移到其中一個模型時，請改為傳送 `"adaptive"`。在這些模型上省略 `thinking` 同樣會得到「adaptive thinking」（自適應思考）。

### 當模型不接受系統訊息時

如果某個模型不在[接受系統訊息的模型清單](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/mid-conversation-system-messages)上，請只在傳給該模型的請求中省略系統訊息。請在您儲存的歷史記錄中保留它們。回到接受系統訊息的模型時，請再次傳送完整的已儲存歷史記錄。回來時未帶上它們就算是變更，請求可能會收到該 400 錯誤。

### 拒絕之後

[允許的後備模型](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/refusals-and-fallback#naming-your-own-fallback-models)都無法讀取拒絕模型的思考，因此後備模型會在不具備該思考的情況下回答。回到您所要求的模型時，Claude 會讀取兩個模型的思考。

### 來自其他供應商模型的輪次

來自其他供應商模型的輪次會附加在結尾，並以 `text` 和 `tool_use` 內容傳送。Claude 先前的思考保持有效。

### 在各平台上什麼算是您的帳戶

| 您呼叫 Claude 的位置 | 您的帳戶 |
| ----- | ----- |
| Claude API、Claude Platform on AWS、Claude Models on Google Cloud (Anthropic managed) 或 Microsoft Foundry | 您的組織 |
| Amazon Bedrock | 您的 AWS 帳戶 |
| Claude Models on Google Cloud (Google managed) | 您的 Google Cloud 專案 |

如果產生思考區塊的另一個帳戶已不再處於良好狀態，API 也可能省略該區塊。這適用於傳送到 Claude Fable 和 Claude Mythos 模型、Claude Opus 5、Claude Opus 5.5、Claude Sonnet 5.5 以及 Claude Haiku 5.5 的請求。請求仍會成功，而模型會在不具備該區塊推理的情況下回答。

## 可用性

保留思考在特定模型上可供使用。

### API 支援

具備保留思考的模型列於[前綴檢查失敗時各模型的行為](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks#outcomes)。

#### [Messages API](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/working-with-messages)

* 可用性：永遠開啟

| 狀態 | 雲端平台 | 模型 |
| ----- | ----- | ----- |
| 可用 | Claude API, [Claude Platform on AWS](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-platform-on-aws), [Claude Models on Google Cloud (Anthropic managed)](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/anthropic-managed), [Claude Models on Google Cloud (Google managed)](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/google-managed), [Microsoft Foundry](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-in-microsoft-foundry) | [Claude Fable 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-2/overview), [Claude Mythos 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/mythos-5-2/overview), [Claude Fable 5.1](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-1/overview), [Claude Mythos 5.1](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/mythos-5-1/overview), [Claude Opus 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/opus-5-5/overview), [Claude Sonnet 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/sonnet-5-5/overview), [Claude Haiku 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/haiku-5-5/overview) |
| 可用 | [Amazon Bedrock](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-in-amazon-bedrock) | [Claude Fable 5.1](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-1/overview), [Claude Opus 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/opus-5-5/overview), [Claude Sonnet 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/sonnet-5-5/overview), [Claude Haiku 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/haiku-5-5/overview) |
| 可用 | [Amazon Bedrock (bedrock-runtime)](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-on-amazon-bedrock-legacy) | [Claude Fable 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-2/overview), [Claude Mythos 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/mythos-5-2/overview) |

#### [Managed Agents](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/managed-agents/overview)

* 可用性：永遠開啟

| 狀態 | 雲端平台 | 模型 |
| ----- | ----- | ----- |
| 可用 | Claude API, [Claude Platform on AWS](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-platform-on-aws), [Claude Models on Google Cloud (Anthropic managed)](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/claude-models-on-google-cloud/anthropic-managed) | [Claude Fable 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-2/overview), [Claude Mythos 5.2](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/mythos-5-2/overview), [Claude Fable 5.1](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/fable-5-1/overview), [Claude Mythos 5.1](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/mythos-5-1/overview), [Claude Opus 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/opus-5-5/overview), [Claude Sonnet 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/sonnet-5-5/overview), [Claude Haiku 5.5](https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/models/haiku-5-5/overview) |

## 後續步驟

<CardGroup cols={2}>
  <Card title="思考區塊的前綴檢查" icon="shield" href="https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/prefix-checks">
    前綴檢查比較的內容、請求未通過前綴檢查時會發生什麼事，以及如何處理這兩種情況。
  </Card>

  <Card title="變更工具或指示而不使前綴檢查失敗" icon="edit" href="https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/change-tools-or-instructions">
    針對您的程式碼對對話所做的每種變更，應改為傳送什麼。
  </Card>

  <Card title="修正綁定到不同對話的思考區塊" icon="wrench" href="https://code.saschaberens.de/_h/platform.claude.com/docs/zh-TW/build-with-claude/preserved-thinking/fix-bound-to-a-different-conversation">
    恢復失敗的對話，並了解捨棄思考的代價。
  </Card>
</CardGroup>
