Skip to content
Code Guide

Module 04: Agents & Specialization

Time: 1.5 hours | Complexity: ⭐⭐ Intermediate

Create specialized agents for specific tasks. Learn how to focus AI capabilities on targeted problems.


  • What agents are and why they’re useful
  • Creating custom agents with AGENT.md
  • Restricting agent capabilities (sandboxing)
  • Using agents for specific tasks
  • When to use agents vs Claude directly

An agent is a specialized version of Claude Code configured for one specific task.

Instead of asking regular Claude for code reviews (which takes mental context-switching), you use:

Terminal window
/agent code-reviewer
Review this function for bugs and performance issues

The code-reviewer agent:

  • Only handles code review
  • Has review-specific tools
  • Knows security vulnerability patterns
  • Doesn’t get distracted by other tasks
AspectNormal ClaudeAgent
ScopeGeneral purposeSpecialized
ContextRemembers everythingFocused task memory
ToolsAll availableRestricted set
SpeedMulti-task capableFast at one thing
UseExploration, learningRepetitive, specific tasks

Agents are defined in .claude/agents/AGENT.md files.

---
name: code-reviewer
type: agent
description: Reviews code for bugs, performance, and security
auto_invoke: false
requires_approval: true
---
# Code Reviewer Agent
## Purpose
Review code for:
- Bugs and logical errors
- Performance issues
- Security vulnerabilities
- Code style consistency
- Test coverage
## Tools
- Code analysis
- Git diff viewer
- Test runner
- Linting tools
## Instructions
When reviewing:
1. Check for null pointers and edge cases
2. Look for performance bottlenecks (O(n²), nested loops)
3. Scan for security issues (SQL injection, XSS)
4. Verify tests cover the change
5. Suggest improvements without being harsh
## Example Usage
/agent code-reviewer
Review src/auth.js for security issues

Place it in your project:

my-project/
└── .claude/
└── agents/
└── code-reviewer.md

In your project CLAUDE.md, reference it:

## Available Agents
Run agents with: /agent [name]
- **code-reviewer** - Code quality and security review
Usage: /agent code-reviewer <description>
- **test-writer** - Generate tests for code
Usage: /agent test-writer <file path>

---
name: quality-auditor
description: Audits code quality metrics
---
# Quality Auditor
## Purpose
Check code for:
- Test coverage (<80% = fail)
- Type safety (TypeScript strict mode)
- Code duplication
- Cyclomatic complexity
## Tools
- Code analysis
- Coverage reporter
- Type checker
## Output Format
- ✅ Passed: [metric] = X
- ⚠️ Warning: [metric] = X
- ❌ Failed: [metric] = X
## Scoring
Score /100 based on all metrics.
---
name: security-auditor
description: Scans code for vulnerabilities
requires_approval: true
---
# Security Auditor
## Purpose
Find security vulnerabilities:
- Injection attacks (SQL, NoSQL, command)
- Authentication/authorization issues
- Cryptography mistakes
- Data exposure risks
- OWASP Top 10
## Tools
- Static analysis
- Dependency checker
- Secret detection
## Severity Levels
- CRITICAL: Stop work immediately
- HIGH: Fix before merge
- MEDIUM: Fix in next sprint
- LOW: Consider fixing
---
name: doc-writer
description: Generates documentation
---
# Documentation Writer
## Purpose
Create or improve:
- README files
- API documentation
- Architecture docs
- User guides
- CHANGELOG entries
## Output Format
- Clear headings
- Code examples for each feature
- Link to related docs
- Numbered lists for sequences
## Style
- Beginner-friendly
- No jargon without explanation
- Show before/after examples

All agents can:

  • Read files (git-aware)
  • Analyze code
  • Write documentation
  • Check syntax
  • Run tests

Use capabilities to sandbox an agent:

---
name: code-reviewer
capabilities:
- read_files # Can read code
- run_tests # Can run test suites
- check_syntax # Can lint
- write_comments # Can suggest changes but...
- NO: commit # ...cannot commit
- NO: push # ...cannot push to git
---

This agent can review but can’t accidentally push broken code.

# Analyzer (read-only)
capabilities:
- read_files
- run_tests
# Can't modify anything
# Refactoring Agent (write, no push)
capabilities:
- read_files
- write_files
- run_tests
- NO: commit
- NO: push
# Can change code but you review before pushing
# Full Agent (unrestricted)
capabilities:
- all
# Can do anything (use with caution)

Terminal window
/agent code-reviewer
Review the changes I just made to src/auth.js

Claude switches to the code-reviewer agent and responds.

Use agents sequentially:

Terminal window
# Step 1: Test Writer generates tests
/agent test-writer
Write tests for src/utils/validators.js
# Step 2: Code Reviewer checks the tests
/agent code-reviewer
Review the tests that were just written
# Step 3: Security Auditor scans
/agent security-auditor
Check the tests and code for vulnerabilities

For risky operations, use /plan within an agent:

Terminal window
/agent refactoring-specialist
/plan
Refactor the payment processing module to use async/await

Terminal window
cat > .claude/agents/test-writer.md << 'EOF'
---
name: test-writer
description: Generates comprehensive tests
capabilities:
- read_files
- write_files
- run_tests
---
# Test Writer Agent
## Purpose
Generate high-quality tests for:
- Unit tests (pure functions)
- Integration tests (component interactions)
- Edge cases and error conditions
- Performance tests
## Style
- Arrange-Act-Assert pattern
- Descriptive test names
- Each test focuses on ONE behavior
- 70%+ code coverage target
## Tools
- Test framework (Jest, pytest, etc)
- Mock libraries
- Assertion libraries
## Output
- Tests in same directory as source
- Naming: [file].test.js or [file].spec.js
- Include setup/teardown code
EOF
## Available Agents
- test-writer: Generate tests for any function or module
Usage: /agent test-writer <file path>
Terminal window
/agent test-writer
Write tests for src/utils/formatDate.js

The agent will:

  1. Read formatDate.js
  2. Understand what it does
  3. Generate comprehensive tests
  4. Show you the test file

Check the tests before accepting:

  • Do they cover edge cases?
  • Is naming clear?
  • Do they actually run?

✅ You do the same task repeatedly (code review, testing, security audit) ✅ You want focused AI for one job ✅ You want to restrict capabilities (safety) ✅ You’re building team workflows ✅ The task has clear success criteria

✅ You’re exploring/learning ✅ The task is novel ✅ You need general-purpose help ✅ You’re debugging something complex ✅ You want conversational back-and-forth


✅ Give agents clear, narrow purposes

✅ Document output format in the agent definition

✅ Restrict capabilities you don’t need

✅ Test agents on sample tasks first

✅ Version control your agents (in .claude/agents/)

❌ Create agents with overlapping purposes (confusing)

❌ Make agents too general (defeats the purpose)

❌ Trust an agent completely (always review)

❌ Create an agent for a one-off task (just use Claude)


✓ You’ve created at least one custom agent

✓ You understand the purpose of agents vs Claude

✓ You can restrict agent capabilities

✓ You know how to call an agent (/agent name)

✓ You’ve tested your agent on a real task


Module 05: Skills & Automation covers:

  • Creating reusable skills (knowledge modules)
  • Bundling capabilities for distribution
  • Skill auto-invocation
  • Building your custom knowledge base

This teaches you how to package knowledge so Claude remembers it across sessions.


Completed Module 04? → Ready for Module 05: Skills & Automation