Agent SDK là gì?
Claude Agent SDK = Claude Code repackaged thành library dùng được trong Python / TypeScript.
Build agent autonomous đọc file, chạy command, search web, edit code — y hệt Claude Code, nhưng programmable.
Install
# TypeScript
npm install @anthropic-ai/claude-agent-sdk
# Python
pip install claude-agent-sdk
TypeScript SDK bundle sẵn Claude Code binary — không cần cài thêm.
Code đầu tiên
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);
}
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)
asyncio.run(main())
Built-in tools
| Tool | Tác dụng |
|---|---|
| Read | Đọc file |
| Write | Tạo file mới |
| Edit | Sửa file chính xác |
| Bash | Chạy shell command |
| Glob | Tìm file theo pattern |
| Grep | Search regex |
| WebSearch | Search Google |
| WebFetch | Fetch URL |
| AskUserQuestion | Hỏi user (multiple choice) |
| Monitor | Watch background script |
So với Anthropic Client SDK
| Client SDK | Agent SDK | |
|---|---|---|
| Tool loop | Bạn tự code | Claude tự handle |
| Build agent | Phải implement scaffold | Có sẵn |
| Use case | LLM call đơn giản | Agent thực sự |
So với Claude Code CLI
| Use case | Best choice |
|---|---|
| Interactive dev | CLI |
| CI/CD pipeline | SDK |
| Custom app | SDK |
| One-off task | CLI |
| Production automation | SDK |
Nhiều team dùng cả 2: CLI hằng ngày, SDK cho production.
Khi nào nên dùng?
- Build product có AI agent bên trong (chatbot doanh nghiệp, code review bot, support bot)
- CI/CD: chạy Claude tự động kiểm code mỗi PR
- Workflow automation: agent xử lý email, sync data
Lưu ý
Từ 15/6/2026, Agent SDK trên gói subscription dùng Agent SDK credit riêng (tách khỏi quota interactive). Dùng API key thay vì login claude.ai.
Nguồn chính thống: code.claude.com/docs/en/agent-sdk/overview