The job: “Get several independent pieces of a project done at the same time without the agents overwriting each other”

Run Claude Code agents in parallel: subagents vs agent teams vs git worktrees

Pick the right way to run several Claude agents on one project at once: parallel subagents, worktree-isolated sessions, agent view or experimental agent teams. Includes a tested two-agent run where each agent got its own git worktree, and a check for when parallel work hurts.

  • Level Intermediate
  • Time 30 minutes for the test run, then minutes per parallel job
  • Works with
    • Claude Code
    • Claude Desktop
On this page12 sections

One Claude agent works through tasks one at a time. When you have three jobs that don’t depend on each other, such as a new helper function, a bug fix and a test file, you can run them at the same time. The risk is that two agents edit the same file and overwrite each other’s work. This guide covers the options Anthropic documents for Claude Code, which one to use when, and a run you can repeat in a few minutes.

We tested the core idea on a tiny made-up Python project. One claude -p prompt asked for two subagents running in parallel, each in its own git worktree. It finished in 22 seconds. Each agent committed to its own branch with passing tests, and our main checkout had no changes. We merged both branches ourselves, and all 12 tests passed (including two we’d written beforehand). Agent teams and agent view weren’t part of the test: agent teams don’t start teammates in claude -p runs, and agent view is an interactive screen.

What you’ll have at the end

  • A clear choice between subagents, worktrees, agent view and agent teams for your next job.
  • A tested prompt that runs two coding tasks in parallel in isolated worktrees.
  • The git commands to check, merge and clean up after parallel agents.
  • A quick test for whether a job should run in parallel at all.

What you need (and cost)

  • Claude Code on a Pro, Max, Ultra, Team or Enterprise plan, or a Console (API) account. The free claude.ai plan doesn’t include it.
  • A git repository. Worktrees need git. Run git init and make one commit if your project isn’t in git yet.
  • Usage. Anthropic’s docs say running several sessions or subagents at once multiplies token usage, and that agent teams use “significantly more tokens than a single session”. Parallel work makes things faster, not cheaper.

The options, side by side

From Anthropic’s Run agents in parallel page:

OptionWhat it isStatusUse it when
SubagentsHelpers inside one session. Each has its own context and returns a summary.StandardA side job would flood your chat, or you want 2-5 independent pieces done and reported back.
WorktreesA separate git checkout and branch for each session or subagent, so edits can’t collide.StandardAny time two agents edit files at the same time.
Agent view (claude agents)One screen to send off and watch several background sessions.Research previewYou have several unrelated tasks and want to check back later.
Agent teamsA lead session plus teammates with a shared task list, who message each other.Experimental, off by defaultWorkers need to talk, such as reviewers challenging each other’s findings.

The same page also lists dynamic workflows (scripts that run many subagents) and projects (cloud threads on claude.ai/code), and mentions /batch, a built-in skill that splits one large change into 5 to 30 worktree-isolated subagents.

When parallel helps, and when it hurts

Before you split a job, ask three questions:

  1. Does each piece touch its own files? Anthropic’s agent teams docs are blunt: two teammates editing the same file leads to overwrites. Worktrees help, but you still have to merge the results.
  2. Can each piece finish without waiting on another? If task B needs task A’s new function name, run them in order.
  3. Is each piece big enough? The docs warn that for tiny tasks, coordination costs more than it saves.

If any answer is “no”, the work is coupled. One agent, or a short chain of agents one after another (like the one-person company team), will be faster overall and easier to check. Parallel work does best on research and review (several angles on the same question, nothing to merge) and on separate modules with clear edges.

Step 1: Make a practice repo

mkdir parallel-test && cd parallel-test && mkdir shop
printf '"""Text helpers."""\n\n\ndef title_case(name):\n    return " ".join(w.capitalize() for w in name.split())\n' > shop/text.py
printf '"""Money helpers."""\n\n\ndef cents_to_dollars(cents):\n    return cents / 100\n' > shop/money.py
touch shop/__init__.py
printf 'import unittest\nfrom shop.text import title_case\nfrom shop.money import cents_to_dollars\n\n\nclass T(unittest.TestCase):\n    def test_title(self):\n        self.assertEqual(title_case("maple pine"), "Maple Pine")\n\n    def test_cents(self):\n        self.assertEqual(cents_to_dollars(1250), 12.5)\n' > test_shop.py
printf '.claude/worktrees/\n__pycache__/\n' > .gitignore
git init -b main && git add -A && git commit -m "init"

The .gitignore line follows Anthropic’s tip: worktrees live in .claude/worktrees/ inside your repo, and ignoring that folder keeps them out of your main checkout’s file list.

Step 2: Run two tasks in parallel, each in its own worktree

Start Claude Code in the folder (claude) and paste the prompt we tested:

I have two independent tasks. Run them in parallel with two subagents, and use worktrees for your agents so their edits can't collide:

1. In shop/text.py, add slugify(name): lowercase, spaces become hyphens, drop anything that isn't a letter, number or hyphen. Add tests for it in a new file tests_text.py.
2. In shop/money.py, add format_price(cents): returns a string like "$12.50". Add tests for it in a new file tests_money.py.

Each subagent: only touch the files named in its task, run its tests with python3 -m unittest, and commit on its own branch. Don't merge anything.
When both are done, tell me each branch name, whether its tests passed, and the files it changed.

“Use worktrees for your agents” is the wording from Anthropic’s docs. Claude Code then creates a temporary worktree for each subagent, and blocks file edits and git commands aimed at your main checkout.

What came back in our run (with --permission-mode acceptEdits and tools allowed up front):

  • Two branches, slugify (4 tests, passed) and format-price (6 tests, passed), each changing only its two files.
  • git status in the main checkout: clean.
  • An honest note: the format_price agent had added handling for negative amounts that we hadn’t asked for, and Claude pointed it out.
  • Two leftover worktree-agent-... branches from the worktree setup, which Claude listed without deleting them.

Step 3: Check, merge and clean up

git worktree list          # where each agent worked
git log --oneline --all    # the agents' commits
git merge slugify
git merge format-price
python3 -m unittest        # run everything together

Both merges went through cleanly in our test, because the agents touched different files. The full test suite (12 tests) passed after the merge. That last step matters: two pieces that each pass on their own can still break each other.

Then remove the worktrees. Anthropic’s docs say Claude Code removes a subagent’s worktree on its own only if the agent made no changes. Worktrees with changes stay until a periodic cleanup, or until you remove them:

git worktree remove .claude/worktrees/<name>
# if git says it's locked:
git worktree unlock .claude/worktrees/<name>

To make one of your own agents always work in a worktree, add isolation: worktree to its frontmatter in .claude/agents/.

Step 4: Run your own sessions side by side

Sometimes you want to steer each job yourself. Open two terminals in the repo:

claude --worktree feature-auth     # terminal 1
claude --worktree bugfix-checkout  # terminal 2

Per the docs, each gets .claude/worktrees/<name>/ on a new branch worktree-<name>, which branches from your default branch. Some things to know:

  • First run: run plain claude in the repo once to accept the trust dialog, or --worktree stops with an error.
  • Fresh checkout: gitignored files such as .env aren’t copied. List them in a .worktreeinclude file at the repo root (same syntax as .gitignore), and install dependencies in each worktree.
  • On exit: if the worktree has changes, Claude asks whether to keep or remove it. Keeping it preserves the folder and branch.
  • Desktop app: in the Code tab, turn on Worktree under the prompt box before you start a session. Start more sessions with + New.

To send work off and come back later, run claude agents. Type a task and press Enter to start a background session, and do the same again for a second one. Press Space on a row to peek and reply, or Enter to open the full session. Anthropic says each session uses your quota on its own, and that a session sent off from agent view moves into its own worktree before it edits files.

Step 5 (optional): Try an experimental agent team

Agent teams are worth a look when workers should debate, such as three reviewers checking the same pull request from different angles. They’re off by default. To turn them on, add this to .claude/settings.json (or ~/.claude/settings.json):

{
  "env": {
    "CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS": "1"
  }
}

Then ask for a team in plain words in an interactive session. This prompt is Anthropic’s own example. We didn’t run it, because teams don’t start in claude -p:

Spawn three teammates to review PR #142:
- One focused on security implications
- One checking performance impact
- One validating test coverage
Have them each review and report findings.

What the docs say to expect:

  • Teammates appear in a panel below the prompt. Use the arrow keys and Enter to read or message one. Split panes need tmux or iTerm2.
  • Teammates don’t get worktrees. Give each one its own files.
  • Start with 3-5 teammates. Anthropic suggests Sonnet for teammates to keep costs down.
  • Limits: /resume doesn’t bring teammates back, there’s one team per session, teammates can’t start their own teams, and task status can lag.
  • With teams turned on, Claude may start teammates when it names a subagent, even if you didn’t ask for a team. Set the variable back to 0 to stop that.

What can go wrong

  • Agents edit the same file. Name the files each agent may touch in the prompt, as in step 2. If the work can’t be split that way, it’s coupled. Run it in one session.
  • A merge conflict after parallel work. Merge one branch, run the tests, then merge the next. Ask Claude to resolve the conflict in the main checkout, and review the result yourself.
  • Parallel agents “agree” on different designs. Two agents building against an API that doesn’t exist yet will each guess its shape. Agree on the interface first, in writing, then go parallel.
  • Worktrees pile up. Check git worktree list once a week, and remove the ones you’ve merged.
  • Too many permission prompts. Background subagents and teammates send their prompts to your main session. Allow common safe commands ahead of time in your permission settings, and don’t skip permissions entirely in a repo with secrets or deploy scripts.
  • Usage limits sooner than expected. Three agents running at once use roughly three agents’ worth of tokens. Use parallel runs for real time savings, not by habit.

Make it yours

  • Read-only fan-out first. The safest parallel job is research or review that doesn’t edit anything, such as three subagents each auditing one folder. Nothing to merge, so nothing to break.
  • Pair with a reviewer. After a parallel run, have the independent reviewer from the one-person company guide check the merged result.
  • Night shift. Combine with scheduled agent tasks so a cloud run opens branches while you sleep, and you merge in the morning.
  • Parallel UI work. Split a page build by component when you turn a screenshot into working UI.

Next steps

Sources

Facts checked against these sources on . Page updated . How we check facts

  1. code.claude.com/docs/en/agents (opens in a new tab)
  2. code.claude.com/docs/en/sub-agents (opens in a new tab)
  3. code.claude.com/docs/en/worktrees (opens in a new tab)
  4. code.claude.com/docs/en/agent-teams (opens in a new tab)
  5. code.claude.com/docs/en/agent-view (opens in a new tab)
  6. code.claude.com/docs/en/desktop (opens in a new tab)
  7. code.claude.com/docs/en/cli-reference (opens in a new tab)
  8. code.claude.com/docs/en/costs (opens in a new tab)
  9. code.claude.com/docs/en/setup (opens in a new tab)

Related guides

All guides