Skip to main content

Lesson 9: Autonomous Agents

Topics Covered
  • Understanding when to delegate to agents vs when to direct Claude manually
  • Exploring agent types: Explore, Plan, and general-purpose agents
  • Using the Task Tool to spawn and manage autonomous agents
  • Running multiple agents in parallel for faster results
  • Orchestrating multi-agent workflows with handoffs and collaboration

Introduction

In Lesson 8, you learned to use Claude Code for individual tasks—reading files, making edits, running commands. Now it's time to scale up. Autonomous agents are specialized subprocesses that handle complex, multi-step tasks without constant supervision.

Instead of guiding Claude through every step, you describe the outcome and let agents figure out how to get there. In this lesson, you'll learn when to spawn agents, which agent type to use, and how to orchestrate multiple agents working together.

The Agent Mindset

Claude Code operates in two fundamentally different modes. Understanding when to use each is the key to working efficiently.

Direct interaction is what you practiced in Lesson 8. You give step-by-step instructions, and Claude executes each one. You read a file, then search within it, then make an edit. You're in the driver's seat at every turn.

Agent delegation is different. You describe the outcome you want, and Claude spawns an agent to figure out how to achieve it. The agent autonomously explores code, plans changes, makes decisions, and completes the work.

Here's the same task in both modes:

Direct interaction:

You: Read src/auth/login.js
Claude: [reads file, shows content]

You: Find the validatePassword function
Claude: [searches within file]

You: Change the hash algorithm to bcrypt
Claude: [makes edit]

Agent delegation:

You: Update the authentication system to use bcrypt instead of the current hashing method
Claude: [spawns agent]
Agent: [explores auth code, identifies hash usage, plans changes, implements across multiple files, runs tests]
tip

Use agents when the task requires exploration or coordination across multiple files. Use direct commands when you already know exactly what needs to change.

When to use agents:

  • The task requires exploring code you haven't seen
  • Multiple files need coordinated changes
  • You want Claude to research and plan before implementing
  • The task has unclear scope (the agent will figure it out)
  • You're blocked and need Claude to investigate

When NOT to use agents:

  • You already know exactly which file to edit
  • The change is a single-line fix
  • You want tight control over each step
  • The task is simple and well-defined

Agent Types

Claude Code offers three specialized agent types, each optimized for different workflows.

Explore Agent

The Explore agent is built for speed. It's your research assistant when you need to understand how code works or find specific patterns.

Best for: "How does authentication work?" or "Find all API endpoints"

Strengths: Quick searches, pattern recognition, mapping code structure

Thoroughness levels: quick, medium, very thorough

You: Use the Explore agent to understand how user permissions are checked
Claude: [Spawns Explore agent]
Agent: [Searches for permission-related code, reads relevant files, maps the flow]

The agent returns with an explanation of the permission system, including relevant file paths and code snippets.

Plan Agent

The Plan agent thinks architecturally. It designs implementation strategies before any code is written.

Best for: "Plan how to add OAuth support" or "Design a caching layer"

Strengths: Architectural thinking, identifying files to change, considering trade-offs

Output: Step-by-step implementation plan with file list

You: Use the Plan agent to design how we'll add rate limiting to the API
Claude: [Spawns Plan agent]
Agent: [Analyzes API structure, proposes middleware approach, lists files to modify]

You get a complete plan you can review, refine, or hand off to a general-purpose agent for implementation.

General-Purpose Agent

The general-purpose agent is your full-stack developer. It handles complex, multi-step tasks from research through implementation.

Best for: "Refactor this module" or "Add feature X end-to-end"

Strengths: Full autonomy, handles entire workflows, adapts to what it finds

Output: Completed implementation

You: Use the general-purpose agent to add email verification to the signup flow
Claude: [Spawns general-purpose agent]
Agent: [Researches current signup, plans email integration, implements changes, adds tests]

One command, and you get a fully implemented feature.

info

Start with Explore to understand the codebase, use Plan when you need a strategy before coding, and deploy general-purpose for end-to-end feature work.

The Task Tool

You don't invoke the Task tool directly. Instead, you ask Claude to use an agent, and Claude handles the Task tool invocation for you.

When you say:

You: Spawn an Explore agent to find all database queries in the codebase

Claude translates this into a Task tool call behind the scenes:

task_invocation.py
Task(
subagent_type="Explore",
description="Find all database queries",
prompt="Search the codebase for all database query operations...",
)

The agent lifecycle:

  1. Spawn: Claude creates the agent with a specific task
  2. Execute: Agent runs autonomously, using all available tools
  3. Report: Agent returns findings to Claude
  4. Continue: Claude uses the output to answer you or spawn more agents

Each agent gets full conversation context up to the spawn point. Agents can use all tools—Read, Grep, Edit, Bash—just like Claude does in direct mode. They return a single consolidated result when finished.

Every agent gets a unique ID that you can use to resume it later.

Running Agents in Parallel

One of Claude Code's most powerful features is parallel agent execution. Instead of waiting for each agent to finish before starting the next, you can run multiple agents simultaneously.

Sequential approach (slow):

You: First, find all the API routes. Then, find all the database models. Then, find all the validation schemas.

Claude spawns Explore agent #1, waits for it to finish, then spawns agent #2, waits, then spawns agent #3. Total time: three times the duration of one agent.

Parallel approach (fast):

You: Run three Explore agents in parallel: one to find API routes, one to find database models, one to find validation schemas

Claude spawns all three agents at once. They run simultaneously. Total time: the duration of the longest single agent.

Just mention "in parallel" or "simultaneously" in your request, and Claude handles the orchestration.

Common use cases for parallel agents:

  • Exploring different parts of a codebase at the same time
  • Running tests while analyzing code
  • Researching multiple APIs or libraries simultaneously
  • Comparing different implementation approaches
warning

Each agent consumes resources. Typically 2-4 parallel agents is optimal. More than that may not provide additional speed benefits.

Agent Collaboration

Complex tasks often require multiple agents working in sequence, with each agent's output feeding the next. This is where Claude Code truly shines.

The Research → Plan → Implement pattern:

Step 1: Explore agent researches the codebase

You: Use an Explore agent to understand the current authentication system
Agent: [Searches auth code, identifies JWT-based auth, finds relevant files]

Step 2: Plan agent designs the solution using Explore findings

You: Now use a Plan agent to design how we'll add OAuth support
Agent: [Uses research from Explore agent, proposes OAuth flow, lists files to modify]

Step 3: general-purpose agent implements the plan

You: Use a general-purpose agent to implement the OAuth plan
Agent: [Follows the plan, makes changes, tests implementation]

Each agent specializes in one phase. You orchestrate by spawning the right agent at the right time.

Here's a real-world example:

You: I want to add Redis caching to the API. First explore how data is currently fetched, then plan the caching strategy, then implement it.

Claude responds by spawning three agents in sequence. The Explore agent finds all data fetching code. The Plan agent designs cache key strategy and invalidation logic. The general-purpose agent adds the Redis client, implements caching, and updates endpoints.

You gave one high-level directive. Claude orchestrated three specialized agents to complete it.

Resuming Agents

Every agent execution gets a unique agent ID. You can use this ID to resume an agent and continue its work or ask follow-up questions.

When to resume:

  • The agent did research, and you want to dig deeper
  • The agent created a plan, and you want to refine it
  • The agent hit an error, and you've fixed the blocker
  • You want to continue a conversation with the agent's context

When an agent finishes, Claude returns its ID:

Agent completed. Agent ID: a1b2c3d4 (for resuming)

To resume:

You: Resume agent a1b2c3d4 and explore the error handling in more detail

The agent continues with all its previous context intact. This is more efficient than spawning a new agent, which would have to re-research everything.

Practical example:

You: Explore the payment processing code
Agent a1b2c3d4: [Finds payment files, explains flow]

You: Resume agent a1b2c3d4 and now show me where refunds are handled
Agent: [Continues with full context, digs into refund logic]

Production Patterns

Let's see how agents handle real-world development tasks.

Pattern 1: Codebase Onboarding

You join a new project and need to understand it fast.

You: Spawn three Explore agents in parallel:
1. Understand the overall architecture and folder structure
2. Map out the API endpoints and their purposes
3. Identify the database schema and key models

All three agents run simultaneously. In minutes, you have a complete picture of the codebase without reading a single file manually.

Pattern 2: Feature Implementation

You need to add a complete feature end-to-end.

You: Add a "forgot password" flow with email verification. Use a general-purpose agent.

The agent explores the current auth system, plans the flow (email service, token generation, reset endpoint), implements backend endpoints, adds the frontend form, writes tests, and updates documentation. One agent, fully autonomous, handles the entire feature.

Pattern 3: Debugging and Root Cause Analysis

A bug appears in production, and you don't know where it originates.

You: Users report that checkout fails when applying discount codes. Use an Explore agent to find the issue.

The agent searches for discount-related code, traces the checkout flow, identifies a race condition in the discount validation, and reports findings with file and line references.

You: Now use a general-purpose agent to fix the race condition

The agent reads the buggy code, implements a fix, and adds a test case for the scenario. Two agents: one to diagnose, one to fix.

Pattern 4: Research and Integration

You need to integrate a new library or API.

You: Research the Stripe API for subscription billing, plan how to integrate it, then implement the integration. Use agents in sequence.

The Explore agent researches Stripe docs and identifies required endpoints. The Plan agent designs the integration (webhook handlers, subscription model, payment flow) and lists files to modify. The general-purpose agent installs the Stripe SDK, implements subscription creation and webhook handling, updates the database, and adds error handling.

tip

For complex projects, always start with research (Explore), then strategy (Plan), then execution (general-purpose). This three-agent pattern catches issues early and produces better results.

Best Practices

Be specific about agent type. Instead of "use an agent," say "Use an Explore agent to find all console.log statements."

Provide context in the prompt. Instead of "add caching," say "Add Redis caching to the product search endpoint. Use a general-purpose agent."

Use parallel agents for independent tasks. Say "In parallel, explore the frontend components and the backend controllers."

Resume agents for follow-up questions. Don't spawn a new agent if you're continuing the same topic. Resume the previous agent to maintain context.

Let agents fail fast. If an agent can't complete a task, it will report why. Use that information to adjust your request or fix blockers.

Agent Limitations

Agents are powerful, but they have constraints you should understand.

Agents can't:

  • Interact with you mid-task (they run autonomously until complete)
  • Access your local environment beyond the project directory
  • Make decisions that require your judgment (e.g., "should we use approach A or B?")

Agents might struggle with:

  • Extremely large codebases (use thoroughness levels to control scope)
  • Tasks that require external context (like "implement the design from Figma")
  • Ambiguous requirements (provide clear goals)
warning

When agents get stuck, check their output—they usually explain what blocked them. Provide more context in your prompt, or break the task into smaller pieces.

Summary

Autonomous agents transform how you work with Claude Code. Instead of micromanaging every step, you delegate complex tasks and focus on high-level direction. Choose the right agent type for each phase of work: Explore for research, Plan for strategy, general-purpose for implementation.

Run agents in parallel to save time. Orchestrate multi-agent workflows for complex projects. Resume agents to continue conversations with full context. And always be specific about what you want the agent to accomplish.

Agents are autonomous, not interactive. They report results when done—you can't steer them mid-execution. But with clear instructions and the right agent type, they'll handle tasks that would take you hours in just minutes.

Next: In Lesson 10, you'll learn to extend Claude Code with Skills (custom commands), Plugins (shareable packages), and MCP servers (external tool integrations)—turning Claude Code into a personalized development environment.