dotsagent.io
语言:简体中文
框架 · Anthropic

快速了解 Claude Agent SDK

Anthropic 的 SDK 将运行框架置于 Claude Code 之后,可在你自己的 Python 或 TypeScript 程序中使用文件和 shell 工具、权限、钩子、子 agent 和 skills。与此列表中的其他 SDK 不同,它仅运行 Claude 模型,且使用受 Anthropic 商业条款约束。

适用于: 需要 Claude 在文件系统上执行实际操作,并由你控制工具权限的应用。

关键信息

维护者
Anthropic
语言
Python, TypeScript
许可证
Anthropic Commercial Terms
最新版本
Python 0.2.163 / TypeScript 0.3.286 · 2026年9月30日
代码仓库
anthropics/claude-agent-sdk-python · 8,200 个 stars
托管选项
Claude Managed Agents
运行框架由 Anthropic 托管;会话在 Anthropic 管理的沙盒或自托管沙盒中运行。

快速入门

安装软件包、设置凭据,然后运行官方文档中的最简 agent。这里使用的模型 ID 与文档一致,但你的账户可能尚未启用这些模型。

Python

安装
pip install claude-agent-sdk

需要 ANTHROPIC_API_KEY

Python
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions

async def main():
    async for message in query(
        prompt="Find and fix the bug in auth.py",
        options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"]),
    ):
        print(message)  # Claude reads the file, finds the bug, edits it

asyncio.run(main())

快速入门来源

TypeScript

安装
npm install @anthropic-ai/claude-agent-sdk

需要 ANTHROPIC_API_KEY

TypeScript
import { query } from "@anthropic-ai/claude-agent-sdk";

for await (const message of query({
  prompt: "Find and fix the bug in auth.ts",
  options: { allowedTools: ["Read", "Edit", "Bash"] }
})) {
  console.log(message); // Claude reads the file, finds the bug, edits it
}

快速入门来源

功能

支持任意模型否仅限 Claude,可通过 Anthropic、Bedrock、Google Cloud 或 Foundry 使用
MCP 客户端是mcpServers 选项;插件可以捆绑 MCP 服务器
MCP 服务器尚未确认
多 agent是子 agent 负责特定子任务
持久化运行尚未确认可恢复或分叉会话;没有持久化引擎
人工审批是权限模式决定哪些工具需要审批
追踪是支持导出 OpenTelemetry;追踪功能处于 beta 阶段
评测否

近期更新

  • 原名为 Claude Code SDK;现已提供迁移指南。
  • 两个 SDK 现在都会捆绑原生 Claude Code 二进制文件。
  • 自 2026 年 6 月 15 日起,订阅方案中的 SDK 使用量将从单独的每月 Agent SDK 额度中扣除。
  • 未经 Anthropic 批准,第三方应用不得提供 claude.ai 登录。

同一语言的替代方案

来源

  1. code.claude.com/docs/en/agent-sdk/overview
  2. code.claude.com/docs/en/agent-sdk/quickstart
  3. code.claude.com/docs/en/agent-sdk/observability
  4. code.claude.com/docs/en/bedrock-vertex
  5. pypi.org/pypi/claude-agent-sdk/json
  6. registry.npmjs.org/@anthropic-ai%2fclaude-agent-sdk
  7. api.github.com/repos/anthropics/claude-agent-sdk-python
  8. api.github.com/repos/anthropics/claude-agent-sdk-typescript

为 AI agent 开发者提供的独立参考资料。与此处提及的任何厂商均无关联。

© 2026 DotsAgent · 事实核查日期:2026年10月1日