# Chain-of-thought prompting with Claude XML

> Use thinking and answer tags to give Claude a scratchpad for multi-step reasoning.
>
> Source: https://claudexml.com/patterns/chain-of-thought/ · Last updated 2026-05-25

Home / Patterns / Chain-of-thought

# Chain-of-thought prompting with Claude XML

    Use  and  tags to give Claude a scratchpad for multi-step reasoning.

    Chain-of-thought (CoT) prompts ask the model to reason step-by-step before answering. The XML version: tell Claude to think inside `<thinking>` and put the final answer inside `<answer>`.


## How to apply the pattern


- Add CoT only when reasoning is needed. Classification, math, planning, ambiguous extraction. Not for lookups.
- Specify both `<thinking>` and `<answer>`. Without `<answer>`, the scratchpad and answer blend together.
- Be explicit about what to think about. "List constraints, deduce, then conclude" beats "think step by step."
- Extract `<answer>` in code. Regex: `<answer>([\s\S]*?)</answer>`.

## Worked example


```xml
<instructions>
You will receive a math word problem. Inside <thinking> tags, identify the
unknowns, write the equations, and solve step by step. Inside <answer> tags,
state the final numerical answer with units. Nothing else in <answer>.
</instructions>

<problem>
A train leaves Chicago at 2pm traveling at 60 mph. Another train leaves
St. Louis at 3pm traveling at 75 mph in the opposite direction. The cities
are 300 miles apart. At what time do they meet?
</problem>
```


## Tips


- If you're using Claude's native extended thinking (Claude 3.7+ via the API), that handles CoT for you — don't double up with `<thinking>` tags.
- Keep the scratchpad if you might surface it to power users ("show reasoning" toggle). Otherwise strip it before display.

Cite this page

`Chain-of-thought prompting with Claude XML. claudexml.com. https://claudexml.com/patterns/chain-of-thought/`
