跳至主要內容
精選 Extended Thinking Opus Sonnet Advanced

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

掌握 Claude Code 的 Extended Thinking。學習何時啟用思考模式、如何使用 effort 等級,以及如何運用深度推理來處理複雜的開發任務。

2026年1月10日 17 分鐘閱讀 作者:ClaudeWorld

Extended Thinking(也稱為「Thinking Mode」)讓 Claude 有更多時間在回應之前深入思考複雜問題。這就像給開發者時間在寫程式碼之前先思考架構一樣。

本指南涵蓋何時使用 Extended Thinking、如何設定它,以及最大化效果的模式。

什麼是 Extended Thinking?

Extended Thinking 讓 Claude 能夠:

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

模型支援

模型Extended Thinking預設備註
Opus 4.5開啟(v2.0.67+)最高品質推理
Sonnet 4.5關閉為複雜任務啟用
Haiku 4.5關閉首個支援思考的 Haiku

關鍵洞察: Opus 4.5 從 v2.0.67 起預設啟用思考功能,因為它能顯著提升品質。

啟用 Extended Thinking

透過 Config

/config 中,啟用思考模式:

Thinking Mode: ON

透過 Settings

.claude/settings.json 中:

{
  "model": "opus",
  "thinking": true
}

每個工作階段

在工作階段中切換:

"Enable thinking mode for this complex architecture discussion."

快速切換模型

在輸入提示時按 Option+P(macOS)或 Alt+P(Windows/Linux)快速切換模型。

Effort 等級(僅 Opus 4.5)

Opus 4.5 支援 effort 等級 來控制思考深度:

Effort思考時間使用情境
low最少快速任務、批次操作
medium平衡預設,大多數任務
high最多複雜分析、架構設計

設定 Effort

在提示中:

"Analyze this authentication system with high effort.
I need thorough security analysis."

在 Task tool 中:

Task({
  subagent_type: "general-purpose",
  model: "opus",
  prompt: `
    Effort: high

    Analyze the payment integration architecture.
    Consider all edge cases and failure modes.
  `
})

何時使用 Extended Thinking

架構決策

沒有思考:

"How should we structure our microservices?"

Claude: [Quick response, may miss considerations]

有思考:

"Enable high-effort thinking.

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

Claude: [Thorough analysis of trade-offs]

安全審查

"Using Opus with high effort, 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.
Use extended thinking to analyze potential causes.

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

Extended Thinking 模式

模式 1:架構審查

"I need to design a new feature. Use extended thinking.

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:安全審計

"Perform a deep security audit with high effort.

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."

對 Context 的影響

重要: Extended Thinking 會影響 prompt caching 效率。

┌─────────────────────────────────────────────────────────────┐
│              Context Usage Comparison                        │
│                                                             │
│  Normal Mode:                                                │
│  ├── Prompt Cache: Highly effective                        │
│  ├── Context usage: Predictable                            │
│  └── Token efficiency: High                                 │
│                                                             │
│  Extended Thinking:                                          │
│  ├── Prompt Cache: Less effective                          │
│  ├── Context usage: Variable (thinking uses tokens)        │
│  └── Token efficiency: Lower (but higher quality)          │
│                                                             │
└─────────────────────────────────────────────────────────────┘

建議: 選擇性地為高價值決策使用 extended thinking,而非日常任務。

模型選擇指南

使用 Haiku 4.5(無思考)

Best for:
- File searches (Explore agent)
- Pattern matching (Grep)
- Simple code generation
- Bulk operations

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

使用 Sonnet 4.5(思考可選)

Best for (without thinking):
- Standard implementations
- Code refactoring
- Test writing
- Documentation

Best for (with thinking):
- Complex implementations
- Multi-file refactoring
- Architecture-sensitive changes

Example:
"Implement the user authentication system following
our security patterns. Enable thinking for the token
refresh mechanism design."

使用 Opus 4.5(預設思考)

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

Example:
"Review the payment processing implementation.
Use high effort for the transaction handling logic."

Agents 中的 Thinking Mode

Explore Agent(Haiku)

Explore agents 使用 Haiku 而不啟用思考以提升速度:

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

不需要思考 — 純粹的搜尋和發現。

Implementation Agent(Sonnet + Thinking)

對於複雜實作,啟用思考:

Task({
  subagent_type: "general-purpose",
  model: "sonnet",
  prompt: `
    Enable thinking mode.

    Implement OAuth 2.0 with PKCE flow.
    Consider:
    - State management
    - Token storage
    - Refresh handling
    - Error recovery
  `
})

Review Agent(Opus + High Effort)

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

Task({
  subagent_type: "general-purpose",
  model: "opus",
  prompt: `
    Effort: high

    Security review the payment integration.
    Check for:
    - PCI compliance issues
    - Data exposure risks
    - Authentication bypasses
    - Rate limiting gaps
  `
})

實際範例

範例 1:功能設計

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

Enable extended thinking with high effort.

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:遷移規劃

"We're migrating from MongoDB to PostgreSQL.

Use Opus with high effort to 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:程式碼審查

"Review this PR with extended thinking.

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 設定

專案層級

.claude/settings.json 中:

{
  "model": "sonnet",
  "thinking": false,
  "thinkingConfig": {
    "enableForSecurity": true,
    "enableForArchitecture": true,
    "defaultEffort": "medium"
  }
}

每個任務的觸發條件

設定思考自動啟用:

{
  "thinkingTriggers": {
    "keywords": ["security", "architecture", "design"],
    "paths": ["auth/", "payment/", "admin/"],
    "operations": ["create-file", "refactor"]
  }
}

成本效益分析

何時 Extended Thinking 值得

情境時間成本品質提升ROI
架構決策+30秒避免數月的返工非常高
安全審查+45秒捕捉漏洞非常高
複雜重構+20秒更好的設計
Bug 調查+15秒更快找到根因
日常編碼+10秒邊際改善

何時跳過

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

最佳實踐

1. 明確說明要使用思考

"Enable extended thinking for this security analysis."

而不是:

"Analyze this code."

2. 提供豐富的上下文

Extended thinking 在有上下文時效果更好:

"Using high-effort thinking, 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 結合

使用思考來進行協調,使用速度來執行:

"Phase 1 (Opus, high effort): Design the migration strategy
Phase 2 (Sonnet, no thinking): Implement each migration step
Phase 3 (Haiku, no thinking): Run tests in parallel"

監控思考使用量

檢查 Context 使用量

狀態列(v2.0.65+)顯示 context 使用量:

Context: 45% used | Thinking: enabled | Model: opus

根據工作階段調整

對於長時間工作階段,考慮在日常任務中停用思考以保留 context:

"Disable thinking for these routine file updates."

開始使用

今天:

  1. 為一個架構決策啟用思考
  2. 比較有無思考的輸出品質
  3. 記錄時間差異

本週:

  1. 為你的專案設定模型選擇
  2. 識別受益於思考的任務
  3. 建立能運用深度推理的提示

本月:

  1. 為團隊建立思考模式指南
  2. 設定自動啟用觸發條件
  3. 衡量對決策品質的影響

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

來源:Claude Code DocumentationClaude Code CHANGELOG