Skip to main content
Claude Code can spawn sub-agents to work on tasks in parallel. A single Claude instance can act as a coordinator that breaks work into pieces, delegates each piece to a sub-agent, and assembles the results—or multiple Claude instances can collaborate as a team. This page covers how the agent system works and how to create custom agents.

The Agent tool

The primary mechanism for multi-agent work is the Agent tool (wire name Task for backward compatibility). When Claude calls this tool it spawns a sub-agent with its own conversation context, tool access, and (optionally) an isolated git worktree. The tool accepts the following parameters: Sub-agents inherit parent permissions by default. When isolation: "worktree" is set, the agent receives a fresh git worktree so its filesystem changes don’t interfere with the parent.

Background tasks

When run_in_background: true is passed, the sub-agent runs asynchronously. Claude receives a notification when it completes. Background tasks auto-activate after 120 seconds of non-interaction when CLAUDE_AUTO_BACKGROUND_TASKS is set or the corresponding feature flag is enabled. You can disable background tasks entirely with CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1. Background tasks are visible and manageable with the /tasks command (also aliased as /bashes).

Built-in agents

Claude Code ships several built-in agents that are always available:
Built-in agents can be disabled for SDK use by setting CLAUDE_AGENT_SDK_DISABLE_BUILTIN_AGENTS=1 (only effective in non-interactive/SDK mode).

Custom agents

You can define custom agents in Markdown files placed in the .claude/agents/ directory. Claude Code loads agents from:
  • Project agents: .claude/agents/ — scoped to the current project
  • User agents: ~/.claude/agents/ — available in all projects
  • Managed agents: loaded from managed settings (enterprise/MDM)
  • Plugin agents: provided by installed plugins
Each agent is a Markdown file whose frontmatter defines its metadata:

Agent frontmatter fields

The body of the Markdown file becomes the agent’s system prompt.

Agent definition types

You can check whether a server or tool requirement is met via requiredMcpServers—agents that declare required MCP servers are hidden from the selector when those servers are not configured.

Agent teams and swarms

Agent teams are an experimental feature. Enable them with CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 or the --agent-teams CLI flag. A remote feature gate must also be active.
When agent teams are enabled, Claude can spawn teammate agents that run as peer processes rather than direct sub-agents. Teammates can receive follow-up messages from the coordinator and collaborate asynchronously.

Coordinator mode

Setting CLAUDE_CODE_COORDINATOR_MODE=1 replaces the standard built-in agent list with coordinator-specific agents designed to manage a pool of worker agents.

Team parameters (Agent tool)

When agent teams are enabled, the Agent tool gains additional parameters:

Use cases

Spawn one agent per test suite. Each runs in an isolated worktree so filesystem side-effects do not conflict.
Claude will use Agent with run_in_background: true and isolation: "worktree" for each suite, then wait for all to complete.
Delegate independent modules to separate agents. The coordinator collects their diffs and resolves conflicts.
Use the built-in Explore agent to map the codebase, then spawn an implementation agent with the exploration results as context.