claude-agent-sdk
БесплатноБез исполняемых скриптовНе проверенThis skill provides comprehensive knowledge for working with the Anthropic Claude Agent SDK. It should be used when building autonomous AI agents, creating…
Об этом скилле
Claude Agent SDK
Status: Production Ready Last Updated: 2025-10-25 Dependencies: @anthropic-ai/claude-agent-sdk, zod Latest Versions: @anthropic-ai/[email protected]+, [email protected]+
Quick Start (5 Minutes)
1. Install SDK
npm install @anthropic-ai/claude-agent-sdk zod
Why these packages:
@anthropic-ai/claude-agent-sdk- Main Agent SDKzod- Type-safe schema validation for tools
2. Set API Key
export ANTHROPIC_API_KEY="sk-ant-..."
CRITICAL:
- API key required for all agent operations
- Never commit API keys to version control
- Use environment variables
3. Basic Query
import { query } from "@anthropic-ai/claude-agent-sdk";
const response = query({
prompt: "Analyze the codebase and suggest improvements",
options: {
model: "claude-sonnet-4-5",
workingDirectory: process.cwd(),
allowedTools: ["Read", "Grep", "Glob"]
}
});
for await (const message of response) {
if (message.type === 'assistant') {
console.log(message.content);
}
}
The Complete Claude Agent SDK Reference
Table of Contents
- Core Query API
- Tool Integration
- MCP Servers
- Subagent Orchestration
- Session Management
- Permission Control
- Filesystem Settings
- Message Types & Streaming
- Error Handling
- Known Issues
Core Query API
The query() Function
The primary interface for interacting with Claude Code CLI programmatically.
import { query } from "@anthropic-ai/claude-agent-sdk";
const response = query({
prompt: string | AsyncIterable<SDKUserMessage>,
options?: Options
});
// Response is AsyncGenerator<SDKMessage, void>
for await (const message of response) {
// Process streaming messages
}
Basic Options
const response = query({
prompt: "Review this code for bugs",
options: {
model: "claude-sonnet-4-5", // or "haiku", "opus"
workingDirectory: "/path/to/project",
systemPrompt: "You are a security-focused code reviewer.",
allowedTools: ["Read", "Grep", "Glob"],
disallowedTools: ["Write", "Edit", "Bash"],
permissionMode: "default" // or "acceptEdits", "bypassPermissions"
}
});
Model Selection
| Model | ID | Best For | Speed | Capability |
|---|---|---|---|---|
| Haiku | "haiku" |
Fast tasks, monitoring | Fastest | Basic |
| Sonnet | "sonnet" or "claude-sonnet-4-5" |
Balanced | Medium | High |
| Opus | "opus" |
Complex reasoning | Slowest | Highest |
| Inherit | "inherit" |
Use parent model | - | - |
Default: "sonnet" if not specified
System Prompts
const response = query({
prompt: "Implement user authentication",
options: {
systemPrompt: `You are an expert backend developer.
Follow these principles:
- Always use TypeScript with strict types
- Implement comprehensive error handling
- Add detailed logging for debugging
- Write unit tests for all functions
- Follow OWASP security guidelines`
}
});
CRITICAL:
- System prompt sets agent behavior for entire session
- Should be clear and specific
- Can be 1-10k tokens (affects context window)
Working Directory
const response = query({
prompt: "Refactor the user service",
options: {
workingDirectory: "/Users/dev/projects/my-app",
// Agent operates within this directory
// Relative paths resolved from here
}
});
Best Practices:
- Use absolute paths for clarity
- Agent stays within this directory scope
- Critical for multi-project environments
Tool Integration (Built-in + Custom)
Built-in Tools
The SDK provides access to Claude Code's built-in tools:
| Tool | Description | Use Case |
|---|---|---|
Read |
Read file contents | Code analysis |
Write |
Create new files | Generate code |
Edit |
Modify existing files | Refactoring |
Bash |
Execute shell commands | Run tests, git |
Grep |
Search file contents | Find patterns |
Glob |
Find files by pattern | File discovery |
WebSearch |
Search the web | Research |
WebFetch |
Fetch URL content | Documentation |
Task |
Delegate to subagent | Orchestration |
Allowing/Disallowing Tools
// Whitelist approach (recommended)
const response = query({
prompt: "Analyze code but don't modify anything",
options: {
allowedTools: ["Read", "Grep", "Glob"]
// ONLY these tools can be used
}
});
// Blacklist approach
const response = query({
prompt: "Review and fix issues",
options: {
disallowedTools: ["Bash"]
// Everything except Bash allowed
}
});
// Combination (allowedTools tak
Установить claude-agent-sdk в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл claude-agent-sdk?
This skill provides comprehensive knowledge for working with the Anthropic Claude Agent SDK. It should be used when building autonomous AI agents, creating multi-step reasoning workflows, orchestrating specialized subagents, integrating custom tools and MCP servers, or implementing production-ready agentic systems with Claude Code's capabilities. Use when building coding agents, SRE systems, security auditors, incident responders, code review bots, or any autonomous system that requires programmatic interaction with Claude Code CLI, persistent sessions, tool orchestration, and fine-grained permission control. Keywords: claude agent sdk, @anthropic-ai/claude-agent-sdk, query(), createSdkMcpServer, AgentDefinition, tool(), claude subagents, mcp servers, autonomous agents, agentic loops, session management, permissionMode, canUseTool, multi-agent orchestration, settingSources, CLI not found, context length exceeded
Как установить скилл claude-agent-sdk?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл claude-agent-sdk запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic