框架 · 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
- 托管选项
- Claude Managed Agents
快速入门
安装软件包、设置凭据,然后运行官方文档中的最简 agent。这里使用的模型 ID 与文档一致,但你的账户可能尚未启用这些模型。
Python
pip install claude-agent-sdkimport 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-sdkimport { 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 登录。