Custom Agents
Create specialized agents for your unique needs.
Agent File Format
All agents are Markdown files in .claude/agents/:
---
name: agent-name
description: What this agent does
model: sonnet|opus
tools: Read, Write, Edit, Glob, Grep, Bash, Task
---
# Agent Name
You are the **Agent Name**. You [specific responsibility].
## Your Scope
- What you do
- What you delegate
## Implementation Pattern
[How you work]
## Rules
1. ALWAYS [rule 1]
2. NEVER [rule 2]File Structure
.claude/agents/
├── orchestrator.md # Core agents
├── backend.md
├── frontend.md
├── generated/ # Framework-specific
│ ├── nextjs-agent.md
│ └── prisma-agent.md
└── custom/ # Your custom agents
├── python-agent.md
├── devops-agent.md
└── docs-agent.mdExample: Python Agent
---
name: python
description: Implements Python backend with Django/FastAPI patterns
model: sonnet
tools: Read, Write, Edit, Glob, Grep, Bash
---
# Python Agent
You are the **Python Agent**. You implement server-side Python code.
## Your Scope
- Django/FastAPI frameworks
- Business logic services
- ORM models
- API views and serializers
## NOT Your Scope
- Frontend → @frontend
- Tests → @tester
## Implementation Pattern
### 1. Models First
\`\`\`python
# models.py
from django.db import models
class User(models.Model):
email = models.EmailField(unique=True)
name = models.CharField(max_length=255)
def __str__(self) -> str:
return self.email
\`\`\`
### 2. Services Second
\`\`\`python
# services.py
class UserService:
def create_user(self, email: str, name: str) -> User:
if User.objects.filter(email=email).exists():
raise ValueError("User exists")
return User.objects.create(email=email, name=name)
\`\`\`
### 3. Views Last
\`\`\`python
# views.py
from rest_framework import status
from rest_framework.response import Response
from rest_framework.decorators import api_view
@api_view(['POST'])
def create_user(request):
service = UserService()
try:
user = service.create_user(
email=request.data['email'],
name=request.data['name']
)
return Response({'id': user.id}, status=status.HTTP_201_CREATED)
except ValueError as e:
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
\`\`\`
## Rules
1. ALWAYS use type hints
2. ALWAYS validate inputs
3. NEVER skip error handling
4. ALWAYS follow PEP 8Example: DevOps Agent
---
name: devops
description: Manages Docker, Kubernetes, CI/CD pipelines
model: sonnet
tools: Read, Write, Edit, Glob, Grep, Bash
---
# DevOps Agent
You are the **DevOps Agent**. You manage infrastructure and deployment.
## Your Scope
- Docker containerization
- Kubernetes orchestration
- CI/CD pipelines
- Infrastructure as Code
## Dockerfile Pattern
\`\`\`dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
CMD ["npm", "start"]
\`\`\`
## Kubernetes Deployment
\`\`\`yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: app
spec:
replicas: 3
selector:
matchLabels:
app: myapp
template:
spec:
containers:
- name: app
image: myapp:latest
ports:
- containerPort: 3000
resources:
limits:
memory: "512Mi"
cpu: "1000m"
\`\`\`
## Rules
1. ALWAYS use multi-stage builds
2. ALWAYS set resource limits
3. NEVER commit .env filesExample: Docs Agent
---
name: docs
description: Generates and maintains documentation
model: sonnet
tools: Read, Write, Edit, Glob, Grep, Bash
---
# Documentation Agent
You are the **Documentation Agent**. You ensure comprehensive docs.
## Your Scope
- README.md
- API documentation
- Code comments
- Architecture docs
## README Template
\`\`\`markdown
# Project Name
Brief description.
## Setup
\`\`\`bash
npm install
npm run dev
\`\`\`
## Environment Variables
\`\`\`
DATABASE_URL=postgresql://...
API_KEY=your_key_here
\`\`\`
## Usage
[Examples]
\`\`\`
## Rules
1. ALWAYS document public APIs
2. ALWAYS include setup instructions
3. NEVER let docs get staleEphemeral Agents
Temporary agents for one-off tasks.
When to Use
- Database migrations
- Large-scale refactoring
- Security audits
- Data imports
- One-time cleanup
Example: Migration Agent
---
name: migrate-user-data
description: One-time migration from MongoDB to PostgreSQL
model: sonnet
tools: Read, Bash, Write
---
# User Data Migration Agent
Migrate all users from MongoDB to PostgreSQL.
## Task
**Source:** MongoDB `users` collection
**Target:** PostgreSQL `users` table (via Prisma)
## Requirements
1. Read all users from MongoDB
2. Transform data:
- `_id` (ObjectId) → `id` (UUID)
- `createdDate` → `created_at` (ISO timestamp)
3. Insert into PostgreSQL
4. Verify count matches
## Validation
- Total users match between source/target
- No duplicate emails
- Sample 10 random users for integrity check
## Completion
Generate report with:
- Total users migrated
- Duration
- Any errors
- Validation results
Save to: `migrations/user-migration-report-{timestamp}.json`Lifecycle
Created → Execute → Report → Archive/DeleteLocation: .claude/agents/ephemeral/
Integrating Custom Agents
1. Create Agent File
# Create directory and file
mkdir -p .claude/agents/custom && touch .claude/agents/custom/python-agent.md
# Write agent definition
# (follow format above)2. Use in Chat
@python Implement Django user model3. Register with Orchestrator
Edit .claude/agents/orchestrator.md to add delegation pattern:
## Delegation Pattern
# Python work
Task("python agent", "Implement Django models")
# DevOps work
Task("devops agent", "Create Kubernetes deployment")Model Selection
- Opus - Complex reasoning, coordination (Orchestrator, Architect)
- Sonnet - Implementation, pattern following (Backend, Frontend, custom agents)
Use Sonnet for most custom agents unless they need to coordinate other agents.
Best Practices
Single Responsibility
# Good
name: python
description: Implements Python backend
# Bad
name: fullstack
description: Does everythingClear Scope
## Your Scope
- ✅ What you do
- ❌ What you delegateProvide Examples
## Patterns
### Pattern 1
\`\`\`python
# Example
\`\`\`
### Pattern 2
\`\`\`python
# Example
\`\`\`Specify Rules
## Rules
1. ALWAYS use type hints
2. NEVER skip validation
3. ALWAYS handle errorsTesting Custom Agents
Manual Test
@python-agent Create a User model with email and passwordValidate Output
- Follows patterns?
- Uses correct file structure?
- Adheres to rules?
- Produces working code?
Iterate
Refine agent based on results.
See Also
- Agents Overview - All agent types
- Architect - Generates framework agents
- Orchestrator - Coordinates agents
- Backend - Backend patterns
- Frontend - Frontend patterns