Back to skills
SKILL.md
Collection
CSecurityBuild production AI agents using the Claude Agent SDK (TypeScript/Python). Use this skill when the user asks about: (1) Building AI agents with Claude, (2) Using the @anthropic-ai/claude-agent-sdk or claude-agent-sdk packages, (3) Implementing agent features like tools, hooks, subagents, MCP integration, or sessions, (4) Migrating from Claude Code SDK to Agent SDK, (5) Configuring permissions, budgets, or custom tool access.
- 24 stars
- 0 votes
- 0 copies
- 0 views
- Added September 8, 2026
Works with
Security analysis
63/100- Pipes output to a shell interpreter
- Uses curl or wget to download content
- Downloads and executes remote scripts — classic supply chain attack
- Installs packages at runtime which could introduce malicious dependencies
- Installs packages at runtime which could introduce malicious dependencies
Pro scans all 21 files and shows the line behind each finding
npx -y skills add mattnigh/skills_collection --skill collection --agent claude-codeAre you the author of Collection?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/mattnigh-collection-2a232df9)---
name: claude-agent-sdk
description: "Build production AI agents using the Claude Agent SDK (TypeScript/Python). Use this skill when the user asks about: (1) Building AI agents with Claude, (2) Using the @anthropic-ai/claude-agent-sdk or claude-agent-sdk packages, (3) Implementing agent features like tools, hooks, subagents, MCP integration, or sessions, (4) Migrating from Claude Code SDK to Agent SDK, (5) Configuring permissions, budgets, or custom tool access."
---
# Claude Agent SDK
Build AI agents that autonomously read files, run commands, search the web, edit code, and more. The Agent SDK provides the same tools, agent loop, and context management that power Claude Code, programmable in Python and TypeScript.
## Installation
### Prerequisites
Install Claude Code runtime first:
```bash
# macOS/Linux/WSL
curl -fsSL https://claude.ai/install.sh | bash
# or via npm
npm install -g @anthropic-ai/claude-code
```
### SDK Installation
```bash
# TypeScript
npm install @anthropic-ai/claude-agent-sdk
# Python
pip install claude-agent-sdk
```
### API Key
```bash
export ANTHROPIC_API_KEY=your-api-key
```
Alternative authentication:
- **Amazon Bedrock**: `CLAUDE_CODE_USE_BEDROCK=1`
- **Google Vertex AI**: `CLAUDE_CODE_USE_VERTEX=1`
- **Microsoft Foundry**: `CLAUDE_CODE_USE_FOUNDRY=1`
## Basic Usage
### TypeScript
```typescript
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const message of query({
prompt: "Find and fix the bug in auth.py",
options: { allowedTools: ["Read", "Edit", "Bash"] }
})) {
if ("result" in message) console.log(message.result);
}
```
### Python
```python
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
async for message in query(
prompt="Find and fix the bug in auth.py",
options=ClaudeAgentOptions(allowed_tools=["Read", "Edit", "Bash"])
):
if hasattr(message, "result"):
print(message.result)
asyncio.run(main())
```
## Built-in Tools
| Tool | Description |
|------|-------------|
| **Read** | Read any file in the working directory |
| **Write** | Create new files |
| **Edit** | Make precise edits to existing files |
| **Bash** | Run terminal commands, scripts, git operations |
| **Glob** | Find files by pattern (`**/*.ts`, `src/**/*.py`) |
| **Grep** | Search file contents with regex |
| **WebSearch** | Search the web for current information |
| **WebFetch** | Fetch and parse web page content |
| **Task** | Spawn subagents for specialized tasks |
## Key Features
For detailed API reference and examples:
- **TypeScript**: See [references/typescript-api.md](references/typescript-api.md)
- **Python**: See [references/python-api.md](references/python-api.md)
### Permission Modes
- `default`: Standard permission checks
- `acceptEdits`: Automatically approve file edits
- `bypassPermissions`: Skip all permission checks (use with caution)
### Sessions
Resume conversations with full context:
```typescript
// Capture session ID from init message
if (message.type === 'system' && message.subtype === 'init') {
sessionId = message.session_id;
}
// Resume later
for await (const message of query({
prompt: "Continue where we left off",
options: { resume: sessionId }
})) { ... }
```
### MCP Integration
Connect external tools via Model Context Protocol:
```typescript
const response = query({
prompt: "Open example.com and describe what you see",
options: {
mcpServers: {
playwright: { command: "npx", args: ["@playwright/mcp@latest"] }
}
}
});
```
### Subagents
Spawn specialized agents for focused tasks:
```typescript
const response = query({
prompt: "Use the code-reviewer agent to review this codebase",
options: {
allowedTools: ["Read", "Glob", "Grep", "Task"],
agents: {
"code-reviewer": {
description: "Expert code reviewer for quality and security reviews.",
prompt: "Analyze code quality and suggest improvements.",
tools: ["Read", "Glob", "Grep"]
}
}
}
});
```
### Hooks
Run custom code at key points in the agent lifecycle:
- `PreToolUse`, `PostToolUse`
- `Stop`, `SessionStart`, `SessionEnd`
- `UserPromptSubmit`
### Budget Control
```typescript
const response = query({
prompt: "Analyze the codebase",
options: {
maxBudgetUsd: 2.5 // Stop if cost exceeds $2.50
}
});
```
### Project Skills
Load custom skills from `.claude/commands/`:
```typescript
const response = query({
prompt: "Review the pull request using available skills",
options: {
settingSources: ["project"] // Loads skills from .claude/commands/
}
});
```
## Message Types
The SDK streams various message types:
- `system` (subtype `init`): Session initialization with `session_id`
- `assistant`: Claude's text responses and tool calls
- `user`: Tool results and user input
- `result`: Final response with execution stats
- `error`: Error information
## Available Models
- `claude-opus-4-5-20251101` - Most capable
- `claude-sonnet-4-20250514` - Balanced (default)
- `claude-sonnet-4-5-20250929` - Latest Sonnet
- `claude-haiku-4-5-20251001` - Fastest
## SDK vs Client SDK
The **Agent SDK** handles tool loops autonomously:
```typescript
// Agent SDK: Claude handles tools autonomously
for await (const message of query({ prompt: "Fix the bug in auth.py" })) {
console.log(message);
}
```
The **Client SDK** requires you to implement tool execution:
```typescript
// Client SDK: You implement the tool loop
let response = await client.messages.create({...});
while (response.stop_reason === "tool_use") {
const result = yourToolExecutor(response.tool_use);
response = await client.messages.create({ tool_result: result, ... });
}
```
## Resources
- [TypeScript SDK GitHub](https://github.com/anthropics/claude-agent-sdk-typescript)
- [Python SDK GitHub](https://github.com/anthropics/claude-agent-sdk-python)
- [Example Agents](https://github.com/anthropics/claude-agent-sdk-demos)
Files in this skill
- 0Chan-smc__claude-code-workflow-lab__claude__skills__frontend-dev-guidelines__SKILL.md
- 17hz__nextjs-template__claude__skills__example-skill__SKILL.md
- 1ambda__dataops-platform__claude__skills__context-synthesis__SKILL.md
- 1natsu172__dotfiles__claude__skills__git-analysis__SKILL.md
- 1natsu172__dotfiles__claude__skills__github-pr-best-practices__SKILL.md
- 23Maestro__prospect-pipeline__claude__skills__npid-fastapi-skill.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-code-javascript__SKILL.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-code-python__SKILL.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-expression-syntax__SKILL.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-mcp-tools-expert__SKILL.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-node-configuration__SKILL.md
- 360AYA25__ClaudeN8N__claude__skills__n8n-workflow-patterns__SKILL.md
- 3x-Projetos__claude-memory-framework__claude__skills__scientist__SKILL.md
- 5MinFutures__futures-arena__claude__skills__migration-tracker__SKILL.md
- 5MinFutures__futures-arena__claude__skills__planning-guidelines__SKILL.md
- 92Bilal26__TaskPilotAI__claude__skills__assessment-builder__SKILL.md
- 92Bilal26__TaskPilotAI__claude__skills__book-scaffolding__SKILL.md
- 92Bilal26__TaskPilotAI__claude__skills__code-validation-sandbox__SKILL.md
- 92Bilal26__TaskPilotAI__claude__skills__exercise-designer__SKILL.md
- 92Bilal26__TaskPilotAI__claude__skills__learning-objectives__SKILL.md
Attribution
Comments
Loading comments…