Chapter 7
Get Started
Set up the Claude Agents SDK in four simple steps.
1
Install Claude Code
The SDK uses Claude Code as its runtime:
curl -fsSL https://claude.ai/install.sh | bash
See Claude Code setup for Windows and other options.
2
Install the SDK
npm install @anthropic-ai/claude-agent-sdk
3
Set your API key
export ANTHROPIC_API_KEY=your-api-key
Get your key from the Console.
The SDK also supports authentication via third-party API providers:
- •Amazon Bedrock: set
CLAUDE_CODE_USE_BEDROCK=1 - •Google Vertex AI: set
CLAUDE_CODE_USE_VERTEX=1 - •Microsoft Foundry: set
CLAUDE_CODE_USE_FOUNDRY=1
4
Run your first agent
This example creates an agent that lists files in your current directory using built-in tools.
first-agent.ts
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "What files are in this directory?",
options: { allowedTools: ["Bash", "Glob"] },
})) {
if ("result" in message) console.log(message.result);
}Compare the Agent SDK to other Claude tools
The Claude platform offers multiple ways to build with Claude. Here's how the Agent SDK fits in:
The Anthropic Client SDK gives you direct API access: you send prompts and implement tool execution yourself. The Agent SDK gives you Claude with built-in tool execution.
With the Client SDK, you implement a tool loop. With the Agent SDK, Claude handles it.