skills/agent-sdk/SKILL.md
Create and run autonomous agents using the Anthropic Agent SDK. Use when the user wants to build custom AI agents, automate workflows with Claude's capabilities, or execute complex multi-step tasks programmatically.
npx skillsauth add szoloth/skills agent-sdkInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
A comprehensive skill for creating, configuring, and running autonomous agents using the Anthropic Agent SDK (formerly Claude Code SDK).
Use this skill whenever the user:
The Anthropic Agent SDK enables you to programmatically build AI agents with Claude Code's capabilities to create autonomous agents that can:
The SDK is available as an npm package:
npm install @anthropic-ai/claude-agent-sdk
query() FunctionThe primary function for creating agents is query(), which:
import { query } from "@anthropic-ai/claude-agent-sdk";
async function main() {
const result = query({
prompt: "Your task description here",
options: {
systemPrompt: "You are a specialized agent for...",
allowedTools: ["Read", "Write", "Bash"],
permissionMode: "acceptEdits"
}
});
for await (const message of result) {
console.log(message);
}
}
main();
Defines the agent's role, behavior, and expertise:
systemPrompt: "You are a data analysis agent that specializes in..."
Restrict which tools the agent can use:
allowedTools: ["Read", "Grep", "Glob", "Bash"]
Common tool combinations:
["Read", "Grep", "Glob"]["Read", "Grep", "Glob", "Bash"]["Read", "Write", "Edit", "Bash", "Grep", "Glob"]Controls how the agent handles operations:
"ask": Ask before each operation (default)"acceptEdits": Auto-approve file edits, ask for commands"acceptAll": Auto-approve all operations (use carefully!)Control which settings to load:
settingSources: ['project'] // Load project-specific settings
const result = query({
prompt: "Analyze the sales data in data/sales.csv and generate insights",
options: {
systemPrompt: `You are a data analysis expert. Analyze data files and:
- Calculate key statistics
- Identify trends and patterns
- Generate visualizations when helpful
- Provide actionable insights`,
allowedTools: ["Read", "Bash", "Write"],
permissionMode: "acceptEdits"
}
});
const result = query({
prompt: "Review the changes in src/components for best practices",
options: {
systemPrompt: `You are a code review expert. Review code for:
- Security vulnerabilities
- Performance issues
- Code style and consistency
- Best practices adherence`,
allowedTools: ["Read", "Grep", "Glob"],
permissionMode: "ask"
}
});
const result = query({
prompt: "Research how authentication is implemented in this codebase",
options: {
systemPrompt: `You are a codebase researcher. When researching:
- Search systematically through relevant files
- Document patterns and architectures
- Create summaries of findings
- Provide code examples`,
allowedTools: ["Read", "Grep", "Glob"],
permissionMode: "ask"
}
});
const result = query({
prompt: "Set up a new React component with tests and styles",
options: {
systemPrompt: `You are an automation expert. When creating components:
- Follow project conventions
- Include comprehensive tests
- Add proper documentation
- Handle edge cases`,
allowedTools: ["Read", "Write", "Edit", "Bash", "Grep", "Glob"],
permissionMode: "acceptEdits"
}
});
Use the provided scaffold script to create a new agent:
./.claude/skills/agent-sdk/create-agent.sh <agent-name> <description>
This creates a new agent template in agents/<agent-name>/ with:
mkdir -p agents/my-agent
cd agents/my-agent
npm init -y
npm install @anthropic-ai/claude-agent-sdk
agent.ts):import { query } from "@anthropic-ai/claude-agent-sdk";
async function runAgent() {
const result = query({
prompt: process.argv[2] || "Default task",
options: {
systemPrompt: "Your agent's role and instructions",
allowedTools: ["Read", "Grep", "Glob"],
permissionMode: "ask"
}
});
for await (const message of result) {
console.log(message);
}
}
runAgent().catch(console.error);
npx tsx agent.ts "Your task here"
# Required: Anthropic API key
ANTHROPIC_API_KEY=your_api_key_here
# Optional: Model selection (defaults to sonnet-4-5)
ANTHROPIC_MODEL=claude-sonnet-4-5
# Optional: Timeout settings
AGENT_TIMEOUT=300000
Create a .env file in your agent directory:
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_MODEL=claude-sonnet-4-5
"ask" permission mode for sensitive operationsWrite effective system prompts by:
Example:
systemPrompt: `You are a security audit agent specializing in Node.js applications.
Your responsibilities:
- Identify security vulnerabilities in code
- Check for common OWASP Top 10 issues
- Verify authentication and authorization patterns
- Review dependency security
Guidelines:
- Always explain the security impact of findings
- Provide specific remediation steps
- Prioritize findings by severity
- Reference security standards when applicable`
Always handle errors gracefully:
async function runAgent() {
try {
const result = query({...});
for await (const message of result) {
console.log(message);
}
} catch (error) {
console.error("Agent error:", error);
process.exit(1);
}
}
Process agent responses as they stream:
for await (const message of result) {
if (message.type === "text") {
console.log(message.content);
} else if (message.type === "tool_use") {
console.log(`Using tool: ${message.tool}`);
}
}
Create agents with specific tool combinations:
// Read-only research agent
allowedTools: ["Read", "Grep", "Glob"]
// Data processing agent
allowedTools: ["Read", "Write", "Bash"]
// Full development agent
allowedTools: ["Read", "Write", "Edit", "Bash", "Grep", "Glob", "Task"]
Chain multiple agent queries for complex workflows:
async function complexWorkflow() {
// Step 1: Research
const research = query({
prompt: "Research the authentication patterns in this codebase",
options: { allowedTools: ["Read", "Grep", "Glob"] }
});
let findings = "";
for await (const message of research) {
findings += message.content;
}
// Step 2: Generate improvements
const improvements = query({
prompt: `Based on these findings:\n${findings}\n\nGenerate improved authentication code`,
options: { allowedTools: ["Write", "Edit"] }
});
for await (const message of improvements) {
console.log(message);
}
}
Build agents that work together:
// Analyzer agent finds issues
const analyzer = query({
prompt: "Analyze code quality in src/",
options: { systemPrompt: "You are a code quality analyzer" }
});
// Fixer agent resolves issues
const fixer = query({
prompt: `Fix the following issues: ${issues}`,
options: { systemPrompt: "You are a code improvement specialist" }
});
Goal: Create an agent that writes tests for existing code
const result = query({
prompt: "Write comprehensive tests for the UserService class",
options: {
systemPrompt: `You are a testing expert. When writing tests:
- Cover all public methods
- Test edge cases and error conditions
- Use appropriate assertions
- Follow testing best practices
- Include setup and teardown`,
allowedTools: ["Read", "Write", "Grep"],
permissionMode: "acceptEdits"
}
});
Goal: Agent that generates documentation from code
const result = query({
prompt: "Generate API documentation for all endpoints in src/api/",
options: {
systemPrompt: `You are a technical writer. Generate documentation that:
- Describes each endpoint's purpose
- Lists all parameters and types
- Shows example requests and responses
- Documents error cases
- Includes authentication requirements`,
allowedTools: ["Read", "Write", "Grep", "Glob"],
permissionMode: "acceptEdits"
}
});
Goal: Agent that refactors code for better patterns
const result = query({
prompt: "Refactor the legacy code in src/legacy/ to use modern patterns",
options: {
systemPrompt: `You are a refactoring expert. When refactoring:
- Preserve existing functionality
- Improve code organization
- Apply SOLID principles
- Add type safety
- Update tests accordingly`,
allowedTools: ["Read", "Edit", "Bash", "Grep"],
permissionMode: "acceptEdits"
}
});
.env file contains ANTHROPIC_API_KEY=your_keysource .env or use dotenvnpm install @anthropic-ai/claude-agent-sdkpackage.json includes the dependencypermissionMode to grant necessary permissionsallowedTools to include required tools"ask" mode for sensitive operationsWrite, Edit, and Bash toolsRun agents as part of your pipeline:
npx tsx agents/code-review/agent.ts "Review PR changes"
Use agents in pre-commit or pre-push hooks:
#!/bin/bash
npx tsx agents/linter/agent.ts "Check code quality"
Run agents on a schedule with cron:
0 9 * * * cd /path/to/project && npx tsx agents/daily-report/agent.ts
Create IDE tasks that invoke agents:
{
"label": "Run Code Review Agent",
"type": "shell",
"command": "npx tsx agents/review/agent.ts '${input:reviewPrompt}'"
}
Instead of preloading all MCP tool definitions into an agent's system prompt (which wastes context), agents can write Python code that calls MCP tools programmatically. This achieves:
Traditional approach (wasteful):
// System prompt lists ALL tools (3,000+ tokens)
systemPrompt: `
Available tools:
- mcp__things__get-today: Get today's tasks
- mcp__things__create-todo: Create new task
- mcp__google_calendar__list_events: List calendar events
- mcp__gmail__list_messages: List emails
[... 50+ more tool definitions ...]
`
// Every data fetch passes through context
const tasks = call_tool('mcp__things__get-today') // 2,000 tokens for 20 tasks
const events = call_tool('mcp__google_calendar__list_events') // 1,000 tokens for 5 events
const emails = call_tool('mcp__gmail__list_messages') // 3,500 tokens for 30 emails
// Total: ~10,800 tokens just for data!
New approach with 95% savings:
#!/usr/bin/env python3
import sys
sys.path.append('/home/user/llm-context-personal/scripts')
from mcp_tools import things, calendar, gmail
# Fetch data via MCP
tasks = things.get_today()
events = calendar.list_events_today()
emails = gmail.get_unread(limit=50)
# Process locally (NOT in Claude's context!)
p1_tasks = [t for t in tasks if t.get('priority') == 'P1']
urgent_emails = [e for e in emails if 'urgent' in e['subject'].lower()]
conflicts = detect_conflicts(tasks, events)
# Return only summary (~300 tokens vs 10,800 tokens)
print(f"""
Daily Summary:
- {len(p1_tasks)} P1 tasks requiring attention
- {len(urgent_emails)} urgent emails
- {len(conflicts)} calendar conflicts
""")
Located at scripts/mcp_tools/, provides wrappers for:
Things 3 (things):
things.get_today() - Today's tasksthings.create_todo(title, notes, tags, deadline) - Create taskthings.update_todo(id, completed=True) - Update taskGoogle Calendar (calendar):
calendar.list_events_today() - Today's eventscalendar.create_event(title, start, end) - Create eventcalendar.get_free_busy(start, end) - Check availabilityGmail (gmail):
gmail.get_unread(limit=50) - Unread messagesgmail.send_message(to, subject, body) - Send emailgmail.search_messages(query) - Search emailsFull documentation: See scripts/mcp_tools/README.md
Old approach (10,800 tokens):
const result = query({
prompt: "Generate my daily plan",
options: {
systemPrompt: `
# You have access to:
- Things 3 MCP tools: get-today, create-todo, update-todo, ...
- Calendar MCP tools: list_events, create_event, ...
- Gmail MCP tools: list_messages, send_message, ...
[Detailed tool descriptions... 3,000+ tokens]
`,
allowedTools: ["mcp__things__get-today", "mcp__google_calendar__list_events", ...]
}
});
// Agent calls each tool directly, all data passes through context
New approach (500 tokens):
const result = query({
prompt: "Generate my daily plan",
options: {
systemPrompt: `
Write Python code using mcp_tools package to:
1. Fetch data from Things, Calendar, Gmail
2. Process locally (filter P1 tasks, detect conflicts, categorize emails)
3. Return concise summary only
Template:
from mcp_tools import things, calendar, gmail
# ... fetch and process ...
print(f"Summary: {p1_count} P1 tasks, {urgent_count} urgent emails")
Example: scripts/mcp_tools/examples/daily_plan.py
`,
allowedTools: ["Bash", "Read", "Write"]
}
});
// Agent writes code, executes locally, returns only summary
✅ Use code execution when:
❌ Use direct tool calls when:
.mcp.json:{
"mcpServers": {
"things": {"command": "node", "args": ["/path/to/things-mcp/index.js"]},
"google-calendar": {"command": "node", "args": ["/path/to/calendar-mcp/index.js"]},
"gmail": {"command": "node", "args": ["/path/to/gmail-mcp/index.js"]}
}
}
const result = query({
prompt: userPrompt,
options: {
systemPrompt: `
You have access to MCP tools via Python code execution.
Import from mcp_tools package:
- things: Things 3 task management
- calendar: Google Calendar
- gmail: Gmail email management
Always:
1. Fetch data first
2. Process/filter in Python
3. Return only concise summary
See: scripts/mcp_tools/README.md and examples/
`,
allowedTools: ["Bash", "Read", "Write", "Grep", "Glob"]
}
});
agents/executive-assistant/ or .claude/skills/executive-assistant/SKILL.md for production implementation.| Aspect | Direct Tool Calls | Code Execution | Savings | |--------|------------------|----------------|---------| | Token usage | ~10,800 tokens | ~500 tokens | 95% | | Context efficiency | Low (all data in context) | High (only summaries) | Massive | | Data processing | Limited (in Claude) | Full Python capabilities | Much better | | State persistence | None | Full Python state | Significant | | Tool discovery | Preload all | Progressive disclosure | Efficient |
docs/CODE_EXECUTION_WITH_MCP.mdscripts/mcp_tools/README.mdscripts/mcp_tools/examples/daily_plan.py.claude/skills/executive-assistant/SKILL.mdtemplates/Build reusable agent functions:
// lib/agents/code-review.ts
export function createCodeReviewAgent(options) {
return query({
prompt: options.prompt,
options: {
systemPrompt: "You are a code review expert...",
...options
}
});
}
Combine multiple agents for complex workflows:
import { analyzerAgent } from "./lib/agents/analyzer";
import { reporterAgent } from "./lib/agents/reporter";
async function fullAudit() {
const analysis = await analyzerAgent("Audit codebase");
const report = await reporterAgent(analysis);
return report;
}
SKILL.md - This comprehensive guideREADME.md - Quick reference and setupcreate-agent.sh - Scaffold script for new agentstemplates/ - Agent templates for common use casesexamples.md - Detailed usage examples and patternscontent-media
Fetch transcripts from YouTube videos for summarization and analysis.
documentation
This skill should be used when reviewing or editing written drafts to ensure they match Sam's personal style guide. It prioritizes voice preservation and anti-beige detection while catching structural gaps. Triggers on requests to review, edit, or improve written content.
tools
Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.
development
Web search and content extraction using Brave Search. Use when researching topics, finding documentation, extracting article content, or gathering information from the web. No browser required - works headlessly.