Skip to content

Claude Code Multi-Agent System — Usage Guide

Let Claude Code orchestrate multiple specialized agents to handle complex tasks in parallel.

Multi-Agent System · Six Built-in Agents · Spawning Agents · Background Tasks · Agent Teams · Custom Agents · Permission Modes · Quick Reference

Multi-Agent System Overview


1. What Is the Multi-Agent System?

Claude Code's multi-agent system is an intelligent task orchestration framework that enables the primary agent to spawn multiple specialized subagents, each executing different tasks independently, then aggregating results for the user.

Core philosophy: Break large tasks into specialized subtasks, execute them in parallel, and boost efficiency.

ScenarioTraditional ApproachMulti-Agent Approach
Research 5 module architecturesExplore them one by one5 Explore agents scan in parallel
Implement + Test + DocumentComplete sequentiallyTeam members each handle one part
Code reviewSingle-threaded, file by fileMultiple reviewers in parallel
Debug a complex bugTry one hypothesis at a timeMultiple debuggers verify in parallel

2. Six Built-in Agents

Six Built-in Agents

Claude Code ships with 6 specialized agent types, each with a specific tool pool and intended use case:

2.1 general-purpose (General Agent)

Use case: Complex multi-step research, code search, tasks requiring full tool access.

Agent({
  description: "Research auth module",
  prompt: "Analyze all files under src/auth/ for the authentication flow...",
  subagent_type: "general-purpose"
})
  • Tool pool: All tools (*)
  • Model: Inherited from parent
  • Characteristics: The all-rounder — choose this when you are unsure which agent type to use

2.2 Explore (Exploration Agent)

Use case: Quickly search files, find code patterns, answer questions about codebase structure.

Agent({
  description: "Search API endpoints",
  prompt: "Find all REST API endpoint definitions...",
  subagent_type: "Explore"
})
  • Tool pool: Read-only tools (Glob, Grep, Read, Bash)
  • Model: Haiku (fast, low cost)
  • Characteristics: Cannot modify files; fast; ideal for research

2.3 Plan (Planning Agent)

Use case: Design implementation plans, analyze architectural trade-offs, generate step-by-step plans.

Agent({
  description: "Plan refactoring",
  prompt: "Design a plan to split the monolith into microservices...",
  subagent_type: "Plan"
})
  • Tool pool: Read-only tools (same as Explore)
  • Model: Inherited from parent (requires strong reasoning)
  • Characteristics: Outputs structured plans including key files and dependency analysis

2.4 verification (Verification Agent)

Use case: Independently verify that an implementation is correct, run tests, perform boundary checks.

Agent({
  description: "Verify login feature",
  prompt: "Verify the newly implemented login feature works correctly...",
  subagent_type: "verification"
})
  • Tool pool: Read-only tools
  • Model: Inherited from parent
  • Characteristics: Always runs in the background; outputs PASS/FAIL/PARTIAL verdicts; displayed with a red badge

2.5 claude-code-guide (Guide Agent)

Use case: Answer questions about Claude Code, Agent SDK, or the Claude API.

Agent({
  description: "Query Claude API usage",
  prompt: "How do I use the tool_use feature...",
  subagent_type: "claude-code-guide"
})
  • Tool pool: Bash, Read, WebFetch, WebSearch
  • Model: Haiku
  • Characteristics: Focused on documentation queries; uses the dontAsk permission mode

2.6 statusline-setup (Status Bar Configuration Agent)

Use case: Configure the Claude Code status bar display.

  • Tool pool: Read + Edit only
  • Model: Sonnet
  • Characteristics: Highly specialized with an extremely narrow scope

Agent Type Comparison

AgentAccessTool PoolModelPurpose
general-purposeRead/WriteAllInheritedGeneral tasks
ExploreRead-onlySearch + ReadHaikuQuick exploration
PlanRead-onlySearch + ReadInheritedArchitecture planning
verificationRead-onlySearch + ReadInheritedIndependent verification
claude-code-guideRead-onlySearch + WebHaikuDocumentation guide
statusline-setupRead/WriteRead + EditSonnetStatus bar config

3. How to Spawn Agents

Parameters

The Agent tool accepts the following parameters:

ParameterTypeRequiredDescription
descriptionstringYes3-5 word task summary
promptstringYesFull task description
subagent_typestringNoAgent type (see table above)
modelstringNoModel override: sonnet/opus/haiku
run_in_backgroundbooleanNoWhether to run in background
namestringNoName the agent so it can be addressed via SendMessage
team_namestringNoJoin a specified team
modestringNoPermission mode
isolationstringNoIsolation mode: worktree

Foreground Synchronous Execution (Default)

The simplest usage — the agent completes and returns its result:

Agent({
  description: "Analyze error logs",
  prompt: "Read the latest error logs under logs/ and summarize common error patterns"
})

The primary agent waits for the subagent to finish, then receives the result and continues working.

Background Asynchronous Execution

Suitable for time-consuming tasks where the primary agent can continue with other work:

Agent({
  description: "Full code review",
  prompt: "Review all TypeScript files under src/ for code quality...",
  run_in_background: true
})
  • The agent immediately returns an async_launched status with a taskId
  • The primary agent continues working without waiting
  • When the agent completes, a <task-notification> is delivered automatically
  • The notification includes task status, output file path, and a result summary

Spawning Multiple Agents in Parallel

Spawn multiple independent agents in a single message for true parallelism:

// Launch 3 explore agents simultaneously
Agent({ description: "Explore frontend", prompt: "...", subagent_type: "Explore", run_in_background: true })
Agent({ description: "Explore backend", prompt: "...", subagent_type: "Explore", run_in_background: true })
Agent({ description: "Explore database", prompt: "...", subagent_type: "Explore", run_in_background: true })

Worktree Isolation

Let an agent work in an isolated git worktree without affecting the main workspace:

Agent({
  description: "Experimental refactor",
  prompt: "Try refactoring module X into...",
  isolation: "worktree"
})
  • Automatically creates a git worktree (on an independent branch)
  • The agent can freely modify files in the isolated environment
  • If changes were made, returns the worktree path and branch name on completion
  • If no changes were made, cleans up automatically

4. Background Task Management

Agent Spawn Flow

Task States

Background agents have four possible states:

StateDescription
runningCurrently executing
completedFinished successfully
failedExecution failed
killedManually terminated

Progress Tracking

Background agent progress updates in real time:

  • Token usage: Input/output token counts
  • Tool usage: Number of tools invoked
  • Recent activity: Descriptions of the last 5 tool calls (circular buffer)
  • Last activity time: Used to detect stuck tasks

Completion Notifications

When a background agent finishes, the primary agent receives an XML-formatted notification:

xml
<task-notification>
  <task-id>abc123</task-id>
  <status>completed</status>
  <summary>Agent "Explore frontend" completed</summary>
  <output-file>~/.claude/temp/.../tasks/abc123.output</output-file>
</task-notification>

Automatic Backgrounding

When the tengu_auto_background_agents feature flag is enabled, foreground agents that run for more than 120 seconds are automatically moved to background execution, freeing the primary agent to continue working.


5. Agent Teams — Multi-Agent Collaboration

Agent Teams Collaboration

Agent Teams is an advanced multi-agent collaboration mode where multiple agents work as a team, coordinating tasks through message-based communication.

Creating a Team

TeamCreate({
  team_name: "feature-team",
  description: "Develop user authentication feature"
})

After team creation:

  • A team configuration file is generated: ~/.claude/teams/{team_name}/config.json
  • A shared task directory is created: ~/.claude/tasks/{team_name}/
  • The current agent automatically becomes the Team Lead

Adding Team Members

Spawn teammates by specifying name and team_name in the Agent tool:

Agent({
  description: "Frontend development",
  prompt: "Implement the login page React components...",
  name: "frontend-dev",
  team_name: "feature-team"
})

Agent({
  description: "Backend development",
  prompt: "Implement the authentication API endpoints...",
  name: "backend-dev",
  team_name: "feature-team"
})

Teammate Communication

Send messages using the SendMessage tool:

// Send to a specific teammate
SendMessage({
  to: "frontend-dev",
  message: "API interface is ready, the format is...",
  summary: "Notify API interface format"
})

// Broadcast to all teammates
SendMessage({
  to: "*",
  message: "Everyone pause, requirements have changed...",
  summary: "Broadcast requirements change"
})

Shutdown Coordination

When the task is complete, the Team Lead requests teammates to shut down:

// 1. Send shutdown request
SendMessage({
  to: "frontend-dev",
  message: { type: "shutdown_request", reason: "Task completed" }
})

// 2. Teammate responds with approval
SendMessage({
  to: "team-lead",
  message: { type: "shutdown_response", request_id: "...", approve: true }
})

// 3. After all teammates shut down, clean up the team
TeamDelete()

Execution Backends

Agent Teams supports two execution backends:

BackendDescriptionUse Case
in-processRuns in the same process, isolated via AsyncLocalStorageDefault mode; lightweight and efficient
tmuxRuns in a separate tmux paneWhen an independent terminal view is needed
iTerm2Runs in a separate iTerm2 windowFor macOS iTerm2 users

6. Custom Agents

In addition to built-in agents, you can create your own specialized agents.

Definition Format

Create a .md file in the .claude/agents/ directory:

markdown
---
name: code-reviewer
description: Professional code review agent
tools:
  - Read
  - Grep
  - Glob
  - Bash
model: sonnet
permissionMode: dontAsk
maxTurns: 10
---

You are a professional code reviewer. Check the following aspects:

1. Code quality and readability
2. Potential security vulnerabilities
3. Performance issues
4. Adherence to best practices

Configurable Fields

FieldTypeDescription
namestringAgent type name
descriptionstringDescription of when to use this agent
toolsstring[]Allowed tool list (['*'] for all)
disallowedToolsstring[]Disallowed tool list
modelstringModel to use (sonnet/opus/haiku/inherit)
permissionModestringPermission mode
maxTurnsnumberMaximum conversation turns
mcpServersobject[]Required MCP servers
hooksobjectAgent-specific hooks
skillsstring[]Available skills
memorystringMemory scope (user/project/local)
isolationstringIsolation mode (worktree/remote)
backgroundbooleanWhether to run in background by default

Loading Priority

Custom agents are loaded according to the following priority:

  1. Built-in agents (built-in) — System predefined
  2. Plugin agents (plugin) — Registered via plugins
  3. User agents (user) — ~/.claude/agents/
  4. Project agents (project) — .claude/agents/ (project-level)
  5. Flag agents (flag) — Registered via API
  6. Policy agents (policy) — Organization policies

Agents with the same name are overridden according to priority.


7. Permission Modes

Each agent can be configured with a different permission mode:

ModeDescription
defaultNormal permission requests requiring user confirmation
planAll operations require explicit approval
acceptEditsFile edits are auto-approved; other operations require confirmation
bypassPermissionsSkip all permission checks
dontAskReject all operations not pre-approved
autoAI-driven permission classification (Anthropic internal only)
bubblePermission prompts bubble up to the parent agent's terminal

8. Quick Reference

ActionMethod
Spawn a subagentAgent({ prompt: "...", subagent_type: "Explore" })
Run in backgroundAgent({ ..., run_in_background: true })
Spawn in parallelSend multiple Agent calls in a single message
Worktree isolationAgent({ ..., isolation: "worktree" })
Create a teamTeamCreate({ team_name: "..." })
Send a messageSendMessage({ to: "name", message: "..." })
Broadcast a messageSendMessage({ to: "*", message: "..." })
Request shutdownSendMessage({ to: "name", message: { type: "shutdown_request" } })
Delete a teamTeamDelete()
Custom agentCreate a definition file in .claude/agents/*.md
Specify a modelAgent({ ..., model: "haiku" })
Name an agentAgent({ ..., name: "researcher" })

Released under the MIT License.