extended-thinking
Use Claude's extended thinking (reasoning) mode effectively — budget tokens, interleaved thinking with tool use, when it helps, when it wastes tokens, and how to inspect the thinking trace. Use this skill when building reasoning-heavy features (math, code generation, multi-step planning), debugging why a model is shallow on hard problems, or deciding whether to enable thinking. Activate when: extended thinking, thinking tokens, budget_tokens, reasoning mode, interleaved thinking, thinking blocks.
What this skill does
# Extended Thinking
**Extended thinking gives the model a scratchpad before the final answer. Pay for reasoning tokens, get deeper answers. Use it surgically, not everywhere.**
## When to Use
- Complex reasoning: math, proofs, multi-step logic
- Code generation where the model needs to plan before writing
- Agent planning: deciding which of many tools to call and in what order
- Debugging subtle issues: model can "think through" root causes
- Writing where structure and coherence matter more than speed
## When NOT to Use
- Simple classification, extraction, or formatting — pure overhead
- Latency-sensitive paths — thinking adds 2-30 seconds
- Small prompts where the model gets it right zero-shot anyway
- High-volume batch tasks on a tight cost budget
## Enabling Thinking
```ts
const response = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 16_000,
thinking: {
type: "enabled",
budget_tokens: 10_000,
},
messages: [{ role: "user", content: "Prove that every prime > 3 is of the form 6k±1." }],
});
```
`budget_tokens` is the max thinking tokens. Model may use fewer. `max_tokens` must be > `budget_tokens` (thinking counts toward the total).
## Budget Sizing
| Task | Typical budget |
|---|---|
| Short multi-step reasoning | 2,000-5,000 |
| Code generation with planning | 5,000-10,000 |
| Complex math/proofs | 10,000-32,000 |
| Deep agent planning | 10,000-20,000 |
| Research synthesis | 16,000-32,000 |
Start at 5,000 and measure. Bigger budget ≠ better answers past a point.
## Inspecting the Thinking Trace
```ts
for (const block of response.content) {
if (block.type === "thinking") {
console.log("REASONING:", block.thinking);
} else if (block.type === "text") {
console.log("ANSWER:", block.text);
}
}
```
The thinking block reveals the model's reasoning. Useful for:
- Debugging why the model chose a wrong answer
- Surfacing rationale to power users (e.g., "show reasoning" toggle)
- Auditing agent decisions
**Do not** feed thinking blocks back to the user as-is in production — they're not polished prose. And do not modify them before passing back in multi-turn (signature validation will fail).
## Interleaved Thinking with Tools
With the `interleaved-thinking-2025-05-14` beta, the model thinks between tool calls — reasoning about each tool result before picking the next:
```ts
const response = await client.messages.create(
{
model: "claude-sonnet-4-6",
max_tokens: 16_000,
thinking: { type: "enabled", budget_tokens: 10_000 },
tools: [searchTool, fetchTool, summarizeTool],
messages: [{ role: "user", content: "Research X and write a brief." }],
},
{ headers: { "anthropic-beta": "interleaved-thinking-2025-05-14" } },
);
```
Without interleaved thinking, the model only thinks once at the start. With it, the model can reassess after every tool result — critical for agents that operate under uncertainty.
## Multi-Turn Conversations
When continuing a conversation that included thinking, pass the assistant's full message back unchanged (including thinking blocks):
```ts
messages.push({ role: "assistant", content: response.content });
messages.push({ role: "user", content: "Great. Now prove the converse." });
const next = await client.messages.create({
model: "claude-sonnet-4-6",
max_tokens: 16_000,
thinking: { type: "enabled", budget_tokens: 10_000 },
messages,
});
```
Thinking blocks carry signatures that the API validates. Reordering or editing them breaks the request.
## Cost
Thinking tokens are billed as output tokens. A call with 10K thinking + 2K answer costs 12K output tokens.
Rough rule: thinking doubles-to-triples the cost of a reasoning-heavy call. Confirm it's worth it by A/B testing against no-thinking.
## Streaming
```ts
const stream = client.messages.stream({
model: "claude-sonnet-4-6",
max_tokens: 16_000,
thinking: { type: "enabled", budget_tokens: 10_000 },
messages: [...],
});
for await (const event of stream) {
if (event.type === "content_block_delta" && event.delta.type === "thinking_delta") {
// show a "thinking..." spinner or subtle text
} else if (event.type === "content_block_delta" && event.delta.type === "text_delta") {
process.stdout.write(event.delta.text);
}
}
```
In UX, show a distinct "thinking" indicator, then switch to streaming the answer.
## Anti-Patterns
1. **Thinking on every request** — massive cost increase with no quality gain for easy tasks
2. **Tiny budget on hard tasks** — 1000 tokens isn't enough for real reasoning; model truncates
3. **Modifying thinking blocks** between turns — breaks signature; API rejects
4. **Showing raw thinking to end users** in production — messy, not polished
## Best Practices
1. Gate thinking on task complexity — classify the query first, enable thinking only for hard ones
2. Start budget at 5K; measure quality and cost; adjust
3. Enable interleaved thinking for any agent with > 3 tools
4. Pass thinking blocks back unmodified in multi-turn
5. Stream the response so users see progress during long thinks
6. Log thinking tokens used per request — detect when the model is consistently maxing out budget
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.