Skip to main content
πŸ’‘ claude code extended thinkingπŸ’‘ claude effort levelπŸ’‘ ultrathink

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:

LevelBehaviorSuitable work
lowMinimal thinking, fast responsesShort, narrowly scoped tasks
mediumToken-savingCost-sensitive work
highBalanced (default for Fable 5 Β· Opus 4.8)Most coding work
xhighDeeper reasoning (default for Opus 4.7)Complex architecture, hard bugs
maxMaximum 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 (xhigh not 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.

Controlling Thinking in Claude Code
  • Toggle: Alt+T (macOS: Option+T), or enable/disable globally in /config
  • One-off high effort: Include the ultrathink keyword in your prompt
  • View the thinking process: Switch to verbose mode with Ctrl+O to 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).

Disabling Adaptive Reasoning

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 typeRecommended budget_tokens
Simple analysis1,000 ~ 3,000
Medium complexity5,000 ~ 10,000
Complex reasoning15,000 ~ 30,000
Very complex problems30,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("");
}
Tips for using Extended Thinking
  • Don't use it for simple questions β€” it increases cost and latency
  • budget_tokens must be smaller than max_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_tokens style of Extended Thinking β€” it is adaptive-thinking only, and the raw thinking process is not returned (you can only receive a summary via thinking.display: "summarized"). Thinking depth is controlled with the effort parameter
Cost warning

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.

이 챕터λ₯Ό μ™„λ£Œν•˜μ…¨λ‚˜μš”?

ν•™μŠ΅ 진도λ₯Ό μ²΄ν¬ν•˜μ—¬ λ‚˜μ˜ λ‘œλ“œλ§΅ 달성λ₯ μ„ λ†’μ—¬λ³΄μ„Έμš”.