Claude Agent SDK
Agent Buildingclaude-agent-sdkClaude Agent SDK is an Agent Skill for agent building published in the wcygan/dotfiles repository on GitHub: a SKILL.md instruction file an AI agent can load to do this task.
Claude Agent SDK (Python/TypeScript) — building programmatic agents with claude-agent-sdk. Covers query(), ClaudeSDKClient, custom tools, hooks, permissions, sessions, subagents, structured outputs, file checkpointing, skills, slash commands. Auto-loads on claude_agent_sdk imports. Keywords claude-agent-sdk, query, ClaudeSDKClient, custom tools, mcp server, subagents.
How to use this skill
Bring this guide into your coding agent with a prompt tailored to the tool you use.
- Open your project in Codex.
- Copy and paste the prompt below.
- Review files and risks before approving any action.
Inspect the Agent Skill at https://github.com/wcygan/dotfiles/blob/HEAD/config/claude/skills/claude-agent-sdk/SKILL.md and all supporting files. Report provenance, permissions, scripts, dependencies, and security risks. Propose an exact installation into .agents/skills/claude-agent-sdk, but wait for my approval before writing files or running scripts.
Copying this prompt does not install or run the skill. Review third-party files before use.
Claude Agent SDK
Reference knowledge for building agents with the Claude Agent SDK (Python focus, TypeScript parity).
Fetch Strategy
- Quick answers: use the local summary in the reference file
- Before making changes or giving definitive guidance: WebFetch the canonical URL to get the latest docs, then act on the live content
Installation (Python with uv)
uv init && uv add claude-agent-sdk
Or with pip:
pip install claude-agent-sdk
Requires Python 3.10+. The Claude Code CLI is bundled with the package.
Core APIs
| API | Use Case |
|---|---|
query() | One-shot tasks, new session per call |
ClaudeSDKClient | Multi-turn conversations, maintains context |
Quick Start
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions, AssistantMessage, ResultMessage
async def main():
async for message in query(
prompt="Review utils.py for bugs and fix them.",
options=ClaudeAgentOptions(
allowed_tools=["Read", "Edit", "Glob"],
permission_mode="acceptEdits",
),
):
if isinstance(message, AssistantMessage):
for block in message.content:
if hasattr(block, "text"):
print(block.text)
elif isinstance(message, ResultMessage):
print(f"Done: {message.subtype}")
asyncio.run(main())
Topic Routing
Key Concepts
Permission Modes
| Mode | Behavior |
|---|---|
default | Unmatched tools trigger canUseTool callback |
acceptEdits | Auto-approves file edits |
dontAsk | Denies anything not in allowed_tools |
bypassPermissions | Runs everything (sandboxed envs only) |
plan | Read-only; tools that modify are blocked |
Message Types
SystemMessage— session lifecycle (init,compact_boundary)AssistantMessage— Claude's responses and tool callsUserMessage— tool results fed back to ClaudeResultMessage— final message with cost, usage, session_idStreamEvent— partial messages (when enabled)
Tool Naming for Custom Tools
Pattern: mcp__{server_name}__{tool_name}
Example: server "weather" + tool "get_temperature" → mcp__weather__get_temperature
Auth Providers
- Anthropic API:
ANTHROPIC_API_KEYin.env - Amazon Bedrock:
CLAUDE_CODE_USE_BEDROCK=1 - Google Vertex AI:
CLAUDE_CODE_USE_VERTEX=1 - Microsoft Azure:
CLAUDE_CODE_USE_FOUNDRY=1