Claude Agent SDK — Build Agents with Claude Code Power
Anthropic's official TypeScript SDK for building AI agents with Claude Code's full capabilities — file editing, command execution, codebase understanding, and complex workflows. npm package.
What it is
The Claude Agent SDK is Anthropic's official TypeScript SDK for building AI agents with Claude Code's full capabilities. It provides file editing, command execution, codebase understanding, and complex workflow orchestration through a clean programmatic API. Available as an npm package.
It is designed for developers who want to embed Claude Code's agent capabilities into their own applications, CI pipelines, or automation scripts rather than using the interactive CLI.
How it saves time or tokens
The SDK handles tool management, conversation state, and error recovery automatically. Instead of building your own agent loop with raw API calls, you get Claude Code's battle-tested orchestration out of the box. The working directory parameter ensures the agent operates in the right context without manual path management.
How to use
- Install:
npm install @anthropic-ai/claude-agent-sdk - Set your API key:
export ANTHROPIC_API_KEY=sk-... - Create a Claude instance and call
claude.agent()with a prompt and working directory
Example
import { Claude } from '@anthropic-ai/claude-agent-sdk';
const claude = new Claude({
apiKey: process.env.ANTHROPIC_API_KEY
});
// Analyze a codebase
const result = await claude.agent({
prompt: 'Analyze this codebase and create a summary of the architecture',
workingDirectory: './my-project',
});
console.log(result.output);
// Fix a bug
const fix = await claude.agent({
prompt: 'Find and fix the null pointer exception in the auth module',
workingDirectory: './my-project',
});
console.log(fix.output);
Related on TokRepo
- AI Tools for Coding -- Developer tools for AI-assisted programming
- AI Tools for Agents -- Tools for building AI agent systems
Common pitfalls
- Requires Node.js 18+ and a valid Anthropic API key with sufficient quota
- The agent has file system access in the working directory; ensure proper sandboxing in production environments
- Long-running agent tasks can consume significant tokens; set budget limits for automated pipelines
Frequently Asked Questions
The CLI is an interactive tool for developers. The SDK is a programmatic interface for embedding Claude Code's agent capabilities into your own applications, scripts, or CI/CD pipelines without interactive prompts.
The agent can read and write files, execute shell commands, search codebases with glob and grep, and use all the tools available in Claude Code CLI. The exact tool set depends on the permissions you configure.
Yes. The SDK is designed for programmatic use. Set the API key as an environment variable, call claude.agent() with your prompt, and process the output. Common uses include automated code reviews, test generation, and documentation updates.
The official SDK is TypeScript/JavaScript. For Python integration, you can use the Anthropic Python SDK with manual tool implementation, or call the Claude Code CLI from Python as a subprocess.
The SDK uses your Anthropic API credits. Cost depends on the complexity of the task and the number of tokens consumed. Monitor usage through the Anthropic dashboard and set spending limits for automated workflows.
Citations (3)
- Claude Agent SDK npm— Anthropic's official TypeScript SDK for building AI agents
- Anthropic Documentation— Claude Code capabilities and tool access
- Anthropic API— Anthropic API pricing and usage
Related on TokRepo
Source & Thanks
Created by Anthropic. Governed by Anthropic Commercial Terms.
claude-agent-sdk-typescript — ⭐ 1,200+
Thank you to Anthropic for making Claude Code's capabilities available as a programmable SDK.
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.