Skip to main content

Environment Setup

Get your development environment ready for Claude Agent SDK exercises.

Estimated time ~10 minutes

1. Prerequisites

  • Node.js 18+ (node --version)
  • npm or pnpm package manager
  • An Anthropic API key (console.anthropic.com)
  • A code editor (VS Code or Cursor recommended)

2. Install the SDK

Terminal
# Create project
mkdir agentway-exercises && cd agentway-exercises
npm init -y

# Install SDK and TypeScript
npm install @anthropic-ai/claude-agent-sdk
npm install -D typescript tsx

# Set API key
export ANTHROPIC_API_KEY="sk-ant-..."

3. Verify Installation

hello-agent.ts
import { query } from "@anthropic-ai/claude-agent-sdk";

const response = query({
  prompt: "Say hello and tell me your model name",
  options: {
    model: "claude-sonnet-4-5",
    allowedTools: []  // No tools needed for this test
  }
});

for await (const message of response) {
  if (message.type === "system") {
    console.log("[Connected] Session:", message.session_id);
  }
  if (message.type === "result") {
    console.log("[Agent]", message.content);
  }
}
Run
npx tsx hello-agent.ts
# Expected output:
# [Connected] Session: sess_abc123...
# [Agent] Hello! I'm Claude (claude-sonnet-4-5)...

4. Project Structure

Recommended Layout
agentway-exercises/
├── package.json
├── p1-agent-basics/
│   └── first-agent.ts        # P1 exercises
├── p2-tool-use/
│   ├── tool-calling.ts        # Exercise 1
│   ├── can-use-tool.ts        # Exercise 2
│   └── tool-logger.ts         # Exercise 3
├── p3-structured-output/
│   └── schema-validation.ts   # P3 exercises
├── ...
└── p12-production/
    └── production-agent.ts    # Final capstone

5. Troubleshooting

AUTHENTICATION_FAILED
Check your ANTHROPIC_API_KEY. Get one from console.anthropic.com.
CLI_NOT_FOUND
Known Issue #1: Install the Claude Code CLI globally: npm i -g @anthropic-ai/claude-code
Module not found
Ensure you're in the correct directory and ran npm install.

Setup complete? Start your first lesson:

Start P1: Agent Basics →
← Back to Dashboard