Help us improve
Share bugs, ideas, or general feedback.
From skills
Build Python workflows and agents using the Claude Agent SDK (claude-agent-sdk). Use this skill whenever the user wants to create, design, or debug agent workflows, multi-agent systems, automation scripts, or any Python code that uses the Claude Agent SDK (formerly Claude Code SDK). Trigger on mentions of: "agent sdk", "claude-agent-sdk", "claude_agent_sdk", "query()", "ClaudeSDKClient", "subagents", "AgentDefinition", "agent workflow", "multi-agent", "claude code sdk", or any request to build an autonomous agent that reads files, runs commands, edits code, or orchestrates tasks programmatically. Also trigger when the user asks about architecting agent systems, choosing between SDK patterns, or integrating custom tools/hooks/MCP servers with the Agent SDK. Even if the user just says "build me an agent" or "automate this with Claude", use this skill.
npx claudepluginhub jewunetie/skillsHow this skill is triggered — by the user, by Claude, or both
Slash command
/skills:cc-agent-sdk-workflowsThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Build production Python agents and workflows using the Claude Agent SDK.
Mandates invoking relevant skills via tools before any response in coding sessions. Covers access, priorities, and adaptations for Claude Code, Copilot CLI, Gemini CLI.
Share bugs, ideas, or general feedback.
Build production Python agents and workflows using the Claude Agent SDK.
references/api-reference.md for types, signatures, and defaults.references/patterns.md for the workflow template closest to the user's need.references/gotchas.md to avoid common mistakes.Only after reading the relevant references should you write or propose code.
When deeper detail is needed beyond what these references provide:
If you are uncertain about any SDK behavior, fetch the relevant documentation page before generating code rather than guessing.
Use this flowchart to choose the right SDK pattern for the user's workflow.
Ask: Does the workflow need multi-turn conversation or response-driven branching?
query().ClaudeSDKClient.Also use ClaudeSDKClient if the workflow needs any of:
Note: Hooks and custom MCP tools work with both query() and ClaudeSDKClient
(they are configured via ClaudeAgentOptions which both interfaces accept). The SDK
reference comparison table may list these as ClaudeSDKClient-only, but official
examples demonstrate them working with query(). When in doubt, prefer
ClaudeSDKClient for complex workflows combining multiple features.
Ask: Is the task a single coherent job, or does it have distinct subtasks that benefit from isolated context, parallelism, or specialized prompts?
query() or ClaudeSDKClient).AgentDefinition. Include
"Task" in allowed_tools on the parent agent.Subagents are valuable when:
Ask: Does the workflow need to call external services, APIs, or custom logic?
@tool +
create_sdk_mcp_server(). These run in-process with no subprocess overhead.mcp_servers as stdio, SSE, or HTTP
configs. Can be mixed with SDK MCP servers.Ask: Does the workflow need guardrails, logging, or behavior modification?
can_use_tool callback on ClaudeAgentOptions.permission_mode="acceptEdits" or
"bypassPermissions" as appropriate.Ask: Does the workflow need structured, machine-readable output?
output_format={"type": "json_schema", "schema": {...}} in options.Ask: Should commands run in a restricted sandbox?
sandbox={"enabled": True, ...} in options.Think of agents like functions: each should have a single, clear responsibility. A good decomposition follows these heuristics:
Choose the most restrictive mode that still lets the workflow function:
"default" -- Prompts for each tool use. Good for interactive sessions."acceptEdits" -- Auto-accepts file reads/writes. Good for automation scripts."bypassPermissions" -- No permission checks. Use only in trusted, sandboxed
environments.can_use_tool callback -- Fine-grained control per tool invocation.query() creates a fresh session every call. No state carries over.ClaudeSDKClient maintains session state across multiple .query() calls.resume=session_id in options.resume=session_id + fork_session=True.setting_sources=["project"].Every workflow should:
CLINotFoundError -- the Claude Code CLI is bundled but may not be available.ProcessError -- includes exit_code and stderr for debugging.CLIJSONDecodeError -- malformed output from the CLI.ResultMessage for monitoring.ResultMessage includes total_cost_usd, usage, duration_ms, and num_turns.
Always capture these for production workflows. For subagents, the Task tool output
includes its own total_cost_usd and duration_ms.
When generating SDK workflow code, always:
asyncio.run(main()) as the entry point (or anyio.run(main) if the user
prefers anyio).ResultMessage fields (cost, duration, session_id).description fields in AgentDefinition so Claude knows when to
invoke each subagent.permission_mode explicitly rather than relying on the default.setting_sources loads anything by default -- it does not."Task" in allowed_tools.async with ClaudeSDKClient() as client: context manager for lifecycle.Use this to calibrate response depth:
Tier 1 -- Simple script (query-based, single agent, built-in tools only): Generate a single Python file. Minimal boilerplate.
Tier 2 -- Interactive agent (ClaudeSDKClient, multi-turn, maybe hooks): Generate a single Python file with a class or structured functions.
Tier 3 -- Multi-agent system (subagents, custom tools, hooks, MCP): Propose a file structure first. Separate concerns: agent definitions, tool definitions, hook definitions, main orchestrator. Confirm structure with user before generating.