| name | claude-agent-sdk-agent-creation |
| user-invocable | false |
| description | Use when creating or configuring Claude AI agents using the Agent SDK. Covers agent initialization, configuration, and basic setup patterns. |
| allowed-tools | ["Read","Write","Edit","Bash","Grep","Glob"] |
Claude Agent SDK - Agent Creation
Creating and configuring AI agents using the Claude Agent SDK with TypeScript.
Core Agent Initialization
Basic Agent Creation
import { Agent } from '@anthropic-ai/claude-agent-sdk';
const agent = new Agent({
model: 'claude-3-5-sonnet-20241022',
systemPrompt: 'You are a helpful assistant specialized in...',
settingSources: ['project'],
allowedTools: ['read_file', 'write_file', 'list_files'],
});
Configuration Options
System Prompts
const agent = new Agent({
systemPrompt: 'You are an expert code reviewer...',
});
const agent = new Agent({
settingSources: ['project'],
});
const agent = new Agent({
settingSources: ['user'],
});
Tool Permissions
const agent = new Agent({
allowedTools: [
'read_file',
'write_file',
'list_files',
'grep',
'bash',
],
});
const agent = new Agent({
disallowedTools: ['bash', 'web_search'],
});
const agent = new Agent({
permissionMode: 'strict',
});
Agent Directory Structure
Required Structure
project/
├── .claude/
│ ├── CLAUDE.md # Project memory
│ ├── agents/
│ │ └── specialist.md # Subagent definitions
│ ├── skills/
│ │ └── my-skill/
│ │ └── SKILL.md # Skill definitions
└── src/
└── index.ts # Your code
Authentication
Environment Variables
export ANTHROPIC_API_KEY="sk-ant-..."
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_REGION="us-east-1"
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"
export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="..."
SDK Configuration
const agent = new Agent({
apiKey: process.env.ANTHROPIC_API_KEY,
});
const agent = new Agent({
provider: 'bedrock',
model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
});
Best Practices
Always Specify Model
const agent = new Agent({
model: 'claude-3-5-sonnet-20241022',
});
const agent = new Agent({});
Use Explicit Setting Sources
const agent = new Agent({
settingSources: ['project'],
});
const agent = new Agent({
systemPrompt: '...',
});
Separate Project and User Memory
const projectAgent = new Agent({
settingSources: ['project'],
});
const userAgent = new Agent({
settingSources: ['user'],
});
Anti-Patterns
Don't Hardcode API Keys
const agent = new Agent({
apiKey: 'sk-ant-hardcoded-key',
});
const agent = new Agent({
apiKey: process.env.ANTHROPIC_API_KEY,
});
Don't Mix Conflicting Permissions
const agent = new Agent({
allowedTools: ['read_file', 'write_file'],
disallowedTools: ['read_file'],
});
const agent = new Agent({
allowedTools: ['read_file'],
});
Related Skills
- tool-integration: Working with tools and MCP servers
- context-management: Managing agent context and memory