Claude FastClaude Fast
Agents

Claude Code Agents: Engineering Autonomous AI Assistants

Master agent engineering in Claude Code. Learn to design and deploy autonomous agents that handle complex tasks independently.

Problem: Complex projects demand multiple perspectives - security reviewer, performance analyst, documentation writer. Switching mental contexts burns time and dilutes focus.

Quick Win: Spawn a sub-agent to handle a parallel task right now:

Use a sub-agent to review the authentication module for security vulnerabilities while I continue working on the API endpoints.

Claude Code launches an isolated sub-agent that works independently, then reports findings back to your main session.

Understanding: Claude Code provides multiple ways to create agent-like behavior - from built-in sub-agents to custom slash commands. Each approach serves different needs. Master these fundamentals before exploring advanced agent patterns.

Four Agent Approaches in Claude Code

Claude Code offers several ways to achieve specialized, agent-like behavior:

ApproachBest ForPersistence
Task Tool (Sub-agents)Parallel execution, isolated workSession only
Custom Slash CommandsReusable workflows, team sharingPermanent
CLAUDE.md PersonasProject-wide behavior rulesPermanent
Perspective PromptingQuick context switchesSingle request

Each approach has trade-offs. Sub-agents excel at parallel work; slash commands excel at reusability.

Sub-Agents: Built-in Parallel Execution

The Task tool spawns mini Claude Code instances inside your session. Each sub-agent gets its own context window, works independently, and returns results to the orchestrator.

Launch parallel sub-agents:

Complete these tasks using 3 sub-agents in parallel:
1. Review src/auth/ for security vulnerabilities
2. Analyze src/api/ for performance bottlenecks
3. Check src/utils/ for code duplication

Why sub-agents matter:

  • Isolated context prevents pollution between tasks
  • Parallel execution speeds up multi-file analysis
  • Failed sub-agents don't crash your main session
  • Background execution lets you continue working (press Ctrl+B)

New: When Claude spawns sub-agents, you can now background them with Ctrl+B and continue chatting with the main agent on other tasks. Results surface automatically when complete. See async workflows for the full guide.

Learn more about sub-agent design patterns for complex orchestration.

Custom Slash Commands: Reusable Specialists

Create permanent, reusable commands by adding Markdown files to .claude/commands/:

<!-- .claude/commands/security-review.md -->
---
description: "Security-focused code review"
allowed-tools: ["Read", "Grep", "Bash"]
---
 
Review the specified code for security vulnerabilities:
1. Check for SQL injection risks
2. Identify authentication bypasses
3. Flag hardcoded secrets
4. Report findings with severity ratings
 
Target: $ARGUMENTS

Now run /project:security-review src/auth/ to invoke your specialist.

Command locations:

  • .claude/commands/ - Project-specific, shareable via git
  • ~/.claude/commands/ - Personal, available everywhere

CLAUDE.md: Persistent Agent Behavior

Your CLAUDE.md file shapes Claude's behavior for every interaction in your project:

<!-- CLAUDE.md -->
## Code Review Protocol
 
When reviewing code, always:
1. Check for security vulnerabilities first
2. Identify performance implications
3. Suggest specific improvements with code examples
4. Flag any deviation from project conventions

This creates agent-like consistency without explicit invocation.

Perspective Prompting: Quick Context Switches

For one-off analysis, prompt Claude to adopt a specific perspective:

Analyze this authentication flow from three perspectives:
1. Security engineer: What vulnerabilities exist?
2. Performance engineer: What bottlenecks could occur at scale?
3. Junior developer: What parts are confusing or poorly documented?

No setup required - immediate specialized analysis.

Choosing Your Approach

Use sub-agents when: You need parallel execution or isolated context for multiple tasks.

Use slash commands when: You repeat the same workflow across sessions or want to share with your team.

Use CLAUDE.md when: You want consistent behavior applied automatically to all interactions.

Use perspective prompting when: You need quick, one-time specialized analysis.

Next Action: Create your first slash command in .claude/commands/ for a workflow you repeat often, then explore task distribution strategies for complex orchestration.

Explore More Agent Concepts:

Last updated on

On this page

Claude Code ready in seconds.