How it works
The core primitive is theAgent tool (internally AGENT_TOOL_NAME = 'Agent', with a legacy alias Task for backward compatibility). When Claude invokes this tool, it launches a new agent with its own context, system prompt, and tool pool.
async_launched status so the coordinator can continue).
Input schema
TheAgent tool accepts the following parameters (defined in tools/AgentTool/AgentTool.tsx):
| Parameter | Type | Description |
|---|---|---|
description | string | Short (3–5 word) label shown in the UI |
prompt | string | Full task instructions for the agent |
subagent_type | string (optional) | Which agent definition to use (e.g. worker, verification) |
model | sonnet | opus | haiku (optional) | Override the agent’s default model |
run_in_background | boolean (optional) | Run async; parent gets an async_launched result |
name | string (optional) | Addressable name for SendMessage routing |
team_name | string (optional) | Spawn as a teammate in an agent swarm |
isolation | worktree (optional) | Run in an isolated git worktree |
cwd | string (optional) | Override the working directory for this agent |
Coordinator mode
Coordinator mode is activated by settingCLAUDE_CODE_COORDINATOR_MODE=1. The coordinator has a different system prompt and tool set, and all agent spawns are forced async — workers send <task-notification> XML back as user-role messages when they complete.
The coordinator never uses the
model parameter on Agent calls. Workers get the default model for substantive tasks.coordinator/coordinatorMode.ts) gives it a structured workflow:
Research
Spawn multiple read-only workers in parallel to investigate the codebase. Launch them simultaneously with multiple
Agent tool calls in a single turn.Synthesis
Read findings and write a specific implementation spec — include file paths, line numbers, and exact changes. Never write “based on your findings.”
Task notifications
When a background agent completes, the coordinator receives a<task-notification> message:
task-id to continue the same worker with SendMessage:
Built-in agent types
Defined intools/AgentTool/builtInAgents.ts:
general-purpose
Default agent used when no
subagent_type is specified. Runs with the full tool pool.worker
Available in coordinator mode. Gets access to Bash, Read, Edit, and MCP tools. Use
subagent_type: "worker" when operating as a coordinator.Explore
One-shot research agent. Investigates and reports findings without modifying files.
Plan
One-shot planning agent. Creates implementation plans from research output.
verification
Runs tests and typechecks to verify changes. Use
subagent_type: "verification".statusline-setup
Sets up shell statusline integrations. Internal use.
Explore and Plan are one-shot agents — the coordinator never sends follow-up SendMessage calls to them. This saves ~135 tokens per run by omitting the agentId/SendMessage/usage trailer (see constants.ts:ONE_SHOT_BUILTIN_AGENT_TYPES).Async vs synchronous agents
By default, agents run synchronously and block the parent turn. Setrun_in_background: true (or define background: true in the agent definition) to run asynchronously.
Async agents return immediately:
outputFile path can be read with the Read or Bash tools to poll progress before the notification arrives.
Worktree isolation
Passisolation: "worktree" to run an agent in a temporary git worktree. The worktree is created before the agent starts and cleaned up afterward — unless the agent made changes, in which case it is preserved at the reported worktreePath.
agent-{first-8-chars-of-agentId} and createAgentWorktree handles the git plumbing (utils/worktree.ts).
Agent swarms (TeamCreate/TeamDelete)
Whenteam_name and name are both provided, the Agent tool routes to spawnTeammate() instead of a regular sub-agent. Teammates are launched in separate tmux panes and appear in the team roster.
SendMessage({ to: "frontend", message: "..." }).
Constraints:
- Teammates cannot spawn other teammates (the roster is flat)
- In-process teammates cannot spawn background agents
- Only one team lead manages the roster
Concurrency model
The coordinator system prompt recommends:| Task type | Concurrency |
|---|---|
| Research (read-only) | Parallel — launch freely |
| Implementation (writes) | Serial per file set |
| Verification | Can run alongside implementation on different files |
Agent tool calls in a single coordinator turn.
Environment variables
| Variable | Effect |
|---|---|
CLAUDE_CODE_COORDINATOR_MODE=1 | Enable coordinator mode |
CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 | Disable all background/async agents |
CLAUDE_AUTO_BACKGROUND_TASKS=1 | Auto-background agents after 120 seconds |
CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS=1 | Disable built-in agents in non-interactive (SDK) mode |