Custom Agents

Software Development with Claude Code

Dani Zysman

AI Curriculum Manager @ DataCamp

What Are Agents?

A team of specialized robot assistants with different tools

Agents are Specialized AI assistants within Claude Code:

  • Each has specific capabilities, works independently
  • Can be built-in or custom-created
Software Development with Claude Code

Built-in Agents

Agent Purpose When Used
Explore Read-only codebase investigation "Map this architecture"
Plan Research and strategize "How should we approach this?"
General Execute tasks with full tools Default for most work

Use /agents to list all available agents

Software Development with Claude Code

Why Create Custom Agents?

Custom agents for specialized tasks

  • Benefits: Reusable, consistent, shareable with team
  • Common use cases:
    • Code review - enforce team standards
    • Security audit - check for vulnerabilities
    • Documentation - generate consistent docs
    • Testing - suggest test cases
Software Development with Claude Code

Creating an Agent File

  • File location:
    • .claude/agents/code-reviewer.md
  • Required sections:
    • name: Agent identifier
    • description: What triggers it
    • Body: Instructions in markdown
___
# code-reviewer.md
name: code-reviewer
description: Reviews code for 
best practices
___
Check for:
1. Clear naming conventions
2. Proper error handling
3. Performance concerns
Software Development with Claude Code

Creating a Code Reviewer Custom Agent

> /agents

> [Select] Create new agent
> [Select] Project level (.claude/agents)
> [Select] Generate with Claude (recommended)
> Create a code reviewer agent that reviews code for naming, error handling, and performance.

Review and approve the generated file.

Software Development with Claude Code

The Project So Far

music-analytics-api/
  app.py
  routes.py        # <- We'll review this file
  models.py
  analytics.py
  CLAUDE.md
  .claude/
    agents/
      code-reviewer.md  # <- Our custom agent
Software Development with Claude Code

When Agents Spawn

No sub-agent (works directly):

"Fix the bug in routes.py"
  -> Claude handles it

"Add validation here"
  -> Claude handles it

Spawns sub-agent:

"Map the architecture"
  -> Explore agent

"How should we refactor?"
  -> Plan agent
Software Development with Claude Code

Using Our Custom Agent

> @code-reviewer review @routes.py
Review Complete

Quick Fixes:
- Remove unused `session` import (line 3)
- Replace hardcoded `* 5` popularity metric with a named constant

Structural Issues:
- Album dictionaries built twice in get_album_stats() and
  get_average_tracks() extract to a shared helper
- get_artist_albums() returns empty list if artist doesn't exist;
  validate artist first
- No range validation on artist_id parameter

Would you like me to fix any of these?
Software Development with Claude Code

Agent Benefits

A magnifying glass with protective shield for safe exploration

  • Separate context
    • Agents work in isolation
    • Main conversation stays clean
  • Safe exploration
    • Explore agent is read-only
    • Perfect for unfamiliar codebases
Software Development with Claude Code

When to Use Agents

Question Type What Happens
"What does this function do?" Claude answers directly
"How does auth work across this codebase?" Explore agent investigates
"What's the best approach to refactor this?" Plan agent researches
"code review @routes.py" Handled by custom agent
Software Development with Claude Code

Let's Practice!

Software Development with Claude Code

Preparing Video For Download...