Package: @anthropic-ai/claude-agent-sdk (npm)
Language: TypeScript
Install: npm install @anthropic-ai/claude-agent-sdk
Requires: Node.js 18+, Zod ^3.24.1
Build AI agents with Claude Code's capabilities: understand codebases, edit files, run commands, execute workflows.
import { query } from '@anthropic-ai/claude-agent-sdk';
const result = query({
prompt: 'List all TypeScript files',
options: {
model: 'claude-sonnet-4-5-20250929',
cwd: '/path/to/project'
}
});
for await (const message of result) {
if (message.type === 'result') {
console.log(message.result, message.total_cost_usd);
}
}| API | Purpose | Doc |
|---|---|---|
query() | Main API for agent queries | query-api |
unstable_v2_createSession() | Persistent sessions (experimental) | query-api |
Options | Configuration interface | options |
| Message types | Type-safe message system | messages |
| Permissions | Control tool execution | permissions |
| Hooks | Lifecycle interceptors | hooks |
| MCP | Custom tools & servers | mcp |
| Agents | Custom subagents | agents |
| Sandbox | Secure execution | sandbox |
| Built-in tools | File ops, shell, web | tools |
// Core imports
import {
query,
type Options,
type Query,
type SDKMessage,
type SDKResultMessage,
type AgentDefinition,
type PermissionResult,
type HookCallback
} from '@anthropic-ai/claude-agent-sdk';
// V2 API (unstable)
import {
unstable_v2_createSession,
unstable_v2_resumeSession,
unstable_v2_prompt,
type SDKSession
} from '@anthropic-ai/claude-agent-sdk';
// MCP tools
import {
createSdkMcpServer,
tool,
type McpServerConfig
} from '@anthropic-ai/claude-agent-sdk';See patterns.md for:
Complete type definitions: types.md
All APIs at a glance: quick-reference.md