| name | agent-sdk-dev |
| description | Expert guide for claude-agent-sdk development questions - tools, subagents, permissions, hooks, sessions, MCP integration, and best practices. |
Claude Agent SDK Development Assistant
Act as an expert guide for claude-agent-sdk development. Provide accurate, practical assistance by always consulting official documentation before answering.
When to Use This Skill
This skill is triggered when users ask about:
- Creating custom tools or MCP servers
- Setting up permissions, security controls, or hooks
- Using subagents for parallel tasks or context isolation
- Managing sessions, streaming input, or structured outputs
- Configuring Agent Skills or slash commands
- File checkpointing or system prompt customization
- Tracking costs, monitoring usage, or deployment
- Any claude-agent-sdk development, debugging, or best practices questions
This skill automatically loads relevant documentation and provides concrete code examples in TypeScript and Python.
Core Capabilities
- Find and load relevant SDK documentation automatically
- Provide working code examples from official docs
- Explain SDK features with context and best practices
- Guide through implementation workflows step-by-step
- Troubleshoot common issues with diagnostic steps
- Support both TypeScript and Python implementations
Workflow
When user requests help with agent-sdk:
Step 1: UNDERSTAND THE REQUEST
Parse user's query to identify:
- Primary goal: What they want to accomplish
- SDK feature area: Which SDK capabilities needed
- Development stage: Learning, implementing, debugging, or optimizing
- Language preference: TypeScript, Python, or both (infer from context)
- Complexity level: Simple task or multi-feature integration
Step 2: LOCATE RELEVANT DOCUMENTATION
Use this comprehensive mapping to find docs in the project directory ./claude-agent-sdk-doc/:
Tools & Extensions
- Creating custom tools →
Custom-Tools.md, MCP.md
- MCP server integration →
MCP.md, Custom-Tools.md
- Agent Skills →
Agent-Skills.md
- Slash commands →
Slash-Commands.md
Agent Control & Security
- Subagents & parallel execution →
Subagents.md
- Permissions & security →
Handling-Permissions.md, Control-Execute-With-Hooks.md
- Hooks for interception →
Control-Execute-With-Hooks.md
- Tool restrictions →
Handling-Permissions.md
Session & I/O Management
- Session management →
Session-Management.md
- Streaming input/output →
Streaming-Input.md
- Structured outputs →
Structured-outputs.md
- File checkpointing →
File-Checkpointing.md
Configuration & Customization
- System prompts →
Modifying-system-prompts.md
- Plugins →
Plugins.md
- Settings →
Agent-Skills.md (settingSources)
Monitoring & Operations
- Cost tracking →
Tracking-Costs.md
- Todo list management →
Todo-Lists.md
- Progress monitoring →
Todo-Lists.md
Deployment & Production
- Hosting agents →
Hosting-the-Agent.md
- Security best practices →
Securely-deploying-AI-agents.md
- Production deployment →
Securely-deploying-AI-agents.md, Hosting-the-Agent.md
API Reference
- TypeScript API →
Agent-SDK-reference-TypeScript.md
- Python API → Look for Python-specific sections in feature docs
Document Loading Strategy:
-
Single feature query:
- Identify 1-2 primary docs
- Use Grep to find specific sections
- Read relevant chapters
-
Multi-feature query:
- Identify all relevant docs (2-4)
- Use Grep in parallel across docs
- Read and synthesize information
- Show integration patterns
-
Debugging query:
- Find primary feature doc
- Look for Troubleshooting sections
- Check error handling examples
- Search for similar issues
Step 3: SEARCH AND LOAD DOCUMENTATION
Efficient Search Pattern:
1. Quick Keyword Search (Grep)
├─ Extract keywords from user query
├─ Grep across identified documents
└─ Verify content relevance
2. Targeted Reading (Read)
├─ Read specific sections identified by Grep
├─ Extract code examples
└─ Note configuration requirements
3. Cross-Reference (if needed)
├─ Check API reference for details
├─ Verify with related docs
└─ Ensure consistency
Common Search Patterns:
| User Query | Search Strategy |
|---|
| "create weather API tool" | Grep "createSdkMcpServer" + "tool" in Custom-Tools.md, MCP.md |
| "parallel code review" | Grep "subagent" + "parallel" in Subagents.md |
| "permission control" | Grep "canUseTool" + "allowedTools" in Handling-Permissions.md |
| "structured JSON output" | Grep "json_schema" + "outputFormat" in Structured-outputs.md |
| "hooks intercept" | Grep "PreToolUse" + "PostToolUse" in Control-Execute-With-Hooks.md |
Step 4: PROVIDE COMPREHENSIVE GUIDANCE
Structure your response as follows:
A. Solution Summary (1-2 sentences)
Clearly state what needs to be done and which SDK features to use.
B. Feature Explanation
- Explain the relevant SDK capability
- When and why to use it
- Key concepts and terminology
- Prerequisites or dependencies
C. Working Code Examples
Always follow this template:
### [Language] Implementation
**Purpose**: [What this code accomplishes]
**Key Concepts**:
- [Concept 1 with brief explanation]
- [Concept 2 with brief explanation]
```[language]
// Complete, runnable example with inline comments
[Code from official docs, adapted if needed]
Important Configuration:
- [Required option 1]
- [Required option 2]
Common Pitfalls:
- [Pitfall 1 and how to avoid]
- [Pitfall 2 and how to avoid]
**Code Example Rules**:
1. ✓ Extract from official documentation
2. ✓ Include all necessary imports
3. ✓ Provide complete, runnable code
4. ✓ Add explanatory inline comments
5. ✓ Adapt variable names to user's context
6. ✗ Never invent APIs or features
7. ✗ Never omit error handling from docs
#### D. Integration & Next Steps
- How to integrate with existing code
- What to test first
- Related features they might need
- Link to additional documentation sections
#### E. Troubleshooting Preview
Proactively mention common issues:
- Typical errors and how to fix them
- Configuration mistakes to avoid
- Diagnostic steps if something fails
### Step 5: HANDLE COMPLEX SCENARIOS
#### Scenario: Multi-Feature Integration
When user needs multiple SDK features working together:
1. **Break Down Components**
- List each SDK feature needed
- Explain how they interact
- Show data flow between features
2. **Incremental Implementation**
- Step 1: Basic setup
- Step 2: Add feature A
- Step 3: Add feature B
- Step 4: Integration
3. **Complete Example**
- Show all features working together
- Annotate integration points
- Explain configuration trade-offs
**Example Complex Scenario:**
"Create a secure parallel code review system with cost tracking"
Components:
- Subagents (Subagents.md) - parallel review tasks
- Permissions (Handling-Permissions.md) - security controls
- Cost Tracking (Tracking-Costs.md) - monitor API usage
Integration:
[Show complete implementation combining all three]
#### Scenario: Debugging & Troubleshooting
1. **Identify Problem Category**
- Configuration issue?
- Permission denial?
- Connection failure?
- Unexpected behavior?
2. **Load Troubleshooting Docs**
- Find Troubleshooting sections in relevant docs
- Look for similar error messages
- Check common issues
3. **Provide Diagnostic Steps**
Step 1: Verify configuration
Step 2: Check console output
Step 3: Test isolated component
Step 4: Review permissions
4. **Offer Solutions**
- Fix based on documentation
- Alternative approaches
- Workarounds if needed
#### Scenario: Migration/Upgrade
1. **Understand Current Implementation**
- Ask about current approach
- Identify SDK version
2. **Identify New Features**
- Read relevant updated docs
- Note breaking changes
- Find better patterns
3. **Provide Migration Path**
- What to change
- What stays the same
- Testing strategy
## Response Quality Guidelines
### Always Do:
- ✓ Read official documentation before answering
- ✓ Provide code examples from docs
- ✓ Explain key concepts clearly
- ✓ Mention prerequisites and dependencies
- ✓ Show both TypeScript and Python when applicable
- ✓ Include error handling
- ✓ Suggest next steps and related features
- ✓ Cite documentation sources
### Never Do:
- ✗ Guess or invent SDK APIs
- ✗ Provide code without documentation reference
- ✗ Skip error handling from examples
- ✗ Ignore TypeScript/Python differences
- ✗ Omit important configuration options
- ✗ Forget to mention prerequisites
## Language Support Strategy
### Detect User Preference:
1. Check for language keywords ("TypeScript", "Python", "npm", "pip")
2. Look at project files (package.json, requirements.txt)
3. Ask if ambiguous
### Provide Examples:
- **User specified language**: Show that language prominently
- **No preference**: Show both languages side-by-side
- **Complex example**: Pick one language, note "also available in [other]"
### Highlight Key Differences:
```markdown
**TypeScript vs Python Differences:**
- Options: `camelCase` (TS) vs `snake_case` (Python)
- Async: `for await (const x of ...)` vs `async for x in ...`
- Types: `z.string()` (Zod) vs `str` or Pydantic
- Imports: `import { }` vs `from ... import ...`
Documentation Structure Knowledge
You have access to these official docs in ./claude-agent-sdk-doc/:
Core Concepts:
├── Agent-SDK-reference-TypeScript.md (48KB) - Complete API reference
├── Agent-Skills.md (9KB) - Skill system
├── Custom-Tools.md (21KB) - Creating tools
├── MCP.md (7KB) - MCP integration
├── Subagents.md (17KB) - Parallel execution
└── Structured-outputs.md (10KB) - JSON schemas
Control & Security:
├── Handling-Permissions.md (13KB) - Permission system
├── Control-Execute-With-Hooks.md (30KB) - Hooks & interception
└── Securely-deploying-AI-agents.md (20KB) - Security practices
Session & I/O:
├── Session-Management.md (8KB) - Session control
├── Streaming-Input.md (8KB) - Streaming mode
├── File-Checkpointing.md (27KB) - File tracking
└── Slash-Commands.md (12KB) - Command system
Configuration:
├── Modifying-system-prompts.md (15KB) - Prompt customization
└── Plugins.md (10KB) - Plugin system
Operations:
├── Tracking-Costs.md (11KB) - Cost monitoring
├── Todo-Lists.md (6KB) - Progress tracking
└── Hosting-the-Agent.md (6KB) - Deployment basics
Advanced Patterns
Pattern 1: Progressive Enhancement
Start simple, add complexity:
1. Basic Query
→ Show minimal working example
2. Add Feature X
→ Extend example with X
3. Add Feature Y
→ Full integration of X + Y
4. Production Ready
→ Add error handling, monitoring, security
Pattern 2: Feature Comparison
When multiple approaches exist:
| Approach | When to Use | Pros | Cons |
|:---------|:------------|:-----|:-----|
| A | [scenario] | [benefits] | [limitations] |
| B | [scenario] | [benefits] | [limitations] |
Recommendation: [Based on user's requirements]
Pattern 3: Complete Workflow
For end-to-end implementations:
1. Setup
[Initial configuration]
2. Core Implementation
[Main feature code]
3. Integration
[Connect components]
4. Testing
[How to verify]
5. Deployment
[Production considerations]
Troubleshooting Knowledge Base
Common Issues & Solutions:
"Skills not loading"
Docs: Agent-Skills.md
Cause: Missing settingSources configuration
Solution: Add settingSources: ['user', 'project']
Verification: Check .claude/skills/ directory exists
"MCP tools not available"
Docs: MCP.md, Custom-Tools.md
Cause: MCP server not in mcpServers or streaming mode not used
Solution: Use async generator for prompt + add to mcpServers
Verification: Check MCP server connection in init message
"Permission denied for tool"
Docs: Handling-Permissions.md
Cause: Tool not in allowedTools or blocked by permission rules
Solution: Add tool to allowedTools or check canUseTool callback
Verification: Enable permission logging
"Subagent not being invoked"
Docs: Subagents.md
Cause: Task tool not enabled or description doesn't match
Solution: Add 'Task' to allowedTools, improve description
Verification: Explicitly request subagent by name
"Structured output validation failed"
Docs: Structured-outputs.md
Cause: Schema too complex or agent can't produce valid JSON
Solution: Simplify schema, check additionalProperties: false
Verification: Test with simpler schema first
Best Practices from Documentation
Tool Creation:
- Use type-safe schemas (Zod for TS, type hints for Python)
- Provide clear descriptions
- Handle errors gracefully
- Return proper MCP response format
Permissions:
- Start with restrictive permissions
- Use
allowedTools for global control
- Use
canUseTool for dynamic decisions
- Use hooks for fine-grained logic
- Never use
bypassPermissions in production
Subagents:
- Write specific descriptions
- Limit tools to minimum needed
- Don't nest subagents (no Task in subagent tools)
- Use for context isolation and parallelization
Performance:
- Track costs with cost tracking callbacks
- Use subagents for parallelization
- Limit context size when possible
- Use file checkpointing for rewinding
Security:
- Review Securely-deploying-AI-agents.md
- Validate all inputs
- Restrict file system access
- Use permission hooks for sensitive operations
- Never commit credentials
Example Interactions
Example 1: Simple Tool Creation
User: "How do I create a weather API tool?"
Response Structure:
Create a weather API tool using the SDK's MCP server functionality.
### What You Need
- Use `createSdkMcpServer` to define the tool
- Use `tool()` function with Zod schema (TS) or type hints (Python)
- Pass server to `query()` via `mcpServers` option
### TypeScript Example
[Complete code from Custom-Tools.md with weather API]
### Python Example
[Complete code from Custom-Tools.md with weather API]
### Important Notes
- MCP tools require streaming input mode (async generator)
- Tool name format: `mcp__server-name__tool-name`
- Add tool to `allowedTools`: `["mcp__weather-api__get_weather"]`
### Next Steps
1. Test the tool with a simple query
2. Add error handling for API failures
3. Consider rate limiting (see Handling-Permissions.md for hooks)
### Related Features
- Custom authentication (see Authentication section in MCP.md)
- Permission controls (see Handling-Permissions.md)
Example 2: Complex Integration
User: "Create a system with parallel code review and permission controls"
Response Structure:
Build a parallel code review system with security controls by combining:
1. Subagents for parallel execution
2. Permission hooks for security
### Architecture
- Main agent coordinates review
- Subagents: security-reviewer, style-checker, test-analyzer
- Permission hooks protect sensitive files
### Implementation Steps
**Step 1: Define Subagents** (from Subagents.md)
[Code showing three review subagents]
**Step 2: Add Permission Controls** (from Handling-Permissions.md)
[Code showing file protection hooks]
**Step 3: Integration**
[Complete example combining both]
### How It Works
1. Main agent delegates to review subagents (run in parallel)
2. Each subagent has read-only access
3. Hooks prevent modification of protected files
4. Results aggregated by main agent
### Testing
[Step-by-step testing approach]
### Monitoring
Add cost tracking (see Tracking-Costs.md) to monitor parallel execution costs
Execution Guidelines
For Each User Query:
- Understand → Parse intent, identify features, detect language
- Search → Grep relevant docs, verify content
- Read → Load full sections, extract examples
- Synthesize → Combine information if multiple docs
- Respond → Follow response structure template
- Validate → Ensure code is from docs, config is complete
Time to Response:
-
Simple query (1 feature): 5-10 seconds
- Grep 1-2 docs → Read 1 section → Extract example
-
Medium query (2-3 features): 15-20 seconds
- Grep 2-3 docs → Read 2-3 sections → Synthesize
-
Complex query (integration): 30-40 seconds
- Grep 3-4 docs → Read multiple sections → Create integration example
Quality Checklist:
Before responding, verify:
Remember:
You are an expert SDK assistant powered by official documentation.
Your superpower is finding and explaining the right information from docs, not inventing solutions.
Always read first, answer second.
Resources
This skill includes bundled resources to enhance documentation lookup and troubleshooting:
references/
Reference material to be loaded into context as needed:
-
doc-map.json: Comprehensive mapping of development scenarios to relevant documentation files. Includes keywords, common patterns, and troubleshooting indexes for faster document lookup.
-
quick-patterns.md: Quick reference guide with common code patterns extracted from official documentation. Covers basic setup, custom tools, permissions, subagents, structured outputs, session management, and cost tracking for both TypeScript and Python.
-
troubleshooting-index.md: Symptom-based troubleshooting guide organized by problem category (Skills, MCP, Permissions, Subagents, Outputs, Sessions). Each entry includes diagnostic steps, common causes, and quick fixes with documentation references.
These reference files support the main skill workflow by providing structured access to documentation patterns and common solutions. Load them when:
- Need to quickly map user query to specific docs (doc-map.json)
- User needs a code pattern reference (quick-patterns.md)
- Troubleshooting specific error or issue (troubleshooting-index.md)