English
中文
English

Agent SDK overview

中文

Agent SDK 總覽

English

Build production AI agents with Claude Code as a library. The Agent SDK gives you the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript.

中文

使用 Claude Code 作為函式庫來建構生產級 AI agents。Agent SDK 提供與 Claude Code 相同的工具、agent 迴圈和上下文管理,可在 Python 和 TypeScript 中程式化使用。

English

Capabilities

中文

功能

English

Everything that makes Claude Code powerful is available in the SDK:

中文

讓 Claude Code 強大的所有功能都可以在 SDK 中使用:

English

Built-in tools

中文

內建工具

English

Your agent can read files, run commands, and search codebases out of the box.

中文

你的 agent 可以直接讀取檔案、執行命令和搜尋程式碼庫。

English
Tool What it does
Read Read any file in the working directory
Write Create new files
Edit Make precise edits to existing files
Bash Run terminal commands, scripts, git operations
Glob Find files by pattern
Grep Search file contents with regex
WebSearch Search the web for current information
WebFetch Fetch and parse web page content
中文
工具 功能
Read 讀取工作目錄中的任何檔案
Write 建立新檔案
Edit 對現有檔案進行精確編輯
Bash 執行終端命令、腳本、git 操作
Glob 按模式尋找檔案
Grep 用正規表達式搜尋檔案內容
WebSearch 搜尋網路以取得最新資訊
WebFetch 抓取和解析網頁內容
English

Hooks

中文

Hooks

English

Run custom code at key points in the agent lifecycle. SDK hooks use callback functions to validate, log, block, or transform agent behavior.

中文

在 agent 生命週期的關鍵點執行自訂程式碼。SDK hooks 使用回呼函式來驗證、記錄、阻止或轉換 agent 行為。

English

Subagents

中文

子代理

English

Spawn specialized agents to handle focused subtasks. Your main agent delegates work, and subagents report back with results.

中文

產生專門的 agent 來處理特定子任務。你的主 agent 委派工作,子代理回報結果。

English

MCP

中文

MCP

English

Connect to external systems via the Model Context Protocol: databases, browsers, APIs, and hundreds more.

中文

透過 Model Context Protocol 連接外部系統:資料庫、瀏覽器、API 等數百種系統。

English

Get started

中文

開始使用

English
  • Step 1: Install Claude Code - The SDK uses Claude Code as its runtime.
  • Step 2: Install the SDK - npm install @anthropic-ai/claude-agent-sdk (TypeScript) or pip install claude-agent-sdk (Python).
  • Step 3: Set your API key - export ANTHROPIC_API_KEY=your-api-key
  • Step 4: Run your first agent - Create an agent that uses built-in tools.
中文
  • 步驟 1:安裝 Claude Code - SDK 使用 Claude Code 作為其執行環境。
  • 步驟 2:安裝 SDK - npm install @anthropic-ai/claude-agent-sdk (TypeScript) 或 pip install claude-agent-sdk (Python)。
  • 步驟 3:設定 API 金鑰 - export ANTHROPIC_API_KEY=your-api-key
  • 步驟 4:執行你的第一個 agent - 建立一個使用內建工具的 agent。
English

Agent SDK vs Client SDK

中文

Agent SDK vs Client SDK

English

The Anthropic Client SDK gives you direct API access: you send prompts and implement tool execution yourself. The Agent SDK gives you Claude with built-in tool execution - Claude handles the tool loop autonomously.

中文

Anthropic Client SDK 提供直接的 API 存取:你發送提示並自己實作工具執行。Agent SDK 提供內建工具執行的 Claude - Claude 自主處理工具迴圈。