跳到主要内容

思考模式与努力级别

定义

扩展思考是 Claude 模型的一项功能,使模型能够在产生最终响应之前在专用的内部草稿区逐步推理问题。与可见输出不同,这个推理过程是为模型的内部深思而设计的——它会浮现中间结论、评估替代方案、发现自己的错误,并构建出经过深思熟虑的答案。结果是复杂任务上更准确的响应、模糊问题上更有条理的推理,以及更少受浅层模式匹配错误影响。

在 Claude Code 中,扩展思考表现为一个努力级别设置,控制模型在回答之前执行多少计算工作。低努力响应速度快,适合简单、无歧义的任务(格式化代码、解释短函数)。高努力响应投入更多推理预算,更适合复杂的架构决策、困难的调试会话,或错误代价高昂的任务。权衡始终是速度与深度之间的取舍:更多思考需要更多时间并消耗更多 token。

重要的是要区分扩展思考与思维链提示。思维链要求模型在输出中展示其工作——推理是响应文本的一部分。扩展思考,相比之下,发生在模型内部处理的单独 thinking 块中。在 Claude Code 会话中,你有时可以在原始 API 输出中观察到 <thinking> 块,尽管 Claude Code 的界面通常只显示最终响应。内部思考不受与输出相同的约束,并且针对推理质量而非可读性进行了优化。

工作原理

思考块和预算 token

当扩展思考启用时,模型会收到一个额外参数:budget_tokens。这个整数指定模型在产生最终响应之前用于内部推理的最大 token 数量。1,000 token 的预算允许简短的深思;10,000 token 的预算允许深入的多步骤分析。模型不总是使用其全部预算——当达到满意的结论时它会停止思考。将预算设置得过高会增加延迟而没有相称的质量提升;正确的预算取决于任务的复杂性。

Claude Code 中的努力级别

Claude Code 将抽象的预算 token 概念转换为更容易理解的命名努力级别:

  • 低努力(简单任务的默认值):最小思考预算,快速响应,适合代码格式化、简单解释、单文件编辑和查找操作。
  • 中等努力:适中的思考预算,大多数交互式编码会话的默认值;在典型开发任务中平衡速度和质量。
  • 高努力 / 最大:大型思考预算,保留用于复杂任务——调试难以重现的问题、设计系统、分析安全影响,或任何错误答案会代价高昂的任务。

模型何时思考

并非每个响应都会触发扩展思考。Claude Code 使用启发式方法根据任务复杂性信号来确定何时需要额外推理:请求的长度和模糊性、涉及的文件数量、任务是否涉及不可逆的更改,以及用户是否明确要求仔细分析。用户也可以通过在请求中添加"仔细想想这个"或"慢慢来"等短语来明确表示所需的努力——这些被模型识别为投入更多推理预算的信号。

流式传输和延迟

扩展思考以可预测的方式与流式传输交互:模型只有在完成内部推理后才开始传输其可见输出。这意味着高努力请求在输出开始之前有更长的初始暂停,但实际内容的第一个 token 是完全成形的,而不是递增地不确定。在 Claude Code 的 CLI 和 IDE 集成中,这显示为响应开始前的简短"思考中..."指示器。对于交互式会话,这种延迟对于复杂任务通常是值得的;对于紧密的反馈循环,保持低努力是首选。

何时使用 / 何时不使用

使用场景避免场景
调试具有许多可能根本原因的复杂、难以重现的错误请求简单的一行代码或快速语法更正——低努力更快且足够
设计或审查具有重大权衡的系统架构每个轮次是一个小步骤的交互式来回会话——延迟会累积
在合并之前分析代码更改的安全影响生成遵循成熟模式的样板代码或脚手架
错误答案需要大量返工才能修复的任务在 CI 管道中运行,其中确定性和速度比推理深度更重要
任何你会交给以"编码前先思考"著称的高级工程师的任务在紧张的 token 预算限制下工作——思考 token 计入你的使用量

优缺点

优点缺点
高努力复杂任务上更高的准确性;发现边缘案例;产生有条理的解释更高的延迟;消耗更多 token;第一个输出 token 之前的暂停更长
低努力响应快速;适合紧密的交互循环;更低的 token 成本可能会在复杂任务上遗漏边缘案例;可能在模糊问题上产生浅层分析
自动努力不需要配置;模型根据任务复杂性自我校准行为较不可预测;可能在看似简单的真正困难任务上投入不足

代码示例

# Claude Code CLI — signaling desired effort level through natural language

# Low effort (fast): simple, well-defined tasks
> Format this function to match our Prettier config

# Medium effort (default): typical coding tasks
> Refactor the UserService class to use dependency injection

# High effort: complex tasks — add "think carefully", "take your time", or "analyze deeply"
> Think carefully: this WebSocket handler occasionally drops messages under high load.
Analyze all the possible race conditions and ordering issues in src/ws/handler.ts
before suggesting a fix.

# High effort: architectural decisions
> Take your time to analyze the trade-offs between using Redis Pub/Sub versus
a message queue like RabbitMQ for our notification service. Consider our
current scale (10k concurrent users) and the team's operational experience.

# High effort: security review
> Analyze src/auth/jwt.ts carefully for security vulnerabilities. Think through
all the attack vectors — token forgery, replay attacks, expiry bypass —
before giving me your assessment.
// Claude Code settings.json — configuring default thinking behavior
// Located at: ~/.claude/settings.json or .claude/settings.json in project root
{
"thinking": {
"defaultEffort": "medium",
"maxBudgetTokens": 8000,
"enableForComplexTasks": true
}
}
# Using extended thinking directly via the Anthropic API (for custom integrations)
import anthropic

client = anthropic.Anthropic()

# High-effort request: complex architectural question
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=16000,
# thinking block enables extended reasoning; budget_tokens controls depth
thinking={
"type": "enabled",
"budget_tokens": 10000 # allow up to 10k tokens of internal reasoning
},
messages=[{
"role": "user",
"content": (
"Analyze the following database schema for potential performance issues "
"at 1M+ rows. Consider indexing strategies, query patterns, and normalization "
"trade-offs. Schema: [paste schema here]"
)
}]
)

# The response content may include both thinking blocks and text blocks
for block in response.content:
if block.type == "thinking":
# Internal reasoning — useful for debugging model behavior
print(f"[THINKING]: {block.thinking[:200]}...")
elif block.type == "text":
# Final response — the part to show the user
print(f"[RESPONSE]: {block.text}")

# Low-effort request: simple, fast task (thinking disabled or minimal budget)
quick_response = client.messages.create(
model="claude-haiku-4-5", # Haiku for fast, simple tasks
max_tokens=1024,
# No thinking block for simple requests — faster and cheaper
messages=[{
"role": "user",
"content": "Convert this array of objects to a Map keyed by id: [{id: 1, name: 'a'}, {id: 2, name: 'b'}]"
}]
)
print(quick_response.content[0].text)

实用资源

另请参阅