Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

Claude Code Subagents and Parallel Agents

How Claude Code splits work across agents: subagents, agent teams (experimental), --worktree and manual sessions, what each shares, and how parallel runs fail. Checked 2026-11-11.

TL;DR

  • Subagents run inside one session in their own context and return a summary. Agent teams are experimental and disabled by default: a lead coordinates teammates that share a task list and message each other. Worktrees separate files and branches for sessions you run yourself.
  • Subagent definitions are Markdown files in .claude/agents/ or ~/.claude/agents/. On a name clash the higher-priority location wins, and only name and description are required.
  • A worktree does not separate anything outside the checkout, such as a dev database or a port, and agent teams don't put teammates in worktrees, so give each agent its own files, port and data.

This page is a map of splitting work across more than one Claude Code agent: subagents inside one session, agent teams, and sessions you run in parallel with git worktrees. It covers what each approach separates and shares, how to define a subagent, what goes wrong in parallel runs, and the order in which to read our articles on the topic. Every fact was checked against the official docs on 2026-11-11, when the latest Claude Code on npm was 2.1.322.

We did not run any command for this hub. Where the docs did not state something, we left it out or marked it “unverified”.

Ways to run work in parallel

ApproachHow it startsSeparateShared
SubagentClaude delegates on its own, or you ask (“use a subagent to…”) or @-mention oneIts own context window; only a summary comes backThe session’s working directory, unless the subagent has isolation: worktree. Its requests count toward the same usage
Agent team (experimental, off by default)Set CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1, then ask Claude for teammates in an interactive sessionEach teammate is a separate Claude Code instance with its own context windowA task list and a mailbox. Teammates load the same CLAUDE.md, MCP servers and skills and start in the lead’s permission mode. They are not put in worktrees
claude --worktree <name>One command per terminalFiles and branch: .claude/worktrees/<name>/ on a branch named worktree-<name>The repository’s .git directory, project-scope plugins, “don’t ask again” approvals, and the main checkout’s untracked skills, agents and commands when the worktree has none of its own
Separate sessions by handgit worktree add, then claude in each directoryWhatever you set upEverything outside the checkout. Cross-session messaging lets those sessions pass findings to each other

(source: https://code.claude.com/docs/en/agents, checked 2026-11-11) (source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-11) (source: https://code.claude.com/docs/en/agent-teams, checked 2026-11-11) (source: https://code.claude.com/docs/en/worktrees, checked 2026-11-11)

The docs list two more approaches. Agent view (claude agents, a research preview) dispatches and monitors background sessions. Dynamic workflows run many subagents from a script and cross-check their results. /batch is a skill that splits one large change into 5 to 30 worktree-isolated subagents. We have not written about these yet.

Details from the docs that change how you plan:

(source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-11) (source: https://code.claude.com/docs/en/agent-teams, checked 2026-11-11) (source: https://code.claude.com/docs/en/costs, checked 2026-11-11)

Defining a subagent

A subagent is a Markdown file with YAML frontmatter. The body becomes its system prompt, and it does not receive Claude Code’s own system prompt. /agents no longer opens an editor; it reminds you to ask Claude or edit the directories directly.

PriorityLocationScope
1 (highest)Managed settingsOrganization
2--agents at launchThat session
3.claude/agents/The project
4~/.claude/agents/All your projects
5A plugin’s agents/ directoryWhere the plugin is enabled

On a name clash, the higher-priority definition wins. The frontmatter name identifies the subagent, not the filename. Edited files are picked up within a few seconds, but a new agents directory that did not exist at session start needs a restart.

The frontmatter keys most definitions need:

(source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-11)

Failures in parallel runs and fixes

A worktree has only committed files. Our subagent failures article found that a gitignored verify script was missing in every lane. A subagent with isolation: worktree branches from the repository’s default branch, not the parent session’s HEAD, unless worktree.baseRef is "head". A .worktreeinclude file copies files that match its patterns and are also gitignored into each new worktree.

A worktree does not separate what lives outside the checkout. Our worktree resources test showed a dev database and the default port shared across worktrees, and a cleanup that deleted the local database with the worktree. The fix was a gitignored .env.local per worktree with its own port and database path.

Isolation checks stop git and edits, not every write. While a session is isolated in a worktree, Claude Code blocks edits and git commands aimed at the main checkout. A command that writes there without running git, such as cp or a shell redirect, is not refused by those checks. Hooks keep ${CLAUDE_PROJECT_DIR} pointing at the main checkout.

Agent teams share files. The docs say two teammates editing the same file leads to overwrites; give each teammate its own set of files.

Leftovers. -p runs have no exit prompt, so their worktrees stay until you run git worktree remove, after git worktree unlock if git says it is locked.

Reports are claims. Our failures article puts guards in every prompt (no --amend, both paths named, findings written to a file, stop with BLOCKED when unsure) and checks results with git rather than the self-report.

(source: https://code.claude.com/docs/en/worktrees, checked 2026-11-11) (source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-11) (source: https://code.claude.com/docs/en/agent-teams, checked 2026-11-11)

Splitting memory and context

Each subagent starts with a fresh context window. It does not see your conversation history, the skills you already invoked or the files Claude already read. It gets the task message, CLAUDE.md files (Explore and Plan skip them, and omitClaudeMd: true turns them off), a git status snapshot and any preloaded skills. It does not inherit auto memory.

With memory set to user, project or local, a subagent keeps its own memory directory, such as .claude/agent-memory/<name>/ for project, and the first 200 lines or 25KB of its MEMORY.md load at startup. The docs recommend project as the default scope.

A teammate loads CLAUDE.md, MCP servers and skills like a regular session, but not the lead’s conversation history, so put task details in the spawn prompt. A subagent in its own worktree takes its instruction files from the main conversation, not from the worktree.

How we split lasting policy from current state, and why notes rot, is in Designing Agent Memory.

(source: https://code.claude.com/docs/en/sub-agents, checked 2026-11-11) (source: https://code.claude.com/docs/en/agent-teams, checked 2026-11-11) (source: https://code.claude.com/docs/en/worktrees, checked 2026-11-11)

Reading order

These are starting points, not a ranking. Read top to bottom if you are new to running more than one agent.

  1. How to Define Claude Code Subagents: built-in subagents, file locations, frontmatter, model choice and tool limits.
  2. Run Parallel AI Agents with Git Worktrees: git worktree basics, --worktree, setup per worktree and cleanup.
  3. Git Worktrees Don’t Isolate Your Database or Ports: a reproducible test of shared data and ports, and a per-worktree fix.
  4. Subagent Failures in Parallel Runs: missing files in worktrees, split handover notes, prompt guards and checking results.
  5. Designing Agent Memory: memory indexes, handover files and notes that go stale.
  6. Claude Code Code Review: /code-review vs Managed PR Reviews: /code-review runs as a background subagent with its own context.

Summary

FAQ

What is the difference between subagents and agent teams in Claude Code?
A subagent works inside one session in its own context window and returns a result to the caller, and the main agent manages the work. In an agent team, each teammate is a separate Claude Code instance; teammates message each other directly and coordinate through a shared task list. The docs say teams use more tokens and are experimental.
How do I turn on agent teams?
Set CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS to 1 in your environment or in the env block of settings.json, then ask Claude for teammates in an interactive session. In -p mode Claude does not spawn teammates.
Where do subagent definition files go, and which one wins on a name clash?
Project subagents go in .claude/agents/ and personal ones in ~/.claude/agents/. The priority is managed settings, then the --agents flag, then .claude/agents/, then ~/.claude/agents/, then a plugin's agents/ directory. The higher-priority definition wins, and the frontmatter name identifies the subagent, not the filename.
Does a git worktree stop parallel agents from sharing a database or a port?
No. A worktree has its own files and branch, but a database path or port set outside the repository is still shared. In our test, a reset in one worktree emptied the other's data and the second dev server could not bind the same port. Give each worktree its own gitignored .env.local.
Does a subagent see my conversation?
No. Each subagent starts with a fresh context window without your conversation history, the skills you already invoked or the files Claude already read. It does get CLAUDE.md files, except for Explore and Plan or when omitClaudeMd is set, and the task message Claude writes for it.