Loading...
Loading...
Guide for Claude Agent SDK - build custom AI agents powered by Claude. Covers installation, authentication providers, tool permissions, file-based configuration, TypeScript/Python code examples, and project scaffolding templates.
npx skill4agent add majesticlabs-dev/majestic-marketplace agent-sdknpm install @anthropic-ai/claude-agent-sdkpip install claude-agent-sdk{
allowedTools: ['Read', 'Write', 'Bash'], // Explicit allowlist
disallowedTools: ['WebSearch'], // Explicit blocklist
permissionMode: 'default' | 'strict' // Overall strategy
}export ANTHROPIC_API_KEY=sk-ant-...export CLAUDE_CODE_USE_BEDROCK=1
export AWS_ACCESS_KEY_ID=...
export AWS_SECRET_ACCESS_KEY=...
export AWS_REGION=us-east-1export CLAUDE_CODE_USE_VERTEX=1
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
export VERTEX_REGION=us-central1
export VERTEX_PROJECT_ID=your-projectexport CLAUDE_CODE_USE_FOUNDRY=1
# Azure credentials configuration| Directory | Purpose |
|---|---|
| Subagent definitions (Markdown) |
| Skill files ( |
| Slash commands (Markdown) |
| Hooks configuration |
| Project memory/context |
{
settingSources: ['project']
}import { Agent } from '@anthropic-ai/claude-agent-sdk';
const agent = new Agent({
model: 'claude-sonnet-4-20250514',
allowedTools: ['Read', 'Write', 'Bash'],
systemPrompt: `You are a code review assistant.
Analyze code for bugs, security issues, and best practices.`,
});
const result = await agent.run({
prompt: 'Review the code in src/auth.ts for security issues',
});
console.log(result.output);import { Agent } from '@anthropic-ai/claude-agent-sdk';
const agent = new Agent({
model: 'claude-sonnet-4-20250514',
mcpServers: {
database: {
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-postgres'],
env: { DATABASE_URL: process.env.DATABASE_URL },
},
},
});
const result = await agent.run({
prompt: 'List all users who signed up in the last 24 hours',
});from claude_agent_sdk import Agent
agent = Agent(
model="claude-sonnet-4-20250514",
allowed_tools=["Read", "Write", "Bash"],
system_prompt="""You are a code review assistant.
Analyze code for bugs, security issues, and best practices.""",
)
result = agent.run(
prompt="Review the code in src/auth.py for security issues"
)
print(result.output)from claude_agent_sdk import Agent, PermissionMode
agent = Agent(
model="claude-sonnet-4-20250514",
permission_mode=PermissionMode.STRICT,
allowed_tools=["Read", "Grep", "Glob"],
disallowed_tools=["Bash"], # Extra safety
)
result = agent.run(
prompt="Find all TODO comments in the codebase"
)// Start here
allowedTools: ['Read']
// Then add as required
allowedTools: ['Read', 'Grep', 'Glob']
// Only if truly needed
allowedTools: ['Read', 'Write', 'Bash'].claude/agents/
├── code-reviewer.md # Reviews code changes
├── test-writer.md # Generates tests
└── doc-generator.md # Creates documentationtry {
const result = await agent.run({ prompt });
if (result.error) {
console.error('Agent error:', result.error);
}
} catch (error) {
console.error('SDK error:', error);
}const agent = new Agent({
onToolUse: (tool, input) => {
console.log(`Tool: ${tool}, Input: ${JSON.stringify(input)}`);
},
onThinking: (thought) => {
console.log(`Thinking: ${thought}`);
},
});/agent-sdk:agent-scaffold| Template | Purpose |
|---|---|
| Node.js package config |
| TypeScript agent entry |
| Python package config |
| Python agent entry |
| Provider config templates |
| Subagent/skill/command templates |
| User Selection | SDK Tools |
|---|---|
| File Operations | Read, Write, Edit, Glob, Grep |
| Code Execution | Bash |
| Web Search | WebSearch, WebFetch |
| MCP Tools | (configured via mcpServers) |
You are a coding assistant that helps developers write better code.
Analyze code for bugs, security issues, and best practices.You are a business analyst assistant.
Help with document analysis, data extraction, and report generation.