Chain-of-thought
Prompt Engineering
Some questions have a direct answer that Claude can produce in one shot. Others require working through intermediate steps — and if Claude skips those steps, it's more likely to get the answer wrong. Chain-of-thought prompting is the technique of explicitly asking Claude to reason before concluding, and it makes a measurable difference on anything involving logic, multi-step analysis, or careful judgement.
Why Step-by-Step Reasoning Helps
Recall from Chapter 1: Claude generates responses token by token, left to right. It can't go back and revise. This means if it jumps to a conclusion early, the reasoning that follows is partly post-hoc justification rather than genuine working-out. The conclusion shapes the reasoning, rather than the other way around.
When you ask Claude to reason step by step, those intermediate steps become part of the context Claude is generating into. Each step informs the next, and the final conclusion is built on explicit reasoning rather than a direct guess. The reasoning is visible — which means you can check it, catch errors, and push back on specific steps.
What a Chain of Thought Looks Like
A well-structured chain-of-thought response moves through identifiable stages:
Claude confirms its understanding of the problem, often surfacing hidden assumptions. "This is asking me to compare X under condition Y…"
The problem is split into sub-problems or sequential steps. Each piece is small enough to handle individually.
Each sub-problem is addressed in turn. Intermediate results appear explicitly and inform the next step.
The final answer is stated, grounded in the steps above. It should follow naturally — not contradict the working.
Trigger Phrases That Work
The exact wording matters less than you might think — Claude recognises the intent. But some phrasings are more reliable than others:
Think through this step by step.
The classic. Works across almost any task. Put it at the end of the prompt where it carries most weight.
Reason through this before giving your answer.
Useful when you want the reasoning to precede the conclusion — prevents Claude from answering first and justifying after.
Walk me through your thinking.
Slightly conversational; works well in diagnostic contexts where you want to follow the logic interactively.
Before answering, list the factors you're weighing.
Good for decision or trade-off questions. Forces Claude to surface assumptions explicitly.
Show your working.
Familiar from maths contexts; also works well for capacity planning, cost estimates, and logic problems.
Think out loud as you work through this.
Produces a more exploratory, less structured response — good when you want Claude to surface uncertainty and alternatives.
A Real Example — Debugging with Chain-of-Thought
When Chain-of-Thought Helps — and When to Skip It
| Task type | Use CoT? | Why |
|---|---|---|
| Multi-step maths or calculations | Yes | Each step uses the previous result — skipping steps introduces compounding error |
| Debugging — finding a root cause | Yes | Reasoning through possibilities systematically beats guessing the most common cause |
| Trade-off decisions (A vs B) | Yes | Forces the criteria to be explicit rather than hidden in a conclusion |
| Security or logic review | Yes | You want to see what Claude checked and what it dismissed — the working matters as much as the answer |
| Simple factual questions | No | Adds verbosity with no benefit — "What port does SSH use?" doesn't need a reasoning chain |
| Creative writing | No | Interrupts flow; reasoning steps don't improve creative output |
| Format / style tasks | No | Rewriting a sentence or reformatting a table doesn't benefit from explicit intermediate steps |
| Ambiguous problem you're still exploring | Yes | "Think out loud" surfaces assumptions and alternatives you might not have considered |
Asking Claude to Separate Thinking from Answer
Sometimes you want the reasoning but don't need it cluttering the final response. You can ask Claude to structure the output explicitly:
Extended Thinking — The Built-In Version
Claude models support an optional extended thinking mode (available via the API and some interfaces) where Claude maintains a private reasoning scratchpad before generating its response. This is chain-of-thought at the architecture level — the model genuinely works through the problem internally before committing to a response token.
- More thorough than a prompted chain-of-thought for hard reasoning tasks
- The scratchpad content may or may not be shown to you depending on the interface
- Slower and higher cost — worth it for complex decisions, not for everyday tasks
- In Claude Code, this is what Fast Mode disables — standard responses are faster; complex reasoning tasks benefit from it being on