intermediate12 min read· Module 6, Lesson 2
🧩Extended Thinking
Let Claude reason step-by-step for complex problems
Extended Thinking
Extended thinking lets Claude show its reasoning process before giving an answer. It's like asking someone to "think out loud."
When to Use Extended Thinking
- Complex math or logic problems
- Code debugging with multiple potential causes
- Analysis requiring multiple steps
- Decision-making with trade-offs
- Any task where you want to verify the reasoning
Basic Usage
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 16000,
thinking: {
type: "enabled",
budget_tokens: 10000 // Max tokens for thinking
},
messages: [{
role: "user",
content: "Is there a pattern in the sequence: 2, 6, 14, 30, 62?"
}]
});
// Process the response
for (const block of response.content) {
if (block.type === "thinking") {
console.log("Claude's reasoning:", block.thinking);
} else if (block.type === "text") {
console.log("Final answer:", block.text);
}
}Response Structure
{
"content": [
{
"type": "thinking",
"thinking": "Let me analyze this sequence step by step...\n2, 6, 14, 30, 62\nDifferences: 4, 8, 16, 32\nThese are powers of 2! So the pattern is 2^(n+1) - 2..."
},
{
"type": "text",
"text": "The pattern is 2^(n+1) - 2. The next number would be 126."
}
]
}Adaptive Thinking (Claude Opus 4.7)
For the latest models, use adaptive thinking instead — Claude dynamically decides how much to think:
const response = await client.messages.create({
model: "claude-opus-4-7",
max_tokens: 16000,
// Claude automatically decides thinking depth
messages: [{
role: "user",
content: "Analyze the time complexity of this algorithm..."
}]
});Key Parameters
| Parameter | Description |
|---|---|
budget_tokens | Max tokens Claude can use for thinking |
display: "summarized" | Get a summary instead of full thinking (default on Claude 4) |
display: "omitted" | Skip thinking output — faster first response |
Cost Note
You're billed for all thinking tokens, even when display is "summarized" or "omitted". Use budget_tokens to control cost.
Next up: Tools and web search — extending Claude's capabilities.