Claude FastClaude Fast
Agents

Claude Code Custom Commands: Build Your Own AI Agents

Create custom Claude Code agents tailored to your workflow. Learn to build specialized commands that automate your unique development patterns.

Problem: Claude Code's default capabilities don't match your specific workflow. You need a code reviewer that follows your team's standards, or a deployment specialist that knows your infrastructure.

Quick Win: Create your first custom agent in under 2 minutes:

/agents

Select "Create New Agent" and use this template:

---
name: code-reviewer
description: Expert code reviewer for quality, security, and maintainability
tools: Read, Grep, Bash
---
 
You are a senior code reviewer ensuring high standards.
 
When invoked:
1. Run git diff to see recent changes
2. Focus on modified files
3. Begin review immediately
 
Review checklist:
- Code is readable and well-named
- No duplicated code
- Proper error handling
- No exposed secrets
- Performance considerations
 
Provide feedback by priority: Critical → Warnings → Suggestions

Understanding: Custom agents are specialized AI assistants that Claude automatically invokes when appropriate. Unlike manual sub-agents, they work automatically - like having expert consultants who jump in exactly when needed.

How Custom Agents Transform Your Workflow

Custom agents solve the "remembering to ask" problem. Instead of manually invoking specialized roles, Claude intelligently routes tasks to the right specialist based on context and agent descriptions.

Automatic Delegation: Each agent has its own context window, system prompt, and tools. When you commit code, Claude might automatically use your code-reviewer agent. When you deploy, your infrastructure-specialist agent takes over.

Separation of Concerns: Like good software architecture, specialized agents perform better than generalists. A security-focused agent with limited tools is more reliable than a general agent with access to everything.

Creating Effective Custom Agents

Start Simple: Begin with one specific problem you face repeatedly:

# Security specialist
/agents
---
name: security-audit
description: Security vulnerability scanner for web applications
tools: Read, Grep, Bash
model: opus
---
 
You are a security expert focused on vulnerability detection.
 
Immediately scan for:
- SQL injection vulnerabilities  
- XSS attack vectors
- Authentication bypass issues
- Exposed API keys or secrets
- OWASP Top 10 violations
 
For each finding, provide:
1. Vulnerability description
2. Risk level (Critical/High/Medium/Low)  
3. Specific fix recommendation
4. Code example of the fix

Tool Restriction Strategy: Limit agents to only necessary tools. A documentation agent doesn't need Bash access. A deployment agent shouldn't read arbitrary files.

Advanced Agent Patterns

Agent Chaining: Create workflows where agents hand off to each other:

First use the security-audit agent to identify issues,
then use the fix-implementation agent to resolve them,
finally use the test-validation agent to verify fixes

Specialized Models: Use different models for different tasks:

  • Haiku for simple formatting checks
  • Sonnet for general development tasks
  • Opus for complex security analysis

Project vs User Agents: Store team-specific agents in .claude/agents/ (project-level) and personal productivity agents in ~/.claude/agents/ (user-level).

Common Agent Examples

Database Specialist:

---
name: db-optimizer  
description: Database performance and query optimization expert
tools: Read, Bash
---
 
You optimize database performance and design.
Focus on: query efficiency, index usage, schema design
Always provide EXPLAIN ANALYZE for slow queries

Documentation Assistant:

---
name: docs-writer
description: Technical documentation and README specialist  
tools: Read, Write
---
 
You write clear, actionable documentation.
Include: setup instructions, examples, troubleshooting
Target audience: developers new to the project

Next Actions

Ready to build your specialist team? Start with your biggest pain point:

Your custom agents become more valuable as you refine them. Share battle-tested configurations with your team, and build a collection that handles every aspect of your development workflow.

Last updated on

On this page

Claude Code ready in seconds.Get Claude Fast