# How to Use Chain of Thought Prompts Effectively with Claude

> Master chain of thought prompts with Claude. Enhance complex reasoning and accuracy using explicit step-by-step generation. Learn how now.

- Repository: [Anthropic/prompt-eng-interactive-tutorial](https://github.com/anthropics/prompt-eng-interactive-tutorial)
- Tags: tutorial
- Published: 2026-03-09

---

**Chain of thought prompting asks Claude to reason out loud before delivering a final answer, significantly improving accuracy on complex reasoning tasks by leveraging explicit step-by-step generation as taught in the Anthropic interactive tutorial.**

Chain of thought prompts are a powerful technique for improving Claude's performance on multi-step reasoning tasks. The `anthropics/prompt-eng-interactive-tutorial` repository provides a comprehensive guide to implementing this strategy through "Precognition" and prompt chaining methodologies. This article distills the core workflow from Chapter 6 and Appendix 10.1 into a practical implementation guide.

## What Are Chain of Thought Prompts?

Chain of thought (CoT) prompting is a technique that instructs Claude to **reason out loud** before generating a final answer. According to the tutorial's Chapter 6 notebook, `Anthropic 1P/06_Precognition_Thinking_Step_by_Step.ipynb`, this approach—referred to as "Precognition"—requires the model to explicitly generate its reasoning process rather than jumping directly to a conclusion. By forcing the model to articulate intermediate steps, you reduce errors in arithmetic, logic, and complex decision-making tasks.

## The Two-Turn Pattern for Chain of Thought Prompts

The most effective way to implement chain of thought prompts with Claude uses a **two-turn conversation pattern** derived from Appendix 10.1 (`Anthropic 1P/10.1_Appendix_Chaining_Prompts.ipynb`). This approach separates the reasoning generation from the final answer extraction, allowing you to capture, inspect, and reuse the model's thought process while keeping the final output clean and parseable.

### Step 1: Request Step-by-Step Reasoning

In the first turn, explicitly instruct Claude to think step by step. The tutorial's [`utils/hints.py`](https://github.com/anthropics/prompt-eng-interactive-tutorial/blob/main/utils/hints.py) files contain helpful phrasing patterns such as "Let's take this exercise step by step" or "Answer the following question by thinking step-by-step." Include the specific task and emphasize that you want the reasoning visible in the output.

### Step 2: Capture and Isolate the Reasoning

Store the assistant's reply containing the chain of thought as a separate message in the conversation history. This isolates the reasoning so Claude can reference it in subsequent turns without regenerating it. According to the chaining appendix, this separation is crucial for prompt chaining workflows where intermediate outputs become inputs for later stages.

### Step 3: Request the Final Answer

In a new user turn, ask Claude to use the previously generated reasoning to produce a concise final answer. Specify the exact format you need—for example, "provide ONLY the final numeric answer in US dollars, without any extra explanation." This leverages the reasoning while filtering out the intermediate steps for clean downstream consumption.

### Step 4: Add Verification (Optional)

For critical applications, add a final verification turn that asks Claude to check the answer against specific constraints, output formats, or required fields. This safety check ensures compliance with downstream parsing expectations and catches any logical errors that survived the initial reasoning phase.

## Practical Implementation: Python Code Example

The following Python snippet demonstrates the complete two-turn workflow using the Anthropic SDK. This example mirrors the implementation patterns found in `Anthropic 1P/06_Precognition_Thinking_Step_by_Step.ipynb` and `Anthropic 1P/10.1_Appendix_Chaining_Prompts.ipynb`.

```python

# 1️⃣ Load your API key and model name (as shown in the notebooks)

# from the IPython store or set them directly:

API_KEY = "YOUR_ANTHROPIC_API_KEY"
MODEL_NAME = "claude-3-haiku-20240307"

import anthropic
client = anthropic.Anthropic(api_key=API_KEY)

def get_completion(messages, system_prompt=""):
    """Wraps Claude's messages API."""
    response = client.messages.create(
        model=MODEL_NAME,
        max_tokens=2000,
        temperature=0.0,
        system=system_prompt,
        messages=messages,
    )
    return response.content[0].text

# ───────────────────────────────────────

# 2️⃣ First turn – ask Claude to think step‑by‑step

# ───────────────────────────────────────

task_prompt = (
    "You are a helpful assistant. "
    "Answer the following question **by thinking step‑by‑step** and then give a concise final answer.\n\n"
    "Question: *What is the total cost of buying 3 laptops at $799 each, "
    "plus a 7 % sales tax?*"
)

messages = [{"role": "user", "content": task_prompt}]
reasoning = get_completion(messages)
print("🔎 Reasoning:\n", reasoning)

# ───────────────────────────────────────

# 3️⃣ Second turn – ask Claude to give the final answer

#    using the previously generated reasoning.

# ───────────────────────────────────────

follow_up = (
    "Using the reasoning you just gave, provide ONLY the final numeric answer "
    "in US dollars, without any extra explanation."
)

messages.append({"role": "assistant", "content": reasoning})
messages.append({"role": "user", "content": follow_up})
final_answer = get_completion(messages)
print("\n💡 Final answer:", final_answer)

```

**What the snippet does**

1. **First turn** – The prompt contains "**by thinking step-by-step**". Claude emits a bullet-point chain of calculations (the *chain of thought*).
2. **Second turn** – The assistant's reasoning is fed back as a prior message. The new user request tells Claude to *use* that reasoning and return only the final number.
3. The result is a **clean, reproducible answer** that benefits from Claude's internal reasoning while keeping the output parsable.

## Key Files in the Anthropic Tutorial Repository

Understanding the source material requires familiarity with these specific files from the `anthropics/prompt-eng-interactive-tutorial` repository:

- **`Anthropic 1P/06_Precognition_Thinking_Step_by_Step.ipynb`**: Introduces the "thinking step-by-step" technique (Precognition) that forms the foundation of chain of thought prompting.
- **`Anthropic 1P/10.1_Appendix_Chaining_Prompts.ipynb`**: Demonstrates prompt chaining, the multi-turn technique for separating reasoning from final answers.
- **[`README.md`](https://github.com/anthropics/prompt-eng-interactive-tutorial/blob/main/README.md)**: Provides the course structure overview, mapping Chapter 6 (Precognition) and Appendix 10 (Chaining).
- **[`utils/hints.py`](https://github.com/anthropics/prompt-eng-interactive-tutorial/blob/main/utils/hints.py)** (in both `Anthropic 1P` and `AmazonBedrock` directories): Contains helper phrases like "Let's take this exercise step by step" that trigger effective chain of thought generation.

## Summary

Chain of thought prompting with Claude follows a structured approach that separates reasoning from final output:

- **Explicitly request step-by-step reasoning** using phrases like "think step by step" to trigger Claude's Precognition capability.
- **Isolate the reasoning** in the conversation history so it can be referenced without regeneration.
- **Chain a follow-up prompt** to extract a clean, parseable final answer based on the previously generated reasoning.
- **Verify outputs** with an optional final check to ensure compliance with format constraints and logical correctness.

## Frequently Asked Questions

### What is the difference between chain of thought prompting and simple step-by-step instructions?

Chain of thought prompting specifically requires the model to **generate its reasoning explicitly** in the output before the final answer, whereas simple step-by-step instructions might only organize the final answer into steps. According to the Anthropic tutorial's Chapter 6 notebook, the explicit generation of intermediate reasoning (Precognition) is what improves accuracy on complex tasks by forcing the model to work through the logic rather than guessing.

### When should I use prompt chaining instead of a single-turn chain of thought prompt?

Use **prompt chaining** when you need to separate the reasoning from the final answer for downstream processing, or when you want Claude to revise its own output based on its previous reasoning. As demonstrated in Appendix 10.1 of the tutorial, chaining allows you to capture the reasoning as a distinct message, then ask Claude to produce a formatted final answer or perform verification checks in subsequent turns, keeping your pipeline clean and modular.

### Does chain of thought prompting work with all Claude models?

Yes, chain of thought prompting is effective across the Claude model family, though the specific phrasing in your system prompt may need adjustment based on the model version. The tutorial notebooks use `claude-3-haiku-20240307` and demonstrate that explicit requests for step-by-step reasoning trigger the desired Precognition behavior consistently across Claude 3 model variants, including Opus and Sonnet.

### How do I prevent the chain of thought from appearing in my final output?

To exclude reasoning from the final output, implement a **two-turn conversation pattern**: first, request the step-by-step reasoning; second, ask Claude to provide only the final answer based on that reasoning. As shown in the Python implementation example, storing the reasoning as an assistant message and then chaining a follow-up request allows you to keep the logic internal to the conversation while surfacing only the clean, parseable result for your application.