claude-agent-sdk-dev
Skill1 starsChanged 7 months agoMITView on GitHub
This skill should be used when the user asks to "build an AI agent with Claude", "use the Claude Agent SDK", "embed Claude Code as a library", "create an autonomous coding agent", "automate code fixes with Claude", "build a Claude-powered CLI tool", "implement subagents", "add hooks to a Claude agent", "configure Claude SDK permissions", "stream Claude agent responses", "use query() / ClaudeAgentOptions", or otherwise develops software using the Claude Agent SDK (Python or TypeScript). Covers project bootstrap, tool/permission/hook/session configuration, message handling, streaming, structured output, MCP/subagent integration, and production hardening. Do NOT use for general Claude Code CLI usage questions, prompt engineering for claude.ai, or Anthropic API (Messages API / Client SDK) direct calls—those belong to claude-code-doc or anthropic-api skills.
In this repository14 other files it gives its agents.
- agent-developmentSkill
- command-developmentSkill
- dev-doc-generatorSkill
- docling-document-intelligenceSkill
- hook-developmentSkill
- mcp-integrationSkill
- openclaw-agent-creatorSkill
- openclaw-cmdSkill
- plugin-settingsSkill
- plugin-structureSkill
- quick-guide-builderSkill
- skill-developmentSkill
- tdad-integrationSkill
- wails3-devSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 68
Minimal options first: Start with query(prompt=..., options=ClaudeAgentOptions(allowed_tools=[...])).
- Very specific: line 80
Run the agent end-to-end against a real prompt.
- Very specific: line 81
Verify the agent stops on its own (no infinite tool-calling loop).
- Very specific: line 82
If permission_mode is set, test a tool that should be denied and one that should be allowed — both paths.
- Very specific: line 120
All 30 official docs at docs/claude-agent-sdk/ (relative to the repo root).
- Distinctive: line 127
Use these as scaffolding for new projects.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Claude Agent SDK Development
Overview
The Claude Agent SDK embeds the full Claude Code agent loop (tools, context management, hooks, permissions) inside a Python or TypeScript application via a single query() function. It is the path to building production AI agents that read files, run commands, edit code, and orchestrate subagents programmatically—without re-implementing tool execution.
This skill drives every Agent SDK task through a fixed workflow. Follow the phases in order. Do not skip the documentation lookup (Phase 3) — the SDK surface is large and most bugs come from stale assumptions.
Core Workflow
Phase 1 — Classify the Task
Determine which of these the request is:
- New project / new agent — greenfield SDK usage, no existing
query()calls in the repo. - Existing project — extend / debug — adding hooks, MCP, subagents, streaming, or fixing behavior in code that already imports
claude_agent_sdk/@anthropic-ai/claude-agent-sdk. - Conceptual / API question — "how do I …" lookup, no code change requested.
Inspect the project to decide: look for claude_agent_sdk in pyproject.toml/requirements.txt, or @anthropic-ai/claude-agent-sdk in package.json. Their presence → existing project.
Phase 2 — Confirm Language
The SDK has two first-class implementations with non-identical APIs:
- Python:
claude_agent_sdk, async-first,from claude_agent_sdk import query, ClaudeAgentOptions - TypeScript:
@anthropic-ai/claude-agent-sdk, async iterator,import { query } from "@anthropic-ai/claude-agent-sdk"
Snake_case in Python (allowed_tools, max_turns) vs camelCase in TypeScript (allowedTools, maxTurns). When the user does not specify, infer from the project's pyproject.toml vs package.json; if neither exists, ask before writing code.
Phase 3 — Load Documentation (mandatory)
The full official documentation is mirrored at docs/claude-agent-sdk/ (relative to the repo root that hosts this skill). Always consult it before writing non-trivial SDK code — the SDK evolves quickly and the API surface is broad.
Map the task to the right document using references/doc-index.md. Quick orientation:
| Task | Document |
| Hello world, install, first agent | docs/claude-agent-sdk/quickstart.md |
| Capabilities map, decision tree vs Client SDK | docs/claude-agent-sdk/overview.md |
| Message lifecycle, turns, compaction | docs/claude-agent-sdk/agent-loop.md |
| Full API reference | docs/claude-agent-sdk/python.md or typescript.md |
| Hooks, MCP, subagents, sessions, permissions, streaming, structured output, custom tools | docs/claude-agent-sdk/<topic>.md |
For full category mapping, read references/doc-index.md.
Phase 4 — Configure the Agent
Decide configuration before coding. Walk through these dimensions in order; each maps to a doc:
- Tools — built-in (
Read,Edit,Bash,Glob,Grep) vs custom MCP tools. Start minimal. - Permissions —
permission_mode+allowed_tools/disallowed_tools. Readreferences/pitfalls.mdfirst — the interaction betweenbypassPermissionsandallowed_toolsis the #1 source of "tool unexpectedly denied/approved" bugs. - System prompt —
claude_codepreset (default) vs custom. Seemodifying-system-prompts.md. - Hooks — only if interception/transformation is required. See
hooks.md. - Sessions — resume/fork only if multi-turn persistence is needed. See
sessions.md. - Streaming —
include_partial_messagesfor real-time UX. Seestreaming-output.md. - Cost limits — set
max_budget_usdfor any production-facing agent. Seecost-tracking.md.
Phase 5 — Implement
Apply these rules:
- Minimal options first. Start with
query(prompt=..., options=ClaudeAgentOptions(allowed_tools=[...])). Add complexity (hooks, subagents, custom tools) only when the minimal version works. - Handle messages by type. Iterate the stream and dispatch on
SystemMessage/AssistantMessage/UserMessage/ResultMessage. Never assume the first message is the result. Seereferences/concepts.md. - Check
ResultMessage.subtype. Values like"success_max_turns","success_max_budget"mean the loop hit a limit, not that the task finished cleanly. - Use working examples as scaffolding. Copy from
examples/minimal-python/orexamples/minimal-typescript/and adapt. - Delegate the write-and-verify loop to the builder subagent for non-trivial work. When the task involves writing new SDK files, extending an existing SDK agent, or debugging SDK-specific failures, dispatch the
claude-agent-sdk-builderagent. The builder is part of the standalone agents collection (~/.claude/agents/claude-agent-sdk-builder.mdafter install) and is fully self-contained — it bundles its own copy of the SDK documentation and does not depend on this skill. Dispatching it keeps doc snippets and trial output out of the main conversation. Reserve inline implementation for one-liners or trivial edits.
For task-specific recipes (bug-fixer agent, code reviewer, structured-output extractor, multi-subagent pipeline), see references/task-recipes.md.
Phase 6 — Validate
Before declaring done:
- Run the agent end-to-end against a real prompt. Token/cost reports must appear in
ResultMessage. - Verify the agent stops on its own (no infinite tool-calling loop). If it loops, set
max_turnsand re-run. - If
permission_modeis set, test a tool that should be denied and one that should be allowed — both paths. Permission bugs are silent. - For production agents, confirm
max_budget_usdis set and there is acanUseToolcallback (seeuser-input.md) for any path that needs human approval.
Documentation Navigation
references/doc-index.md is the authoritative map from intent → document. When in doubt about which doc to read, consult it first.
Core Concepts (quick reference)
Detailed in references/concepts.md:
query()is the only entry point. Returns an async iterator of messages. The loop runs inside the SDK; code consumes the stream.- Five message types.
SystemMessage(lifecycle),AssistantMessage(Claude's text + tool calls),UserMessage(tool results fed back),StreamEvent(partial, opt-in),ResultMessage(terminal, with cost/session). - Turns, not requests. One turn = one Claude response + tool execution.
max_turnscounts tool-using turns. Without limits, open-ended prompts can loop indefinitely. allowed_tools≠ constraint. It pre-approves listed tools; unlisted tools still run ifpermission_modeallows. Usedisallowed_toolsto actually block.- Python checks types with
isinstance(); TypeScript checksmessage.type === "result"etc.AssistantMessage.message.content(TS) vsmessage.content(Py).
Common Pitfalls
Top issues, summarized. Full list with fixes in references/pitfalls.md:
bypassPermissions+allowed_tools=["Read"]still approves every tool.allowed_toolsonly pre-approves; it does not constrainbypassPermissions. Usedisallowed_toolsto block specific tools.- Subagent results appear as
UserMessage, notAssistantMessage. When the main agent invokes theAgenttool, the subagent's final output is wrapped as aUserMessagecarrying aToolResultBlock. ResultMessageis not always the last message. A few trailing system events (prompt_suggestion) can arrive after it. Iterate the stream to completion.subtype≠"success"does not mean crashed. It means a limit was hit. Inspect the subtype string to know which.- MCP tool names in
allowed_toolsmust use themcp__<server>__<tool>form. Bare names are ignored with a startup warning.
Additional Resources
Reference Files (in this skill)
references/doc-index.md— Intent → document map. Read first when deciding which doc to consult.references/task-recipes.md— Copy-adapt recipes: bug fixer, code reviewer, structured-output extractor, multi-subagent pipeline, session resume.references/concepts.md— Core concepts deep-dive: message types, turns, permissions flow, hooks lifecycle, sessions model.references/pitfalls.md— Top pitfalls with verified fixes and the source doc each came from.
Official Documentation (mirrored)
All 30 official docs at docs/claude-agent-sdk/ (relative to the repo root). When the local mirror is stale or missing, fetch fresh from https://code.claude.com/docs/en/agent-sdk/<page>.md (append .md to any page URL).
Examples (in this skill)
examples/minimal-python/main.py— Smallest runnable Python agent.examples/minimal-typescript/main.ts+package.json— Smallest runnable TypeScript agent.
Use these as scaffolding for new projects; copy and adapt rather than starting from a blank file.
Builder Subagent (standalone, lives in the agents collection)
claude-agent-sdk-builder— Execution specialist for writing and verifying SDK code. Dispatch it from Phase 5 when the implementation is non-trivial. The agent is part of the standalone agents collection, installed to~/.claude/agents/. It is fully self-contained: it bundles its own copy of the SDK docs atagents/docs/claude-agent-sdk/and has no runtime dependency on this skill. Skill and agent are intentionally isolated so each can be installed and used without the other.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

