Install
openclaw skills install claude-code-agent-sdkClaude Agent SDK documentation — build production AI agents with Claude Code as a library in Python or TypeScript. Use when building, configuring, or debugging agents with the Claude Agent SDK.
openclaw skills install claude-code-agent-sdkBuild production-grade AI agents using Claude Code as a library. Supports Python and TypeScript.
Reference files are split by topic in references/. Load only what you need:
from claude_agent_sdk import query, ClaudeAgentOptions
async for message in query(
prompt="Fix the bug in auth.py",
options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"])
):
print(message)
options = ClaudeAgentOptions(
hooks={"PreToolUse": [HookMatcher(matcher="Bash", hooks=[validate_command])]}
)
options = ClaudeAgentOptions(
mcp_servers={"playwright": {"command": "npx", "args": ["@playwright/mcp@latest"]}}
)
options = ClaudeAgentOptions(
allowed_tools=["Read", "Glob", "Agent"],
agents={"reviewer": AgentDefinition(
description="Code reviewer",
prompt="Review code quality",
tools=["Read", "Glob", "Grep"]
)}
)
async with ClaudeSDKClient(options=options) as client:
await client.query("Analyze the auth module")
async for msg in client.receive_response(): print(msg)
await client.query("Now refactor it") # auto-continues
async for msg in client.receive_response(): print(msg)