跳至主要內容

Claude Code 的 Extended Thinking:釋放深度推理能力

掌握 Claude Code 的 Extended Thinking:了解現行模型的 adaptive reasoning 如何運作、effort 等級如何引導它、何時使用 ultrathink,以及如何運用深度推理處理複雜的開發任務。

2026 年 11 月 4 日更新: ultrathink 現在可將該回合提升到 xhigh effort(Claude Code v2.1.311 起),詳見下方「單一回合:ultrathink」一節與 effort 等級指南。

2026 年 10 月 21 日更新: 本文已依 Claude Code 2.1.305 改寫:現行模型使用由 effort 等級引導的 adaptive reasoning(自適應推理),Opus 5.5、Sonnet 5.5、Haiku 5.5 與 Fable 模型都無法關閉思考,ultrathink 可針對單一回合要求更深入的推理,設定範例也已改用真實存在的設定鍵。

Extended Thinking(也稱為「Thinking Mode」)是 Claude 在回應之前所做的推理。這就像給開發者時間在寫程式碼之前先思考架構一樣。在現行模型上,它是自適應的:Claude 在每一步自行決定要不要思考、思考多少,而 effort 等級決定它多願意思考。

本指南涵蓋現行模型上的思考如何運作、如何引導它,以及發揮最大效果的模式。

什麼是 Extended Thinking?

Extended Thinking 讓 Claude 能夠:

  • 更長時間地深思熟慮再回應
  • 考慮多種方法來解決問題
  • 系統性地推理邊界情況
  • 徹底規劃多步驟實作
┌─────────────────────────────────────────────────────────────┐
│                    Normal vs Extended Thinking              │
│                                                             │
│  Normal:                                                    │
│  ┌────────┐      ┌────────┐                                │
│  │ Prompt │  ──► │Response│                                │
│  └────────┘      └────────┘                                │
│                                                             │
│  Extended Thinking:                                         │
│  ┌────────┐   ┌─────────────────┐   ┌────────┐            │
│  │ Prompt │ ► │ Internal Reason │ ► │Response│            │
│  └────────┘   │ (collapsed)     │   └────────┘            │
│               └─────────────────┘                          │
│                     ▲                                       │
│                     │                                       │
│              Longer, deeper                                 │
│              deliberation                                   │
└─────────────────────────────────────────────────────────────┘

Adaptive reasoning:需要時才思考

Claude Code 的文件是這樣描述的:「Adaptive reasoning 讓每一步的思考都變成可選的,因此 Claude 能更快回應例行的 prompt,把更深入的思考留給真正受益的步驟。」Fable 模型、Sonnet 5 及之後的模型、Haiku 5.5,以及 Opus 4.7 及之後的模型一律使用 adaptive reasoning;在這些模型上,effort 等級是控制思考量的主要手段。你仍然可以在 prompt 或 CLAUDE.md 中要求多想或少想,模型會在其 effort 設定的範圍內回應這類指引。

模型支援

在 Claude Code 2.1.305 中:

模型思考方式能否關閉思考?Effort 等級預設 effort
Fable 5.1、Fable 5Adaptive reasoning否low–maxhigh
Opus 5.5、Sonnet 5.5、Haiku 5.5Adaptive reasoning否low–maxmedium
Opus 5、Sonnet 5、Opus 4.8Adaptive reasoning是low–maxhigh
Opus 4.7Adaptive reasoning是low–maxxhigh
Opus 4.6、Sonnet 4.6預設為 adaptive;可用 CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1 改為固定預算是low、medium、high、maxhigh
Haiku 4.5以固定 token 預算思考是不支援 effort—

low–max 代表全部五個等級:low、medium、high、xhigh 與 max。Haiku 4.5 仍然重要,因為在 Claude Platform on AWS、Amazon Bedrock、Google Cloud’s Agent Platform 與 Microsoft Foundry 上,haiku 仍解析為它。

關鍵洞察: 在目前的模型陣容中,你決定的不是 Claude 要不要思考,而是用 effort 等級決定思考多少。

開啟與關閉思考

所有支援思考的模型預設都會開啟思考。以下控制方式只會在允許關閉的模型上生效;在 Opus 5.5、Sonnet 5.5、Haiku 5.5 與 Fable 模型上,它們會顯示 Thinking can't be turned off 或沒有作用。

透過 Config

在 /config 中切換思考模式。Claude Code 會把這個選擇存成 ~/.claude/settings.json 中的 alwaysThinkingEnabled。

透過 Settings

{
  "showThinkingSummaries": true
}

Claude Code 預設會收合思考輸出,而在 Anthropic API 上的互動式 session 會收到經過遮蔽的思考區塊。如果你希望用 Ctrl+O 展開思考時能看到完整摘要,請設定 showThinkingSummaries: true。要在允許關閉的模型上讓每個 session 都關閉思考,請設定 "alwaysThinkingEnabled": false;設成 true 不會改變任何事,因為思考本來就是開啟的。所有產生的思考 token 都會計費,即使它們被收合或遮蔽也一樣。

每個工作階段

按 Option+T(macOS)或 Alt+T(Windows/Linux)可切換目前工作階段的思考。這對 Opus 5.5、Sonnet 5.5、Haiku 5.5 與 Fable 模型沒有作用,因為它們一律會思考。

單一回合:ultrathink

在 prompt 的任何位置加入 ultrathink,就能在不改變工作階段 effort 設定的情況下,要求那一回合進行更深入的推理:

"ultrathink: why does this cache invalidation race only show up under load?"

Claude Code 會辨識這個關鍵字並加入一段情境內指示。從 v2.1.311 起,在終端機的 prompt 中輸入它,還能透過 Anthropic API 將該回合提升到 xhigh effort(適用於 Opus 5.5、Sonnet 5.5、Haiku 5.5 與 Fable 5.1);可以提升時,這個字會以彩虹色顯示。在無法提升的情況下(例如 Amazon Bedrock),請改為設定 effort 等級。無論哪種情況,你儲存的 effort 設定都不會改變;v2.1.316 的 changelog 另新增 CLAUDE_CODE_DISABLE_ULTRATHINK,可關閉這個關鍵字。其他說法例如「think」、「think hard」和「think more」都只會被當成一般的 prompt 文字傳遞,不會被辨識為關鍵字。

透過環境變數

MAX_THINKING_TOKENS 的行為依模型而異:

  • 0 會在 Anthropic API 上關閉思考,但 Opus 5.5、Sonnet 5.5、Haiku 5.5 與 Fable 模型除外,它們無法關閉思考。在第三方 provider 上,0 則是省略 thinking 參數,因此 adaptive reasoning 模型仍可能思考。
  • 正數代表固定的思考預算。在 adaptive reasoning 模型上,Claude Code 會忽略這個數字,除非你用 CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1 把 Opus 4.6 或 Sonnet 4.6 切回固定預算。預算上限是請求最大輸出 token 數減一,且不會低於 1,024。

在 Anthropic API 上關閉思考時,對於不接受這種組合的模型(例如 Opus 5),Claude Code 會改送 high effort,而不是更高的等級。

快速切換模型

按 Option+P(macOS)或 Alt+P(Windows/Linux)可以在不清除 prompt 的情況下切換模型。在 macOS 上,這個快捷鍵需要在終端機中把 Option 設定為 Meta。

Effort 等級

在 adaptive reasoning 模型上,effort 等級就是你控制思考深度的方式。使用 /effort 設定整個工作階段的等級,必要時也可針對個別 subagent 覆寫:

Effort思考量使用情境
low最少快速任務、改名、你會逐一審查的批次操作
medium平衡Opus 5.5、Sonnet 5.5 與 Haiku 5.5 的預設;範圍明確的日常工作
high深入在既有程式碼中修 bug、複雜分析;包括 Fable 5.1 在內大多數其他模型的預設
xhigh更深入架構決策與最困難的判斷工作
max最深入希望 Claude 自行解決的難題;容易想太多,請先測試

並非每個模型都支援所有等級:Opus 4.6 與 Sonnet 4.6 沒有 xhigh,而 Haiku 4.5 未列為支援 effort 的模型。完整的對照表,以及儲存與限制 effort 的設定,請見 Ultracode 與 Effort 等級。

設定 Effort

在 prompt 裡寫「with high effort」並不會改變 effort 等級,那只是模型在目前設定範圍內參考的指引。要改變等級本身:

/effort high      # set the level and save it as this model's default
/effort           # open the slider: Enter saves, s applies to this session only
/effort status    # show the level in effect
claude --effort xhigh                   # one session, set at launch
CLAUDE_CODE_EFFORT_LEVEL=high claude    # environment variable; overrides --effort and /effort

若要設定 subagent,可以在其定義的 frontmatter 中設定 effort,或讓 Claude 傳入 Agent 工具的 effort 參數(v2.1.292+)。當你請 Claude 把分析工作交給一個使用 Opus、high effort 的 general-purpose subagent 時,呼叫會長這樣(Agent 工具以前叫 Task,Task 這個名稱仍可作為別名使用):

Agent({
  description: "Analyze payment architecture",
  subagent_type: "general-purpose",
  model: "opus",
  effort: "high",
  prompt: `
    Analyze the payment integration architecture.
    Consider all edge cases and failure modes.
  `
})

何時使用 Extended Thinking

架構決策

快速過一遍,使用工作階段的預設 effort:

"How should we structure our microservices?"

Claude: [Quick response, may miss considerations]

深入分析,使用 ultrathink(或先執行 /effort high):

"ultrathink

How should we structure our microservices?
Consider: scalability, team structure, data ownership,
deployment complexity, and failure isolation."

Claude: [Thorough analysis of trade-offs]

安全審查

prompt 本身無法切換模型或 effort,所以要先做這兩件事:

/model opus
/effort high

"Review the authentication implementation for vulnerabilities.

Consider: OWASP Top 10, JWT best practices, session
management, rate limiting, and common attack vectors."

複雜重構

"Think through how to refactor the legacy payment system
to the new architecture. Consider:

- Backward compatibility
- Database migrations
- API versioning
- Rollback strategy
- Testing approach"

除錯複雜問題

"This bug only happens in production with high concurrency.
ultrathink about potential causes.

Symptoms: [describe symptoms]
Environment: [describe environment]
Recent changes: [describe changes]"

Extended Thinking 模式

像「think deeply」這類說法,是模型在其 effort 等級範圍內參考的指引;ultrathink 是唯一會被辨識的關鍵字,而 /effort 才會改變等級本身。

模式 1:架構審查

"I need to design a new feature. ultrathink.

Feature: Real-time notifications
Requirements:
- Support 100K concurrent users
- < 100ms delivery latency
- Support mobile and web
- Handle offline users

Analyze options and recommend architecture."

模式 2:權衡分析

"Think deeply about this trade-off.

Option A: Monolith with modular structure
Option B: Microservices from start

Context:
- 3-person team
- MVP stage
- Unknown scale requirements
- Limited DevOps experience

Analyze both options with pros, cons, and recommendation."

模式 3:安全審計

這個模式請在 /effort high 或更高的等級下執行:

"Perform a deep security audit.

Focus areas:
- Authentication and authorization
- Input validation
- Data encryption
- API security
- Dependency vulnerabilities

For each issue found, provide:
- Severity (Critical/High/Medium/Low)
- Description
- Remediation steps
- Code examples"

模式 4:效能調查

"The API is slow under load. Think through potential causes.

Observations:
- Response time increases from 50ms to 2s at 500 RPS
- CPU stays at 30%, memory at 60%
- Database connections spike
- No errors in logs

Analyze potential bottlenecks and suggest investigation steps."

對成本與快取的影響

重要: 思考會消耗 token,而在工作階段中途更換模型或 effort,可能讓你失去 prompt cache。

┌─────────────────────────────────────────────────────────────┐
│              What Thinking Costs You                        │
│                                                             │
│  Tokens:                                                    │
│  ├── Every thinking token is billed, even when collapsed    │
│  └── Higher effort -> more thinking -> more tokens          │
│                                                             │
│  Prompt cache:                                              │
│  ├── Switching models starts a fresh cache                  │
│  ├── Changing effort resets it on most models               │
│  └── Opus 5.5, Sonnet 5.5, Haiku 5.5 and Fable 5.1 keep it  │
│      (with an API key or a Claude subscription)             │
└─────────────────────────────────────────────────────────────┘

在變更 effort 會重置快取的模型上,Claude Code 會在快取仍有效時請你確認。

建議: 在工作階段一開始就選好模型與 effort 等級,並把更深入的推理留給高價值的決策,而非日常任務。

模型選擇指南

使用 Haiku 5.5(夠用的最低 effort)

Best for:
- File searches and exploration subagents
- Pattern matching
- Simple code generation
- Bulk operations

Thinking is adaptive and always on; keep effort
low for mechanical work.

Example:
"Find all uses of deprecated API in the codebase"

在 Bedrock、Agent Platform、Foundry 與 Claude Platform on AWS 上,haiku 仍代表 Haiku 4.5,它以固定預算思考,也不接受 effort 設定。

使用 Sonnet 5.5(預設 medium)

Best at medium effort:
- Standard implementations
- Code refactoring
- Test writing
- Documentation

Raise to high for:
- Complex implementations
- Multi-file refactoring
- Architecture-sensitive changes

Example:
"Implement the user authentication system following
our security patterns. ultrathink about the token
refresh mechanism design."

使用 Opus 5.5 / Fable 5.1(最深度推理)

Best for:
- Architecture decisions
- Security audits
- Complex debugging
- Critical code paths

Opus 5.5 defaults to medium; raise it to high or
xhigh for this work. Fable 5.1 defaults to high.

Example:
"Review the payment processing implementation,
especially the transaction handling logic."

Agents 中的 Thinking Mode

自 v2.1.198 起,subagent 會繼承主對話的思考設定:如果你的工作階段開啟了思考,subagent 也會開啟。沒有針對個別 subagent 的思考開關,所以請改用每個 subagent 的模型與 effort 來引導思考深度。

Explore Agent(Haiku)

內建的 Explore agent 會使用主對話的模型(當主模型是 Fable,且你以訂閱方案或 Console 帳號登入時,它會改用 opus 模型)。要讓探索保持便宜,請自己定義一個名為 Explore、設定 model: haiku 的 subagent,或請 Claude 用 Haiku 執行搜尋:

Agent({
  description: "Find auth patterns",
  subagent_type: "Explore",
  model: "haiku",
  prompt: "Find authentication patterns (thoroughness: medium)"
})

不需要額外的 effort — 純粹的搜尋和發現。

Implementation Agent(Sonnet + High Effort)

對於複雜實作,提高 subagent 的 effort:

Agent({
  description: "Implement OAuth with PKCE",
  subagent_type: "general-purpose",
  model: "sonnet",
  effort: "high",
  prompt: `
    Implement OAuth 2.0 with PKCE flow.
    Consider:
    - State management
    - Token storage
    - Refresh handling
    - Error recovery
  `
})

Review Agent(Opus + xhigh Effort)

對於關鍵審查,使用 Opus 搭配 xhigh effort:

Agent({
  description: "Security review payments",
  subagent_type: "general-purpose",
  model: "opus",
  effort: "xhigh",
  prompt: `
    Security review the payment integration.
    Check for:
    - PCI compliance issues
    - Data exposure risks
    - Authentication bypasses
    - Rate limiting gaps
  `
})

經常執行的審查,可以把 model: opus 與 effort: xhigh 寫進自訂 subagent 的 frontmatter,讓每次呼叫都套用。

實際範例

範例 1:功能設計

"I need to add collaborative editing to our document app.

ultrathink.

Constraints:
- Real-time sync (< 100ms)
- Handle offline mode
- Conflict resolution
- Undo/redo support

Analyze:
1. Technology options (CRDT, OT, etc.)
2. Architecture approach
3. Trade-offs of each option
4. Recommended path forward"

範例 2:遷移規劃

/model opus
/effort high

"We're migrating from MongoDB to PostgreSQL.
Create a migration plan.

Current state:
- 50 collections
- 10M documents
- 5 services depending on data
- Zero downtime requirement

Deliverables:
1. Migration strategy
2. Schema design
3. Service update plan
4. Rollback strategy
5. Testing approach
6. Timeline estimate"

範例 3:除錯工作階段

"Production issue: Intermittent 500 errors on /api/checkout.

Think through this carefully.

Data points:
- Happens ~1% of requests
- No pattern in time of day
- No correlation with request size
- Started after last deploy
- Logs show: 'Connection reset by peer'

Analyze potential causes and investigation steps."

範例 4:程式碼審查

"ultrathink: review this PR.

PR adds: Payment processing with Stripe

Focus areas:
- Error handling completeness
- Idempotency of operations
- State machine correctness
- Webhook handling security
- Test coverage adequacy

Provide detailed feedback with specific line references."

Thinking Mode 設定

專案層級

思考預設就是開啟的,不需要專案設定;你要設定的是 effort。在 .claude/settings.json 中:

{
  "model": "sonnet",
  "modelSettings": {
    "claude-opus-5-5": { "effortLevel": "high" }
  },
  "maxEffortLevel": "xhigh"
}

modelSettings 讓每個模型有自己的 effort 等級(這裡是有人切換到 Opus 5.5 時以 high 執行),maxEffortLevel 則把所有模型的上限設為 xhigh。頂層的 effortLevel(low、medium、high 或 xhigh)會為這個專案中的所有模型設定同一個預設值。

每個任務的觸發條件

Claude Code 沒有 thinkingConfig 或 thinkingTriggers 這類設定。以下三個真實機制可以滿足同樣的需求:

  • 在 prompt 中使用 ultrathink,只影響單一回合。
  • 在 skill 或 subagent 的 frontmatter 中設定 effort,讓總是需要深度的工作總是得到它。
  • 用 maxEffortLevel 讓最昂貴的等級無法被選用。

例如,一個總是以 xhigh 執行的安全審查 skill:

---
name: security-review
description: Deep security review of the current diff
effort: xhigh
---

Review the diff for authentication, authorization, and input-validation issues.
Report each finding with a severity and a file and line reference.

成本效益分析

何時 Extended Thinking 值得

情境建議 effort品質提升ROI
架構決策high–xhigh避免數月的返工非常高
安全審查high–max捕捉漏洞非常高
複雜重構high更好的設計高
Bug 調查high更快找到根因高
日常編碼模型預設邊際改善低

何時跳過

以下情況維持模型預設或更低的 effort:

  • 檔案搜尋
  • 模式匹配
  • 簡單的程式碼變更
  • 文件更新
  • 常規測試

最佳實踐

1. 明確說明需要的深度

"ultrathink: analyze this code for security issues."

而不是:

"Analyze this code."

2. 提供豐富的上下文

深度推理在有上下文時效果更好:

"ultrathink: design the caching layer.

Context:
- Current: No caching, 200ms average response
- Goal: <50ms for 80% of requests
- Constraints: Redis available, 5GB memory budget
- Traffic: 10K RPM, 80% reads

Consider cache invalidation, TTL strategies, and
cache stampede prevention."

3. 要求結構化輸出

"Think through this architecture decision.

Output format:
1. Options considered (3-5)
2. Evaluation criteria
3. Analysis matrix
4. Recommendation with rationale
5. Risk assessment"

4. 與 Agents 結合

把 effort 花在協調上,把速度用在執行上:

"Phase 1 (Opus 5.5, xhigh effort): Design the migration strategy
Phase 2 (Sonnet 5.5, medium effort): Implement each migration step
Phase 3 (Haiku 5.5, low effort): Run tests in parallel"

監控思考使用量

檢查 Effort 與 Context

工作階段標題會在模型名稱旁顯示目前的 effort(例如「with low effort」),/effort status 會印出它,/context 則顯示是什麼佔據了上下文視窗。自訂狀態列會以 JSON 收到模型、effort 等級、思考狀態與 context 使用量,所以你可以讓它們一直顯示在畫面上:

{
  "statusLine": {
    "type": "command",
    "command": "jq -r '\"[\\(.model.display_name)] \\(.effort.level // \"-\") effort | \\(.context_window.used_percentage // 0)% context\"'"
  }
}

根據工作階段調整

在 5.5 家族與 Fable 模型上無法關閉思考,所以遇到一長串例行的檔案更新時,改為降低 effort:打開 /effort,選擇 low,再按 s 只套用到這個工作階段。直接輸入 /effort low 則會同時把它存成該模型的預設值。

開始使用

今天:

  1. 用預設 effort 問一個架構問題,再加上 ultrathink 問一次
  2. 比較輸出品質
  3. 在 /usage 中記錄時間與 token 的差異

本週:

  1. 為你的專案選定預設模型與各模型的 effort
  2. 識別受益於更高 effort 的任務
  3. 建立能為深度推理提供豐富上下文的提示

本月:

  1. 為團隊建立 effort 使用指南
  2. 在需要深度的 skill 與 subagent 的 frontmatter 中加入 effort
  3. 衡量對決策品質的影響

Extended Thinking 將 Claude 從快速回應者轉變為深思熟慮的夥伴。把 effort 策略性地花在重要的決策上,你會看到架構決策品質顯著提升。

來源:Claude Code model configuration、Claude Code CHANGELOG