OpenParable
Skip to content
← Back to skills

Claude Agent SDK

Agent Building
claude-agent-sdk

Claude 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.

View on GitHub ↗
QUICK START

How to use this skill

Bring this guide into your coding agent with a prompt tailored to the tool you use.

  1. Open your project in Codex.
  2. Copy and paste the prompt below.
  3. Review files and risks before approving any action.
Prompt to paste
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

APIUse Case
query()One-shot tasks, new session per call
ClaudeSDKClientMulti-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

TopicReferenceCanonical URL
Getting started with Python (uv)quickstarthttps://platform.claude.com/docs/en/agent-sdk/quickstart#python-(uv)
Python SDK full API referencepython-sdkhttps://platform.claude.com/docs/en/agent-sdk/python
GitHub repo and READMEgithub-repohttps://github.com/anthropics/claude-agent-sdk-python
Agent loop lifecycle and messagesagent-loophttps://platform.claude.com/docs/en/agent-sdk/agent-loop
Loading CLAUDE.md, skills, hooksclaude-code-featureshttps://platform.claude.com/docs/en/agent-sdk/claude-code-features
Session management (resume, fork)sessionshttps://platform.claude.com/docs/en/agent-sdk/sessions
Custom tool definitionscustom-toolshttps://platform.claude.com/docs/en/agent-sdk/custom-tools
Scaling to many toolstool-searchhttps://platform.claude.com/docs/en/agent-sdk/tool-search
Permission modes and rulespermissionshttps://platform.claude.com/docs/en/agent-sdk/permissions
User input and approval flowsuser-inputhttps://platform.claude.com/docs/en/agent-sdk/user-input
Intercepting tool calls with hookshookshttps://platform.claude.com/docs/en/agent-sdk/hooks
File change tracking and rewindfile-checkpointinghttps://platform.claude.com/docs/en/agent-sdk/file-checkpointing
Validated JSON output schemasstructured-outputshttps://platform.claude.com/docs/en/agent-sdk/structured-outputs
Customizing system promptssystem-promptshttps://platform.claude.com/docs/en/agent-sdk/modifying-system-prompts
Spawning isolated subagentssubagentshttps://platform.claude.com/docs/en/agent-sdk/subagents
Built-in and custom slash commandsslash-commandshttps://platform.claude.com/docs/en/agent-sdk/slash-commands
Skills in the SDKskills-sdkhttps://platform.claude.com/docs/en/agent-sdk/skills
Skills authoring (Claude Code)skills-authoringhttps://code.claude.com/docs/en/skills

Key Concepts

Permission Modes

ModeBehavior
defaultUnmatched tools trigger canUseTool callback
acceptEditsAuto-approves file edits
dontAskDenies anything not in allowed_tools
bypassPermissionsRuns everything (sandboxed envs only)
planRead-only; tools that modify are blocked

Message Types

  • SystemMessage — session lifecycle (init, compact_boundary)
  • AssistantMessage — Claude's responses and tool calls
  • UserMessage — tool results fed back to Claude
  • ResultMessage — final message with cost, usage, session_id
  • StreamEvent — 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_KEY in .env
  • Amazon Bedrock: CLAUDE_CODE_USE_BEDROCK=1
  • Google Vertex AI: CLAUDE_CODE_USE_VERTEX=1
  • Microsoft Azure: CLAUDE_CODE_USE_FOUNDRY=1