Use this file to discover all available pages before exploring further.
Starting June 15, 2026, Agent SDK and claude -p usage on subscription plans will draw from a new monthly Agent SDK credit, separate from your interactive usage limits. See Use the Claude Agent SDK with your Claude plan for details.
ファイルを自動的に読み取り、コマンドを実行し、ウェブを検索し、コードを編集するなど、さらに多くのことができる AI エージェントを構築します。Agent SDK は、Claude Code を強化する同じツール、エージェントループ、およびコンテキスト管理を提供し、Python と TypeScript でプログラム可能です。
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptionsasync 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 itasyncio.run(main())
Python パッケージには Python 3.10 以降が必要です。pip が No matching distribution found for claude-agent-sdk と報告する場合、インタープリターは 3.10 より古いバージョンです。macOS または Linux では python3 --version を実行するか、Windows では py --version を実行してバージョンを確認してください。
TypeScript SDK は、プラットフォーム用のネイティブ Claude Code バイナリをオプションの依存関係としてバンドルしているため、Claude Code を別途インストールする必要はありません。
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptionsasync def main(): async for message in query( prompt="What files are in this directory?", options=ClaudeAgentOptions(allowed_tools=["Bash", "Glob"]), ): if hasattr(message, "result"): print(message.result)asyncio.run(main())
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptionsasync def main(): async for message in query( prompt="Find all TODO comments and create a summary", options=ClaudeAgentOptions(allowed_tools=["Read", "Glob", "Grep"]), ): if hasattr(message, "result"): print(message.result)asyncio.run(main())
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptionsasync def main(): async for message in query( prompt="Review this code for best practices", options=ClaudeAgentOptions( allowed_tools=["Read", "Glob", "Grep"], ), ): if hasattr(message, "result"): print(message.result)asyncio.run(main())
複数の交換にわたってコンテキストを維持します。Claude は読み取ったファイル、実行した分析、および会話履歴を記憶します。後でセッションを再開するか、異なるアプローチを探索するためにフォークします。この例は、最初のクエリからセッション ID をキャプチャし、その後、完全なコンテキストで続行するために再開します。
import asynciofrom claude_agent_sdk import query, ClaudeAgentOptions, SystemMessage, ResultMessageasync def main(): session_id = None # First query: capture the session ID async for message in query( prompt="Read the authentication module", options=ClaudeAgentOptions(allowed_tools=["Read", "Glob"]), ): if isinstance(message, SystemMessage) and message.subtype == "init": session_id = message.data["session_id"] # Resume with full context from the first query async for message in query( prompt="Now find all places that call it", # "it" = auth module options=ClaudeAgentOptions(resume=session_id), ): if isinstance(message, ResultMessage): print(message.result)asyncio.run(main())
Claude Platform は Claude で構築するための複数の方法を提供しています。Agent SDK がどのように適合するかは次のとおりです。
Agent SDK vs Client SDK
Agent SDK vs Claude Code CLI
Agent SDK vs Managed Agents
Anthropic Client SDK は直接 API アクセスを提供します。プロンプトを送信し、ツール実行を自分で実装します。Agent SDK は、組み込みツール実行を備えた Claude を提供します。Client SDK では、ツールループを実装します。Agent SDK では、Claude がそれを処理します。
# Client SDK: You implement the tool loopresponse = client.messages.create(...)while response.stop_reason == "tool_use": result = your_tool_executor(response.tool_use) response = client.messages.create(tool_result=result, **params)# Agent SDK: Claude handles tools autonomouslyasync for message in query(prompt="Fix the bug in auth.py"): print(message)