公式の改名

Claude Agent SDK 開発者ガイド

旧 Claude Code SDK は正式に Claude Agent SDK へ改名され、コーディングタスク以外の AI エージェント構築まで対象を広げています。このガイドでは Python/TypeScript クイックスタート、コアコンセプト、Managed Agents との比較、QCode 経由の接続方法を取り上げます。

Python & TypeScript 旧 Claude Code SDK QCode.cc 対応

更新日 2026-10-20

Claude Agent SDKとは

公式の改名

Claude Code SDK Claude Agent SDK

公式の移行ガイドでは、改名に伴いドキュメントが再編され、インストール用のパッケージ名も変更されたことが示されていますが、両方とも同じ SDK を指します(2026-10-20 確認)。

改名の理由

公式ドキュメントは、コーディング以外の AI エージェント構築まで扱うようになったことを改名の理由として挙げています(2026-10-20 確認)。

統一ツールインターフェース

Claude Code と同じツール、エージェントループ、コンテキスト管理を提供し、ライブラリとしてご自身の Python や TypeScript アプリに組み込み、自分のプロセスで稼働できます。

プロダクション対応

ファイルの読み書き・編集、コマンド実行、Web 検索などの組み込みツールに加え、セッション管理、権限制御、Hooks、サブエージェント、MCP 接続も備えています。

多言語サポート

公式に 2 つのパッケージが保守されています。Python 向けは claude-agent-sdk、TypeScript 向けは @anthropic-ai/claude-agent-sdk で、両方とも継続的に更新されています。

コアコンセプト

ツール (Tools)

Agentが呼び出せる関数のコレクション。デコレータで宣言し、JSON Schemaを自動生成してClaudeが理解・実行できます。

エージェントループ

Claude思考→ツール選択→実行→結果観察→継続思考のループ。タスク完了まで繰り返します。

メモリ/コンテキスト

セッション内短期メモリ(会話履歴)とクロスセッション長期メモリ(ファイル/DB永続化)の統一管理。

パーミッション

きめ細かな権限制御:ファイルシステム、ネットワーク、コード実行、外部APIアクセス範囲を個別設定可能。

Pythonクイックスタート

3 ステップで最初の Claude Agent を完成。QCode では API キーと Anthropic エンドポイントを設定するだけです。

1

ステップ1:SDKインストール

python3 -m venv .venv && source .venv/bin/activate
pip install claude-agent-sdk
2

ステップ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

ステップ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

ステップ1:SDKインストール

npm install @anthropic-ai/claude-agent-sdk
2

ステップ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

ステップ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 を https://api.qcode.cc/api に設定すると、QCode の API キーで Agent SDK を呼び出せます。利用可能なモデルは /models をご覧ください。Managed Agents は Anthropic がエージェントループをホストする方式で、セッションはマネージドクラウドサンドボックスと自社インフラのサンドボックスのいずれかで実行できます(公式ドキュメント 2026-10-20 取得)。ただし、この経路は本サイトでは検証しておらず、動作について何も約束できません。

.env
# 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",
    },
)

Fable 5 / Opus 4.8 / Sonnet 4.6 は QCode で呼び出せ、Haiku 4.5 などその他のモデルが使えるかどうかは /models をご確認ください(2026-10-20 確認)。

ツール呼び出し(Function Calling)完全サポート

ストリーミング出力サポート

公式 Messages API と同形:Agent SDK は ANTHROPIC_BASE_URL を変えるだけ

今すぐAIエージェント構築を始める

QCode.ccに登録して、Agent SDKのすべての機能をサポートする安定したClaude APIアクセスを取得しましょう。

どちらから始めるか迷ったら

まず 1 週間試す

小パック $4(枠 $30、7日間)

毎日使う

スターターは月 $9.00、毎日 $5 の枠付き。$1 の枠あたりわずか $0.060で、中パックは約 $0.113です