claude-agent-sdk
Decisions, patterns and pitfalls for building agents with the Claude Agent SDK (TypeScript package @anthropic-ai/claude-agent-sdk, Python package…
от fcsouza★ 29 звёзд на GitHub
Установить claude-agent-sdk в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Claude Agent SDK
The SDK runs the Claude Code binary as a subprocess and talks to it over stdio. Your code configures it and reads a stream of messages. Versions checked on 2026-11-15: @anthropic-ai/claude-agent-sdk 0.3.325, claude-agent-sdk 0.2.182 (Python 3.10+; Node 18.14+).
Use the official docs for the API
For the Messages API, use the claude-api skill if it is installed. For this SDK there is no official skill, so read the docs. Fetch the index at https://code.claude.com/docs/llms.txt and open the Agent SDK pages as .md. Start with these:
- Options and types: https://code.claude.com/docs/en/agent-sdk/typescript.md and https://code.claude.com/docs/en/agent-sdk/python.md
- Permissions: https://code.claude.com/docs/en/agent-sdk/permissions.md
- Hooks: https://code.claude.com/docs/en/agent-sdk/hooks.md
- Subagents: https://code.claude.com/docs/en/agent-sdk/subagents.md
- Custom tools and MCP: https://code.claude.com/docs/en/agent-sdk/custom-tools.md and https://code.claude.com/docs/en/agent-sdk/mcp.md
- Sessions and storage: https://code.claude.com/docs/en/agent-sdk/sessions.md and https://code.claude.com/docs/en/agent-sdk/session-storage.md
- Hosting and security: https://code.claude.com/docs/en/agent-sdk/hosting.md and https://code.claude.com/docs/en/agent-sdk/secure-deployment.md
- Model IDs: https://platform.claude.com/docs/en/about-claude/models/overview.md
- Structured output: https://code.claude.com/docs/en/agent-sdk/structured-outputs.md
- Cost and usage tracking: https://code.claude.com/docs/en/agent-sdk/cost-tracking.md
- Streaming input, interrupts and images: https://code.claude.com/docs/en/agent-sdk/streaming-vs-single-mode.md
AskUserQuestionand approvals: https://code.claude.com/docs/en/agent-sdk/user-input.md- Pre-warming a subprocess with
startup()orprewarm()(TypeScript only): the "startup" and "prewarm" sections of the TypeScript reference above
Do not copy option tables, hook-event lists or type definitions into answers from memory. They change with each release. Open the page, then quote the field name.
Pick the runtime first
- Agent SDK: your process runs Claude Code's loop, tools, permissions and sessions. Use it for coding agents, CI agents and file-and-shell work.
- Client SDK (Messages API): you write the tool loop yourself. Use it when you need no built-in file or shell tools.
- Managed Agents: Anthropic hosts the loop and the sandbox. Use it when you do not want to operate containers.
- Another language: run
claude -p --output-format jsonas a subprocess.
Entry points
query()starts a new session on every call. Use it for one-off and CI tasks. For multi-turn in TypeScript, pass anAsyncIterableof user messages asprompt, or passcontinue: true/resume: sessionId.ClaudeSDKClient(Python) keeps one session acrossclient.query()calls and supportsinterrupt().- The TypeScript V2 session API (
unstable_v2_*) was removed in 0.3.142. Do not use it. Usequery(). - Always branch on
ResultMessage.subtypebefore readingresult.successis the only subtype that carries a final answer. The others areerror_max_turns,error_max_budget_usd,error_during_executionanderror_max_structured_output_retries.
Copy templates/ci-agent.ts (TypeScript) or templates/agent.py (Python) when you need a headless agent with caps and a result check.
Permissions
The SDK checks every tool call in six steps. The first step that decides wins:
- Hooks. A hook can deny or pass. A hook that returns
allowdoes not skip steps 2 and 3. - Deny rules (
disallowedTools, and deny rules from loaded settings files). They deny in every mode,bypassPermissionsincluded. - Ask rules (from settings.json). A match goes to
canUseTool, even inbypassPermissions. - Permission mode.
- Allow rules (
allowedTools, allow rules from settings). Safe reads inside the working directory also resolve here. canUseToolcallback. IndontAskmode this step is skipped and the call is denied.
What follows from that order:
allowedToolsapproves the tools it lists. It does not restrict Claude to them. Unlisted tools fall through to the mode andcanUseTool. To remove a tool, usedisallowedTools. A bare tool name there removes the tool definition. A pattern likeBash(rm *)keepsBashand denies matching calls.- An allow rule for a tool name hides that tool's calls from
canUseTool. If your callback must see them, remove the name fromallowedTools. The SDK warns with codeCLAUDE_SDK_CAN_USE_TOOL_SHADOWEDfor this and forbypassPermissions. - For headless agents use
dontAskwith an explicitallowedTools. A call that would need approval is then denied instead of waiting for a prompt that nobody answers. Calls that need no approval indefaultmode still run: reads in the working directory, read-only Bash commands, and others the permissions page lists. AdddisallowedToolsfor anything that must never run. - `bypa
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- references/bun-runtime.md
- references/sources.md
- templates/agent.py
- templates/bun-compile.ts
- templates/ci-agent.ts
- templates/embedded-binary.d.ts
- templates/guard-hook.ts
- templates/subagents.ts
- templates/tenant-isolation.ts
FAQ
Что делает скилл claude-agent-sdk?
Decisions, patterns and pitfalls for building agents with the Claude Agent SDK (TypeScript package @anthropic-ai/claude-agent-sdk, Python package claude-agent-sdk): permissions, settings isolation, subagents, hooks, custom tools, sessions, hosting. Use when writing or reviewing code that calls the SDK's query() or ClaudeSDKClient, or when deciding how to run, secure, cap or host such an agent.
Как установить скилл claude-agent-sdk?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл claude-agent-sdk запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…