Skip to main content
Agent swarms let Claude Code break a large task into parallel workstreams — each handled by an independent sub-agent with its own context window. The primary (coordinator) session orchestrates the agents, synthesizes their results, and directs follow-up work.
Agent swarms consume significantly more tokens and API calls than single-agent sessions. Each sub-agent runs its own full conversation. Use swarms when the parallelism benefit clearly outweighs the cost.

Core tools

AgentTool — spawning sub-agents

AgentTool (internal name: Task) is how Claude spawns a sub-agent. Each call starts a new Claude session with its own isolated context:
Key parameters: Workers run autonomously — they do not need further messages unless you continue them with SendMessageTool.

SendMessageTool — continuing a running agent

SendMessageTool sends a follow-up message to a worker that has already completed a turn. Use it to give a worker a synthesized implementation spec after it finishes research, or to correct a failed attempt without spawning a fresh worker:
The worker ID (to field) comes from the task_id returned by AgentTool when the worker was spawned.

TaskCreateTool / TaskUpdateTool — task tracking

TaskCreateTool and TaskUpdateTool let the coordinator create and update structured task records that can be shared across agents. This provides a lightweight coordination layer for tracking progress on multi-file or multi-phase work.

TeamCreateTool / TeamDeleteTool — managing agent teams

TeamCreateTool creates a named team of agents that can share a communication channel. Use teams when you need multiple long-running workers to coordinate with each other, not just with the coordinator:
TeamDeleteTool tears down a team once its work is complete.

Coordinator mode

Coordinator mode is a special session configuration that gives Claude a tailored system prompt optimized for multi-agent orchestration. Enable it by setting the CLAUDE_CODE_COORDINATOR_MODE environment variable:
In coordinator mode, Claude is instructed to:
  • Parallelize — launch independent research and implementation workers concurrently
  • Synthesize — read worker findings and write specific, actionable follow-up prompts rather than delegating understanding
  • Verify separately — use a dedicated verification worker with fresh context to prove changes work
  • Report to the user — summarize progress after each batch of worker results
Workers spawned in coordinator mode receive a context message listing the tools available to them, including MCP tools from connected servers and skills via SkillTool.

Inter-agent communication

When a worker finishes a turn, the coordinator receives a <task-notification> message in the conversation:
The task-id is the agent ID to use with SendMessageTool. The result field contains the worker’s final response.

Worktree isolation

When running parallel agents that modify files, use worktree mode to give each agent an isolated git working tree so their changes don’t conflict:
The EnterWorktreeTool / ExitWorktreeTool tools manage per-agent worktrees programmatically. In bridge mode, the worktree spawn mode creates a fresh git worktree for each incoming session automatically. Configure worktree behavior in settings.json:
  • symlinkDirectories — symlink these directories from the main repo into each worktree to avoid duplicating large directories
  • sparsePaths — use git sparse checkout to only populate these paths in worktrees (significantly faster in large monorepos)

Example: parallel refactor

The following shows how a coordinator session structures a multi-agent refactor:

Use cases

  • Parallel test runs — run different test suites in separate agents simultaneously
  • Large refactors — split file-by-file changes across agents (use worktrees to avoid conflicts)
  • Multi-file changes — research in one agent, implement in parallel workers, verify in a separate agent
  • Codebase exploration — fan out read-only research agents across different subsystems at once
  • Iterative fixes — fix one agent’s failure with SendMessageTool while other agents continue working

Agent tools

Full reference for AgentTool, SendMessageTool, TeamCreateTool, and related tools.

Architecture

Understand how Claude Code’s tool and query engine work.

Headless mode

Run Claude Code non-interactively for automated pipelines.

Skills

Skills that workers can invoke during swarm execution.