Extended Thinking
Extended Thinking lets Claude think deeply, internally, before responding. It delivers much higher accuracy on complex math problems, multi-step reasoning, and strategic decision-making.
Effort Level in Claude Codeโ
In Claude Code, you control Extended Thinking through an Effort Level. Instead of setting the API's budget_tokens directly, you use a simple tiered system. The available tiers depend on the model:
| Level | Behavior | Suitable work |
|---|---|---|
low | Minimal thinking, fast responses | Short, narrowly scoped tasks |
medium | Token-saving | Cost-sensitive work |
high | Balanced (default for Fable 5 ยท Opus 4.8) | Most coding work |
xhigh | Deeper reasoning (default for Opus 4.7) | Complex architecture, hard bugs |
max | Maximum reasoning with no token constraint (session-only) | Demanding tasks |
- Fable 5 / Opus 4.8 / 4.7: All 5 tiers supported (including
xhigh) - Opus 4.6 / Sonnet 4.6:
lowยทmediumยทhighยทmax(xhighnot supported)
How to set the Effort Levelโ
# 1. In the /model menu, adjust the slider with the left/right arrow keys
/model
# 2. Set via environment variable
export CLAUDE_CODE_EFFORT_LEVEL=high
# 3. Set permanently in settings.json
# "effortLevel": "high"
As of v2.1.198, subagents and context compaction inherit the session's Extended Thinking setting as-is. If you set a high effort in the main session, delegated work gets the same thinking depth, which improves result quality.
- Toggle:
Alt+T(macOS:Option+T), or enable/disable globally in/config - One-off high effort: Include the
ultrathinkkeyword in your prompt - View the thinking process: Switch to verbose mode with
Ctrl+Oto display the internal reasoning - Combine with Fast Mode: Fast Mode (
/fast) + low effort = maximum speed, standard mode + high effort = maximum quality
Note that you cannot turn thinking off on Fable 5 โ the session toggle, alwaysThinkingEnabled, and MAX_THINKING_TOKENS=0 all have no effect. Fast mode is also unsupported on Fable 5 (Opus only).
To go back to the previous approach (a fixed thinking budget): set CLAUDE_CODE_DISABLE_ADAPTIVE_THINKING=1, then specify a fixed budget with MAX_THINKING_TOKENS. This applies only to Opus 4.6 and Sonnet 4.6 โ Opus 4.7 and later always use adaptive reasoning, so this environment variable has no effect. Fable 5 also always operates in adaptive mode.
Extended Thinking in the APIโ
When you use the Anthropic API directly rather than Claude Code, you set the thinking budget yourself with the thinking.budget_tokens parameter.
What Is Extended Thinking?โ
A normal response vs. Extended Thinking:
[Normal response]
User โ Claude โ immediate response
[Extended Thinking]
User โ Claude โ ๐ค internal thinking process โ final response
The thinking process is included as a separate block in the API response, which is also useful for debugging.
Basic Usageโ
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function thinkingQuery(problem: string): Promise<{
thinking: string;
answer: string;
}> {
const response = await client.messages.create({
model: "claude-opus-4-8", // Opus and Sonnet support Extended Thinking (Fable 5 is adaptive-thinking only โ cannot be disabled)
max_tokens: 16000,
thinking: {
type: "enabled",
budget_tokens: 10000 // maximum tokens to use for thinking
},
messages: [{ role: "user", content: problem }]
});
let thinking = "";
let answer = "";
for (const block of response.content) {
if (block.type === "thinking") {
thinking = block.thinking;
} else if (block.type === "text") {
answer = block.text;
}
}
return { thinking, answer };
}
// Usage
const result = await thinkingQuery(
"Design the most efficient algorithm for primality testing, " +
"analyze its time complexity, then implement it in TypeScript."
);
console.log("๐ญ Thinking process:\n", result.thinking);
console.log("\nโ
Final answer:\n", result.answer);
Good Use Casesโ
1. Complex algorithm designโ
const algorithmProblem = `
Design a scheduling algorithm that satisfies the following conditions:
- 100+ microservice jobs
- Each job has dependencies, priorities, and resource requirements
- Achieve maximum throughput with minimal resources
- Deadlock prevention
Include algorithm analysis + pseudocode + a real implementation.
`;
const { thinking, answer } = await thinkingQuery(algorithmProblem);
2. Architecture decisionsโ
const architectureDecision = `
Determine the optimal database architecture under these conditions:
- 1 million daily active users
- 80% read / 20% write ratio
- Real-time feed feature required
- Global service (Asia, Europe, US)
- 99.99% availability requirement
Considering a combination of PostgreSQL, MongoDB, Cassandra, and Redis,
present a trade-off analysis and a final recommendation.
`;
const result = await thinkingQuery(architectureDecision);
3. Security vulnerability analysisโ
const securityAnalysis = `
Analyze every possible attack vector in the following authentication code:
\`\`\`typescript
async function login(username: string, password: string) {
const user = await db.query(
\`SELECT * FROM users WHERE username = '\${username}'\`
);
if (user && user.password === md5(password)) {
return generateToken(user.id);
}
}
\`\`\`
For each vulnerability, present an attack scenario and the fixed code.
`;
Setting the Thinking Budgetโ
A budget_tokens guide based on task complexity:
| Task type | Recommended budget_tokens |
|---|---|
| Simple analysis | 1,000 ~ 3,000 |
| Medium complexity | 5,000 ~ 10,000 |
| Complex reasoning | 15,000 ~ 30,000 |
| Very complex problems | 30,000 ~ 50,000 |
// Budget-optimizing wrapper
async function adaptiveThinking(
problem: string,
complexity: "low" | "medium" | "high" | "extreme"
): Promise<string> {
const budgets = {
low: 2000,
medium: 8000,
high: 20000,
extreme: 40000
};
const response = await client.messages.create({
model: "claude-opus-4-6",
max_tokens: budgets[complexity] + 4096,
thinking: {
type: "enabled",
budget_tokens: budgets[complexity]
},
messages: [{ role: "user", content: problem }]
});
return response.content
.filter(b => b.type === "text")
.map(b => b.type === "text" ? b.text : "")
.join("");
}
Making Use of the Thinking Processโ
Use the thinking process for debugging and quality verification:
async function verifiedAnalysis(code: string) {
const { thinking, answer } = await thinkingQuery(
`Find the bugs in the following code:\n\`\`\`\n${code}\n\`\`\``
);
// Detect uncertainty in the thinking process
const isUncertain = thinking.toLowerCase().includes("not certain") ||
thinking.toLowerCase().includes("unsure") ||
thinking.toLowerCase().includes("maybe") ||
thinking.toLowerCase().includes("not sure");
return {
answer,
confidence: isUncertain ? "low" : "high",
reasoning: thinking.slice(0, 500) + "..." // summary
};
}
Using Thinking in Multi-turn Conversationsโ
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function thinkingConversation() {
const messages: Anthropic.MessageParam[] = [];
// Turn 1: request a complex design
messages.push({
role: "user",
content: "Help me design a microservices architecture. It's an e-commerce system."
});
const response1 = await client.messages.create({
model: "claude-opus-4-6",
max_tokens: 12000,
thinking: { type: "enabled", budget_tokens: 8000 },
messages
});
// The thinking block must also be included in history (for multi-turn)
messages.push({ role: "assistant", content: response1.content });
// Turn 2: follow-up question
messages.push({
role: "user",
content: "How should I design communication between the payment service and the order service?"
});
const response2 = await client.messages.create({
model: "claude-opus-4-6",
max_tokens: 12000,
thinking: { type: "enabled", budget_tokens: 8000 },
messages
});
// Extract the text of the second answer
return response2.content
.filter(b => b.type === "text")
.map(b => b.type === "text" ? b.text : "")
.join("");
}
- Don't use it for simple questions โ it increases cost and latency
budget_tokensmust be smaller thanmax_tokens- Saving the thinking process lets you trace the rationale for a decision later
- Opus (4.6~4.8) and Sonnet 4.6 all support Extended Thinking
- Fable 5 does not support the
thinking.budget_tokensstyle of Extended Thinking โ it is adaptive-thinking only, and the raw thinking process is not returned (you can only receive a summary viathinking.display: "summarized"). Thinking depth is controlled with theeffortparameter
Extended Thinking's thinking tokens are billed at the output-token rate. You can adjust cost with the Effort Level; in production, enable it only when needed.