Module 2 - Lesson 2: Anthropic Claude Prompts Overview

Comprehensive guide to Anthropic Claude prompting techniques and patterns.

Published: 1/10/2026

Anthropic Claude Prompts: From Basic to Advanced

This lesson covers essential Anthropic Claude prompting techniques, mirroring what you learned with OpenAI in Module 1, but with Anthropic's unique approach and features.

Lesson Structure

Each sub-lesson focuses on a specific prompting technique with working code examples. Follow them in order to build your understanding progressively while comparing with OpenAI's approach.


šŸ“š Prompt Techniques Overview

Lesson 2a: Basic Prompt

Simple text input prompt with Anthropic Claude.

  • Send a basic text prompt to Claude
  • Understand Anthropic's response structure
  • Learn about required max_tokens parameter
  • Use Case: Quick, straightforward queries
  • Key Difference: Response is an array of content blocks

Lesson 2b: System Prompt

Defining AI role and behavior with system prompts.

  • Set Claude's personality and expertise
  • Use separate system parameter
  • Control response style and tone
  • Use Case: Specialized assistants (travel agent, code reviewer, etc.)
  • Key Difference: System prompt is a top-level parameter, not in messages array

Lesson 2c: Temperature Control

Adjusting response creativity with the temperature parameter.

  • Learn how temperature affects randomness in Claude
  • Balance creativity vs consistency
  • Understand Anthropic's temperature range (0.0 - 1.0)
  • Use Case: Creative writing (high temp) vs factual responses (low temp)
  • Key Difference: Range is 0.0-1.0 (vs OpenAI's 0.0-2.0)

Lesson 2d: Extended Prompts

Detailed context and instructions for advanced prompt engineering.

  • Provide comprehensive background information
  • Use detailed instructions for complex tasks
  • Leverage Claude's large context window (200k tokens)
  • Use Case: Complex analysis, detailed planning, multi-step reasoning
  • Key Difference: Claude excels at very long, detailed prompts

Lesson 2e: Streaming Responses

Real-time output with streaming responses.

  • Stream Claude responses word-by-word
  • Use .stream() method with event handlers
  • Handle partial responses
  • Use Case: Chat interfaces, real-time assistants
  • Key Difference: Uses .on("text") event handler vs OpenAI's async iterator

Lesson 2f: Structured Output

Validated JSON output using Zod.

  • Request JSON responses from Claude
  • Validate with Zod schemas
  • Handle markdown code block wrappers
  • Use Case: Data extraction, form filling, API integrations
  • Key Difference: Prompt-based approach (Claude doesn't have native structured output yet)

Lesson 2g: Function/Tool Calling

Integrating external APIs and tools with function calling.

  • Define tools Claude can use
  • Handle tool use responses
  • Build multi-turn conversations
  • Use Case: Weather lookups, database queries, calculations, external integrations
  • Key Difference: Different tool response format and conversation flow

Learning Path

Legend:

  • šŸ”µ Light Blue: Foundation concepts
  • 🟔 Light Yellow: Intermediate techniques
  • šŸ”“ Light Red: Advanced patterns

Quick Reference

TechniqueComplexityBest ForModule 1 Equivalent
Basic Prompt⭐ BeginnerSimple queriesLesson 3a
System Prompt⭐ BeginnerDefining AI roleLesson 3b
Temperature⭐⭐ IntermediateBalancing creativityLesson 3c
Extended Prompts⭐⭐ IntermediateComplex instructionsLesson 3d
Streaming⭐⭐ IntermediateReal-time UIsLesson 3e
Structured Output⭐⭐⭐ AdvancedType-safe dataLesson 3f
Function Calling⭐⭐⭐ AdvancedTool integrationLesson 3g

OpenAI vs Anthropic: Side-by-Side

Basic Structure

OpenAI:

const response = await openai.responses.create({
  model: "gpt-5-nano",
  system: "You are helpful",
  input: "Hello"
});
const text = response.output_text;

Anthropic:

const response = await anthropic.messages.create({
  model: "claude-haiku-4-5",
  max_tokens: 1000,
  system: "You are helpful",
  messages: [
    { role: "user", content: "Hello" }
  ]
});
const text = response.content[0].text;

Key Differences

FeatureOpenAIAnthropic
max_tokensOptionalRequired
System promptIn messagesSeparate parameter
Responsechoices[0].message.contentcontent[0].text
Streamingstream: true.stream() method
Temperature range0.0 - 2.00.0 - 1.0
Context window128k (GPT-4)200k (Claude)

Prerequisites

Before starting these lessons, ensure you have:

  1. āœ… Completed Module 1 (OpenAI prompts)
  2. āœ… Anthropic API key configured in .env
  3. āœ… @anthropic-ai/sdk installed
  4. āœ… Understanding of basic prompting concepts

Folder Structure

All Anthropic examples are in src/anthropic/:

src/
ā”œā”€ā”€ anthropic/
│   ā”œā”€ā”€ basic-prompt.ts              ← Lesson 2a
│   ā”œā”€ā”€ basic-prompt-with-system.ts  ← Lesson 2b
│   ā”œā”€ā”€ basic-prompt-with-temperature.ts ← Lesson 2c
│   ā”œā”€ā”€ extended-prompt.ts           ← Lesson 2d
│   ā”œā”€ā”€ stream-prompt.ts             ← Lesson 2e
│   ā”œā”€ā”€ structured-output-prompt.ts  ← Lesson 2f
│   └── tools-prompt.ts              ← Lesson 2g
└── openai/                          ← Module 1 examples
    └── ...

Getting Started

Start with Lesson 2a: Basic Prompt and work through each lesson sequentially. Each builds on concepts from the previous ones.

Run Examples

# Run an Anthropic example
pnpm tsx src/anthropic/basic-prompt.ts

# Compare with OpenAI version
pnpm tsx src/openai/basic-prompt.ts

Navigation


What You'll Learn

By completing these seven lessons, you'll master:

  • āœ… Anthropic Claude API fundamentals
  • āœ… Key differences from OpenAI
  • āœ… Response structure and parsing
  • āœ… Real-time streaming with events
  • āœ… Prompt-based structured outputs
  • āœ… Tool calling with conversation flow
  • āœ… Multi-provider development skills

Comparison Skills

You'll be able to:

  • šŸ”„ Translate OpenAI code to Anthropic
  • šŸ“Š Compare provider strengths
  • šŸŽÆ Choose the right provider for each task
  • šŸ› ļø Build provider-agnostic applications

Claude's Strengths

When to Choose Anthropic

  1. Long Documents

    • 200k token context window
    • Better retention over long conversations
    • Ideal for document analysis
  2. Complex Reasoning

    • Excellent at multi-step logic
    • Strong analytical capabilities
    • Thoughtful, nuanced responses
  3. Safety & Reliability

    • Constitutional AI approach
    • Reduced harmful outputs
    • Consistent behavior
  4. Writing Quality

    • Natural, human-like text
    • Good at following style guidelines
    • Excellent for content creation

Practice Exercises

As you go through the lessons, try these:

  1. Compare Responses

    • Run the same prompt on both OpenAI and Anthropic
    • Note differences in style, length, and quality
  2. Measure Performance

    • Time response speeds
    • Count token usage
    • Calculate costs
  3. Test Edge Cases

    • Very long prompts
    • Complex multi-turn conversations
    • Structured output reliability

Ready to Begin?

Start with Lesson 2a: Basic Prompt →

In Lesson 2a, you'll make your first API call to Claude and see how Anthropic's response structure differs from OpenAI's.


Resources

Anthropic Documentation

Code Repository

Community


Happy coding with Claude! šŸš€