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.
这个资产会安全暂存
这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。
npx -y tokrepo@latest install b6989234-7835-4bd6-a182-f08f07d60d7c --target codex先暂存文件;激活前需要读取暂存 README 和安装计划。
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
常见问题
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.
引用来源 (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
来源与感谢
Created by Anthropic.
claude-agent-sdk-typescript — ⭐ 1,200+
讨论
相关资产
Claude Agent SDK Demos — 8 Official Example Projects
Official demo collection by Anthropic showcasing the Claude Agent SDK: email agent, research agent, resume generator, chat app, Excel processing, and more. MIT license, 2,100+ stars.
Anthropic Agent SDK — Build Production AI Agents
Official Anthropic SDK for building AI agents with tool use, memory, and orchestration. Production-grade agent framework with Claude as the backbone for autonomous tasks.
Claude Swarm — Multi-Agent Orchestration with SDK
Python-based multi-agent orchestration built on Claude Agent SDK. Opus decomposes tasks, Haiku workers execute in parallel waves with real-time TUI dashboard and budget control.
pbi-cli — Power BI Skills for Claude Code
pbi-cli is a Python CLI that installs Claude Code skills for Power BI models and PBIR reports. Get started with pipx + `skills install`.