Anthropic Agent SDK
(TypeScript)
Build autonomous AI agents powered by Claude. The same tools, agent loop, and context management that power Claude Code -- packaged as a library for your applications.
What is the Anthropic Agent SDK?
The Anthropic Agent SDK (TypeScript) -- published as @anthropic-ai/claude-agent-sdk on npm -- is a library for building autonomous AI agents powered by Claude. It gives you the same tools, agent loop, and context management that power Claude Code, packaged as a library you can embed in your own applications.
Think of it this way: if the Anthropic SDK (@anthropic-ai/sdk) is a telephone that lets you talk to Claude, the Agent SDK is a complete robotic assistant -- Claude with hands. It can read files, run terminal commands, search the web, edit code, and orchestrate complex multi-step workflows without you implementing any of the tool execution logic.
Key Facts at a Glance
| Property | Value |
|---|---|
| NPM Package | @anthropic-ai/claude-agent-sdk |
| GitHub | anthropics/claude-agent-sdk-typescript |
| Latest Version | v0.2.87 (March 2026) |
| Minimum Node.js | 18+ |
| Language | TypeScript / JavaScript |
| Used by | 1,100+ projects |
| Python Equivalent | claude-agent-sdk (pip) |
One-Sentence Summary
The Agent SDK wraps Claude's intelligence with built-in tool execution, turning a chat API into an autonomous agent that can read, write, search, and execute -- all with a single function call.
Technical Overview
The Agent SDK sits between your application and the Claude API, managing the entire agent lifecycle:
Two Primary Interfaces
query()-- A standalone function returning an async generator. Best for single-shot tasks and simple integrations.- V2 Session Interface (Preview) --
unstable_v2_createSession()provides a class-based session with explicitsend()andstream()methods for multi-turn conversations.
Authentication
The SDK supports multiple authentication methods:
- Anthropic API Key --
ANTHROPIC_API_KEYenvironment variable - Amazon Bedrock -- Set
CLAUDE_CODE_USE_BEDROCK=1with AWS credentials - Google Vertex AI -- Set
CLAUDE_CODE_USE_VERTEX=1with GCP credentials - Azure AI Foundry -- Set
CLAUDE_CODE_USE_FOUNDRY=1with Azure credentials
Architectural Position
The Agent SDK embodies several deliberate architectural choices:
- Same Runtime as Claude Code -- The SDK spawns a Claude Code process under the hood. Your agent runs the same binary that powers the CLI.
- Tool Execution, Not Tool Description -- Unlike the Client SDK, the Agent SDK executes tools directly. You define what Claude can do, not how.
- Streaming-First -- The
query()function returns anAsyncGenerator<SDKMessage, void>. Every interaction is streaming by default. - Security by Default -- Tools are not auto-approved. Explicit opt-in via
allowedTools,permissionMode, orcanUseTool. - Session Persistence -- Sessions persist to disk (JSONL format), enabling resume, fork, and inspection.
typescript// Client SDK: You build the loop let response = await client.messages.create({ ...params }); while (response.stop_reason === "tool_use") { const result = yourToolExecutor(response.tool_use); response = await client.messages.create({ tool_result: result, ...params }); } // Agent SDK: The loop is built for you for await (const message of query({ prompt: "Fix the bug in auth.py" })) { console.log(message); }
Course Sections
Core Concepts
The agent loop, tools, messages, permissions, sessions, and subagents.
→Architecture & Internals
High-level architecture, message flow, IPC protocol, and hook execution.
→Getting Started
Installation, first agent, configuration deep dive, V2 interface.
→Implementation Patterns
Common patterns: analyzers, modifiers, MCP tools, multi-agent pipelines.
→Use Cases & Adoption
CI/CD, code review, documentation, research, enterprise patterns.
→Ecosystem & Integrations
MCP servers, cloud providers, GitHub, databases, plugins.
→Performance & Optimization
Cost management, optimization strategies, monitoring, benchmarks.
→Advanced Topics
Streaming input, V2 deep dive, file checkpointing, hook orchestration.
→Tradeoffs & Alternatives
Comparison with LangChain, CrewAI, AutoGen. Decision matrix.
→Quick Start
bashnpm install @anthropic-ai/claude-agent-sdk
typescriptimport { 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); }