home / skills / thebushidocollective / han / agent-creation

This skill helps you create and configure Claude AI agents with the Agent SDK, enabling initialization, prompts, and tool access settings.

npx playbooks add skill thebushidocollective/han --skill agent-creation

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
3.9 KB
---
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

```typescript
import { Agent } from '@anthropic-ai/claude-agent-sdk';

const agent = new Agent({
  model: 'claude-3-5-sonnet-20241022',  // Latest model
  systemPrompt: 'You are a helpful assistant specialized in...',
  settingSources: ['project'],  // Load .claude/CLAUDE.md from project
  allowedTools: ['read_file', 'write_file', 'list_files'],
});
```

## Configuration Options

### System Prompts

```typescript
// Direct system prompt
const agent = new Agent({
  systemPrompt: 'You are an expert code reviewer...',
});

// Load from CLAUDE.md
const agent = new Agent({
  settingSources: ['project'],  // Loads ./.claude/CLAUDE.md
});

// User-level memory
const agent = new Agent({
  settingSources: ['user'],  // Loads ~/.claude/CLAUDE.md
});
```

### Tool Permissions

```typescript
// Allow specific tools
const agent = new Agent({
  allowedTools: [
    'read_file',
    'write_file',
    'list_files',
    'grep',
    'bash',
  ],
});

// Block specific tools
const agent = new Agent({
  disallowedTools: ['bash', 'web_search'],
});

// Permission modes
const agent = new Agent({
  permissionMode: 'strict',  // Require explicit approval
});
```

## 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

```bash
# Anthropic API (primary)
export ANTHROPIC_API_KEY="sk-ant-..."

# Alternative providers
export AWS_ACCESS_KEY_ID="..."
export AWS_SECRET_ACCESS_KEY="..."
export AWS_REGION="us-east-1"

# Google Vertex AI
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json"

# Azure
export AZURE_OPENAI_API_KEY="..."
export AZURE_OPENAI_ENDPOINT="..."
```

### SDK Configuration

```typescript
// Anthropic direct
const agent = new Agent({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

// Amazon Bedrock
const agent = new Agent({
  provider: 'bedrock',
  model: 'anthropic.claude-3-5-sonnet-20241022-v2:0',
});
```

## Best Practices

### Always Specify Model

```typescript
// Good
const agent = new Agent({
  model: 'claude-3-5-sonnet-20241022',
});

// Avoid: relying on default model
const agent = new Agent({});
```

### Use Explicit Setting Sources

```typescript
// Good
const agent = new Agent({
  settingSources: ['project'],
});

// Avoid: unclear memory source
const agent = new Agent({
  systemPrompt: '...',
});
```

### Separate Project and User Memory

```typescript
// Project-specific context
const projectAgent = new Agent({
  settingSources: ['project'],
});

// User preferences
const userAgent = new Agent({
  settingSources: ['user'],
});
```

## Anti-Patterns

### Don't Hardcode API Keys

```typescript
// Bad
const agent = new Agent({
  apiKey: 'sk-ant-hardcoded-key',
});

// Good
const agent = new Agent({
  apiKey: process.env.ANTHROPIC_API_KEY,
});
```

### Don't Mix Conflicting Permissions

```typescript
// Bad: contradictory permissions
const agent = new Agent({
  allowedTools: ['read_file', 'write_file'],
  disallowedTools: ['read_file'],  // Conflict!
});

// Good: clear permissions
const agent = new Agent({
  allowedTools: ['read_file'],
});
```

## Related Skills

- **tool-integration**: Working with tools and MCP servers
- **context-management**: Managing agent context and memory

Overview

This skill guides creating and configuring Claude AI agents with the Agent SDK using TypeScript. It covers agent initialization, prompt sourcing, tool permissions, authentication, and recommended setup patterns for reliable, auditable agents.

How this skill works

The skill shows how to instantiate Agent objects with explicit model, systemPrompt, settingSources, and tool permission options. It explains how the SDK loads project- or user-level settings, how to wire API keys or cloud provider credentials, and how to select provider-specific models. Examples demonstrate safe defaults and common configuration permutations.

When to use it

  • Initializing a new Claude agent for a project or microservice.
  • Configuring system prompts and memory sources for predictable behavior.
  • Defining and restricting tool access before running agents in production.
  • Switching authentication between Anthropic, AWS Bedrock, Google Vertex, or Azure.
  • Creating separate agents for project context versus personal preferences.

Best practices

  • Always specify the model explicitly to avoid unintended defaults.
  • Use environment variables for API keys; never hardcode secrets.
  • Prefer explicit settingSources (project or user) to make memory sources auditable.
  • Grant the minimal tool permissions required and avoid conflicting allow/deny lists.
  • Separate project and user agents when their context or permissions differ.

Example use cases

  • Create a code-review agent that loads project context from .claude/CLAUDE.md and only allows read_file and grep.
  • Spin up a project-specific assistant that uses a specialist subagent defined under .claude/agents.
  • Configure an agent to run on Bedrock or Vertex by swapping provider and model settings without code changes.
  • Lock an agent into strict permissionMode for workflows that require explicit tool approvals.

FAQ

How do I load a system prompt from project files?

Set settingSources: ['project'] to load the CLAUDE.md in the .claude directory; this keeps prompts and project memory version-controlled.

Which credentials are supported?

The SDK accepts Anthropic API keys via ANTHROPIC_API_KEY and can be configured to use AWS, Google Vertex, or Azure credentials for alternative providers.

How should I manage tool permissions safely?

Use allowedTools to enumerate required tools, avoid contradictory disallowedTools entries, and enable permissionMode: 'strict' for manual approvals.