Intermediate

Precognition: Thinking Step by Step

Asking Claude to reason before answering is one of the most reliable ways to improve accuracy on complex tasks. Learn Chain-of-Thought prompting, the <thinking> tag pattern, and extended thinking mode.

16 min read 8 examples Chapter 6 of 11

What Chain-of-Thought Prompting Is

Chain-of-Thought (CoT) prompting is the practice of instructing Claude to work through its reasoning explicitly before delivering a final answer. Instead of jumping to a conclusion, Claude narrates its thought process โ€” each step informing the next โ€” like showing its work on a math exam.

The term "precognition" captures the intuition: think before you speak. By generating intermediate reasoning steps, Claude dramatically reduces errors on tasks that require multi-step logic, mathematical calculation, nuanced analysis, or careful inference.

๐Ÿ’ก
Why It Works
Language models generate text sequentially, token by token. Without CoT, Claude must "jump" to a conclusion in one pass. With CoT, each intermediate reasoning step becomes context for the next step โ€” allowing Claude to build up to complex answers incrementally rather than guessing them directly.

Zero-Shot CoT: The Simplest Trigger

The most basic CoT technique requires no examples โ€” just a simple instruction appended to your prompt:

๐Ÿง 
"Think step by step"
The classic zero-shot CoT trigger. Reliable for math, logic, and analysis tasks. Append to any prompt that requires multi-step reasoning.
๐Ÿ”
"Before answering, reason through..."
More directive โ€” specifies when to reason and implies what to reason about. Better for tasks where you want to constrain the reasoning to specific considerations.
๐Ÿ“
"Work through this carefully"
A softer trigger that still activates deliberate processing. Useful for judgment calls and analysis where "step by step" sounds too mechanical.
โœ…
"Show your reasoning, then answer"
Explicitly separates the reasoning process from the final answer, making it easy to validate the reasoning chain independently.

The <thinking> Tag Pattern

For applications where you want Claude's reasoning to be separable from its answer โ€” so you can display or hide it, log it, or evaluate it independently โ€” use the <thinking> tag pattern:

Thinking Tag Pattern
Analyze the following business scenario and recommend a course of action.

First, use <thinking> tags to work through the problem:
- What are the key factors at play?
- What are the trade-offs of each option?
- What assumptions am I making?

After your thinking, provide your recommendation in plain prose.

<scenario>
A Series B SaaS startup (ARR: $8M, burn rate: $600K/month, runway: 14 months)
has two offers: (1) strategic acquisition at 4x ARR from a larger competitor,
or (2) a new funding round at a 20% down round valuation. The founding team
wants to remain independent. Three key engineers have competing offers.
</scenario>

Claude responds with explicit <thinking> XML wrapped around its reasoning, followed by the clean recommendation. Your code can then parse and separate the two sections.

Parsing Thinking Tags (Python)
import re

def parse_cot_response(response_text: str) -> dict:
    """Separate thinking from final answer."""
    thinking_match = re.search(
        r'<thinking>(.*?)</thinking>',
        response_text,
        re.DOTALL
    )
    thinking = thinking_match.group(1).strip() if thinking_match else ""
    answer = re.sub(r'<thinking>.*?</thinking>', '', response_text, flags=re.DOTALL).strip()
    return {"reasoning": thinking, "answer": answer}

Before / After: Direct vs. CoT โ€” Math Word Problem

A train leaves Chicago at 2:30 PM traveling at 65 mph toward New York. A second train leaves New York at 4:00 PM traveling at 80 mph toward Chicago. The distance between cities is 790 miles. At what time do the trains meet?
Solve this problem step by step. Show each calculation clearly. At the end, state the answer as a specific time. A train leaves Chicago at 2:30 PM traveling at 65 mph toward New York. A second train leaves New York at 4:00 PM traveling at 80 mph toward Chicago. The distance between cities is 790 miles. At what time do the trains meet?
Step 1 โ€” Head start distance. Train A departs 1.5 hours before Train B. Distance covered by Train A before Train B departs = 65 ร— 1.5 = 97.5 miles. Step 2 โ€” Remaining distance when Train B departs. 790 - 97.5 = 692.5 miles remaining between the two trains at 4:00 PM. Step 3 โ€” Combined closing speed. 65 mph + 80 mph = 145 mph (trains are moving toward each other). Step 4 โ€” Time to close the gap. 692.5 รท 145 = 4.776... hours โ‰ˆ 4 hours 46.6 minutes Step 5 โ€” Meeting time. 4:00 PM + 4h 47m = 8:47 PM The trains meet at approximately 8:47 PM.

CoT for Financial Analysis

Financial Analysis with Structured Reasoning
You are a financial analyst. Evaluate whether this company is worth
acquiring at the proposed valuation.

Before reaching your conclusion:
1. Calculate the key valuation multiples (EV/Revenue, EV/EBITDA)
2. Compare them to industry benchmarks (note your benchmarks)
3. Assess the qualitative risks
4. Weigh the strategic value

Then provide a final recommendation: Proceed / Negotiate / Pass.

<company_data>
Revenue: $12M ARR (35% YoY growth)
EBITDA: -$2M (investing in growth)
Proposed acquisition price: $60M
Industry: B2B HR tech SaaS
Comparable transactions: typically 5-8x ARR for this growth rate
Strategic fit: fills gap in enterprise product suite
Key risk: 2 of 4 engineers are contractors
</company_data>

Self-Consistency: Asking Claude to Verify Its Own Answer

Self-consistency is a technique where you ask Claude to check its own work โ€” either by re-solving the problem from scratch, or by explicitly asking it to verify each step of its reasoning:

Self-Consistency Verification Pattern
# Pattern 1: Solve then verify
Solve this logic puzzle step by step.
After reaching your answer, verify it by checking if it satisfies
all the stated constraints. If it doesn't, revise your solution.

# Pattern 2: Independent re-solve
First, solve this problem using approach A.
Then, solve the same problem using a completely different approach.
If both approaches agree, report that answer. If they disagree,
identify which approach has an error and correct it.

# Pattern 3: Confidence-gated verification
Solve this problem step by step.
Rate your confidence in the answer from 1-10.
If confidence is below 8, re-examine your reasoning and identify
the weakest step.

Extended Thinking Mode (Claude 3.7+)

Claude 3.7 Sonnet and later models support extended thinking โ€” a native API-level feature where Claude generates an internal reasoning trace before producing its response. This is more powerful than prompt-level CoT because the thinking happens in a dedicated scratchpad that isn't constrained by the response format.

Extended Thinking API (Python)
import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-3-7-sonnet-20250219",
    max_tokens=16000,
    thinking={
        "type": "enabled",
        "budget_tokens": 10000  # tokens allocated for internal reasoning
    },
    messages=[{
        "role": "user",
        "content": "Design the optimal database schema for a multi-tenant SaaS application that needs row-level security, audit logging, and soft deletes. Consider performance implications."
    }]
)

# Response contains two content blocks:
for block in response.content:
    if block.type == "thinking":
        print("Internal reasoning:", block.thinking)
    elif block.type == "text":
        print("Final answer:", block.text)

When NOT to Use CoT

CoT increases token usage and latency. It's valuable for complex reasoning but wasteful for:

โŒ
Skip CoT for:
Simple factual lookups ("What is the capital of France?"), direct translations, basic text transformations, classification with obvious categories, and creative tasks where reasoning scaffolding constrains rather than helps.
โœ…
Use CoT for:
Math problems, logic puzzles, multi-step analysis, legal or medical reasoning, debugging (reason through the failure mode), financial modeling, decision-making with multiple trade-offs, and any task where the answer could be "gotcha'd" by a subtlety.
โœ…
Chapter 6 Takeaway
Asking Claude to reason before answering is one of the highest-ROI prompt techniques for accuracy on complex tasks. Use zero-shot "think step by step" for quick wins, the <thinking> tag pattern for separable reasoning in applications, and extended thinking API mode for maximum reasoning depth on hard problems. Reserve CoT for tasks where the reasoning path matters โ€” it's overkill for simple lookups.