Claude Agent SDK 開発者ガイド
Claude Code SDKは正式にClaude Agent SDKに改名され、より完全なAIエージェント構築体験を提供します。本ガイドはPython/TypeScriptクイックスタート、コアコンセプト、エンタープライズベストプラクティスを網羅します。
更新日 2026-09-21
Claude Agent SDKとは
公式の改名
公式の移行ガイドはドキュメントの再編も伝えており、両方とも同じSDKを指します(2026-09-21確認)。
改名の理由
公式ドキュメントは、コーディング以外のAIエージェント構築まで扱うようになったことを改名の理由として挙げている(2026-09-21確認)。
統一ツールインターフェース
Claude Codeと同じツールシステムとエージェントループを共有し、ローカルとクラウドデプロイをシームレスに切り替えられます。
プロダクション対応
エラーリトライ、セッション管理、ストリーミング出力などエンタープライズ機能が標準搭載。
多言語サポート
公式PythonとTypeScript SDKは対称的なAPI設計と包括的なドキュメントを提供。
コアコンセプト
ツール (Tools)
Agentが呼び出せる関数のコレクション。デコレータで宣言し、JSON Schemaを自動生成してClaudeが理解・実行できます。
エージェントループ
Claude思考→ツール選択→実行→結果観察→継続思考のループ。タスク完了まで繰り返します。
メモリ/コンテキスト
セッション内短期メモリ(会話履歴)とクロスセッション長期メモリ(ファイル/DB永続化)の統一管理。
パーミッション
きめ細かな権限制御:ファイルシステム、ネットワーク、コード実行、外部APIアクセス範囲を個別設定可能。
Pythonクイックスタート
3ステップで最初のClaude Agentを構築。QCode.cc サブスクリプションと完全互換。
ステップ1:SDKインストール
python3 -m venv .venv && source .venv/bin/activate
pip install claude-agent-sdk
ステップ2:Agentを作成
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
options = ClaudeAgentOptions(
system_prompt="You are an expert Python developer",
permission_mode="acceptEdits",
)
async for message in query(
prompt="Create a Python web server", options=options
):
print(message)
asyncio.run(main())
ステップ3:カスタムツール定義
import asyncio
from typing import Any
from claude_agent_sdk import (
ClaudeAgentOptions, create_sdk_mcp_server, query, tool
)
@tool("get_weather", "Get current weather for a city", {"city": str})
async def get_weather(args: dict[str, Any]) -> dict[str, Any]:
return {
"content": [
{"type": "text",
"text": f"Weather in {args['city']}: 22 C, sunny"}
]
}
weather_server = create_sdk_mcp_server(
name="weather",
version="1.0.0",
tools=[get_weather],
)
options = ClaudeAgentOptions(
mcp_servers={"weather": weather_server},
allowed_tools=["mcp__weather__get_weather"],
)
async def main():
async for message in query(
prompt="What's the weather in Beijing and Shanghai?",
options=options,
):
print(message)
asyncio.run(main())
TypeScriptクイックスタート
Node.js / Bun環境でのClaude Agent開発、完全な型サポート付き。
ステップ1:SDKインストール
npm install @anthropic-ai/claude-agent-sdk
ステップ2:Agentを作成
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Create a Python web server",
options: { systemPrompt: "You are an expert Python developer" },
})) {
console.log(message);
}
ステップ3:完全サンプル
import { tool, createSdkMcpServer, query } from "@anthropic-ai/claude-agent-sdk";
import { z } from "zod";
const getTemperature = tool(
"get_temperature",
"Get the current temperature at a location",
{
latitude: z.number().describe("Latitude coordinate"),
longitude: z.number().describe("Longitude coordinate")
},
async (args) => {
return {
content: [{ type: "text", text: `Temperature at ${args.latitude}` }]
};
}
);
const weatherServer = createSdkMcpServer({
name: "weather",
version: "1.0.0",
tools: [getTemperature]
});
for await (const message of query({
prompt: "What's the temperature in Beijing?",
options: {
mcpServers: { weather: weatherServer },
allowedTools: ["mcp__weather__get_temperature"]
}
})) {
console.log(message);
}
Agent SDK vs Managed Agents
| 比較項目 |
Agent SDK
|
Managed Agents
|
|---|---|---|
| 実行環境 | セルフホスト(ローカル/自社サーバー) | Anthropicクラウドホスト |
| スケーリング | 手動インスタンス管理 | 自動エラスティックスケーリング |
| ユースケース | プロトタイピング、高度カスタムシナリオ | エンタープライズ本番Agentデプロイ |
QCode.cc経由での利用
ANTHROPIC_BASE_URL を QCode.cc エンドポイントに設定すれば Agent SDK をそのまま利用できます(利用可能なモデルは /models)。Managed Agents は Anthropic 側が agent をホストする方式(公式ドキュメント 2026-09-22 取得)で、本サイトではこの経路を検証していません。
# Python SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc/api
ANTHROPIC_API_KEY=your-qcode-api-key
# TypeScript SDK
ANTHROPIC_BASE_URL=https://api.qcode.cc/api
ANTHROPIC_API_KEY=your-qcode-api-key
# Point the endpoint at your own gateway: the SDK reads it from env
from claude_agent_sdk import ClaudeAgentOptions
options = ClaudeAgentOptions(
env={
"ANTHROPIC_BASE_URL": "https://api.qcode.cc/api",
},
)
全Claudeモデル(Fable 5/Opus 4.8/Sonnet 4.6/Haiku 4.5)対応
ツール呼び出し(Function Calling)完全サポート
ストリーミング出力サポート
公式 Messages API と同形:Agent SDK は ANTHROPIC_BASE_URL を変えるだけ
今すぐAIエージェント構築を始める
QCode.ccに登録して、Agent SDKのすべての機能をサポートする安定したClaude APIアクセスを取得しましょう。