Skills2026年4月6日·1 分钟阅读

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 就绪

这个资产会安全暂存

这个资产会先安全暂存。复制的指令会要求 Agent 读取暂存文件,并在激活脚本、MCP 配置或全局配置前先确认。

Stage only · 29/100策略:需暂存
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Stage only
信任
信任等级:Community
入口
Claude Agent SDK — Build Agents with Claude Code Power
安全暂存命令
npx -y tokrepo@latest install b6989234-7835-4bd6-a182-f08f07d60d7c --target codex

先暂存文件;激活前需要读取暂存 README 和安装计划。

TL;DR
Anthropic's official TypeScript SDK that gives your applications Claude Code's agent capabilities programmatically.
§01

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.

§02

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.

§03

How to use

  1. Install: npm install @anthropic-ai/claude-agent-sdk
  2. Set your API key: export ANTHROPIC_API_KEY=sk-...
  3. Create a Claude instance and call claude.agent() with a prompt and working directory
§04

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);
§05

Related on TokRepo

§06

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

常见问题

How is the SDK different from the Claude Code CLI?+

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.

What tools does the agent have access to?+

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.

Can I use the SDK in CI/CD pipelines?+

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.

Is there a Python version of the SDK?+

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.

How much does it cost to use?+

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)
🙏

来源与感谢

Created by Anthropic.

claude-agent-sdk-typescript — ⭐ 1,200+

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产