TypeScript SDK Reference
БесплатноБез исполняемых скриптовНе проверенComprehensive reference for the TypeScript Agent SDK with functions, types, and interfaces for programmatic Claude Code interactions
Об этом скилле
TypeScript SDK Reference
A comprehensive reference for building applications with the Anthropic Agent SDK (TypeScript), enabling programmatic interactions with Claude Code and custom tool integrations.
Installation
npm install @anthropic-ai/claude-agent-sdk
Quick Start
Core Functions
| Function | Purpose | Key Use Case |
|---|---|---|
query() |
Primary interface for Claude Code interactions | Send prompts, stream responses, manage multi-turn conversations |
tool() |
Define MCP tools with type-safe schemas | Create custom tools for agents using Zod validation |
createSdkMcpServer() |
Create in-process MCP servers | Host tools natively in your application |
Example: Basic Query
import { query } from '@anthropic-ai/claude-agent-sdk';
const result = query({
prompt: "Analyze this code and suggest improvements",
options: {
allowedTools: ['Read', 'Grep'],
model: 'claude-opus'
}
});
for await (const message of result) {
if (message.type === 'assistant') {
console.log(message.message.content);
}
}
Main Functions Reference
query()
Streams Claude Code responses with full message type support. Returns an async generator of SDKMessage objects.
Parameters:
prompt: string or async iterable of messages (streaming mode)options: Configuration object (see Options below)
Returns: Query object (extends AsyncGenerator<SDKMessage, void>)
Key Methods:
.interrupt()– Interrupt streaming (streaming mode only).setPermissionMode(mode)– Change permissions dynamically (streaming mode only)
tool()
Creates type-safe MCP tool definitions using Zod schemas. Handlers receive validated inputs and must return CallToolResult.
Parameters:
name: Tool identifierdescription: Natural language descriptioninputSchema: Zod schema defining inputshandler: Async function(args: z.infer<Schema>, extra?: unknown) => Promise<CallToolResult>
Returns: SdkMcpToolDefinition<Schema>
createSdkMcpServer()
Creates an in-process MCP server for hosting custom tools. Runs in the same Node.js process—no subprocess overhead.
Parameters:
name: Server identifierversion: Optional semantic versiontools: Array of tool definitions fromtool()
Returns: McpSdkServerConfigWithInstance (ready for mcpServers option)
Key Configuration Options
Essential Options
| Option | Type | Default | Purpose |
|---|---|---|---|
allowedTools |
string[] |
All available | Restrict which tools Claude can use |
disallowedTools |
string[] |
[] |
Explicitly block tools |
model |
string |
CLI default | Override Claude model (e.g., 'claude-opus') |
cwd |
string |
process.cwd() |
Working directory for operations |
abortController |
AbortController |
New instance | Control task cancellation |
Advanced Options
| Option | Type | Default | Purpose |
|---|---|---|---|
systemPrompt |
string or preset object | None | Custom system instructions or Claude Code preset |
agents |
Record<string, AgentDefinition> |
undefined |
Programmatically define subagents with custom prompts |
mcpServers |
Record<string, McpServerConfig> |
{} |
Connect stdio, SSE, HTTP, or SDK MCP servers |
settingSources |
('user' | 'project' | 'local')[] |
[] |
Load filesystem settings (CLAUDE.md, settings.json) |
permissionMode |
PermissionMode |
'default' |
'default', 'acceptEdits', 'bypassPermissions', or 'plan' |
maxThinkingTokens |
number |
undefined |
Token limit for extended thinking |
maxTurns |
number |
undefined |
Maximum conversation turns before stopping |
resume |
string |
undefined |
Resume a previous session by ID |
forkSession |
boolean |
false |
Fork to new session on resume instead of continuing |
Message Types Overview
The query() generator yields SDKMessage objects. Common types:
| Message Type | When Emitted | Key Fields |
|---|---|---|
'system' |
Session initialization | tools, model, permissionMode, slash_commands |
'user' |
User input sent | message (APIUserMessage), uuid |
'assistant' |
Claude responds | message (APIAssistantMessage with content/tool_use) |
'result' |
Query completes | subtype ('success' or error), usage, total_cost_usd |
'stream_event' |
Partial streaming data | event (only if includePartialMessages: true) |
See Message Types Reference for complete definitions.
Types Reference Overview
Core Configuration Types
Options– Query configuration with 20+ properties (Tools, MCP, permissions, execution)PermissionMode– Control execution permissions:'default','acceptEdits','bypassPermissions','plan'
Установить TypeScript SDK Reference в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadWriteEditTaskВложенные файлы
FAQ
Что делает скилл TypeScript SDK Reference?
Comprehensive reference for the TypeScript Agent SDK with functions, types, and interfaces for programmatic Claude Code interactions
Как установить скилл TypeScript SDK Reference?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл TypeScript SDK Reference запускает скрипты?
Нет, скилл состоит только из инструкций (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