How to run several Claude Code agents in parallel
How do I run more than one Claude Code agent at the same time without them breaking each other's work? Give each agent its own git worktree: run claude --worktree <name> in a separate terminal for each task, or switch
How do I run more than one Claude Code agent at the same time without them breaking each other's work?
Give each agent its own git worktree: run claude --worktree <name> in a separate terminal for each task, or switch on Worktree in the desktop app. Then watch them from one screen with claude agents, and merge each branch only after you've checked it.
Why not just open two terminals?
Two agents in the same folder edit the same files. One saves, the other saves over it, and neither notices. A git worktree fixes that: it's a second working folder with its own branch, sharing the same history as your project. Each agent gets its own, so their edits can't collide until you choose to merge them.
Before you start
-
Make one commit. A worktree is created from an existing commit. In a project with none, Claude Code stops with
Failed to resolve base branch "HEAD". -
Run Claude once in the project. Type
claudein the project folder and accept the trust prompt. Without it,--worktreeexits with an error. -
Ignore the worktrees folder. Add
.claude/worktrees/to.gitignoreso the copies don't show up as new files in your main project. -
Bring your secrets along. Files like
.envare ignored by git, so a fresh worktree won't have them. Create a.worktreeincludefile at the project root, same syntax as.gitignore, listing for example.envand.env.local.
Start one agent per task
Open a terminal in your project and start the first agent with a name for its task:
claude --worktree contact-form
Claude Code creates the folder .claude/worktrees/contact-form/ on a new branch called worktree-contact-form, and starts the session there. Open a second terminal and do the same with another name:
claude --worktree pricing-page
The short form is -w. Each worktree is a fresh copy, so the first thing to ask each agent is usually to install the dependencies.
Pick tasks that don't overlap
Split by feature, not by layer. "Contact form" and "pricing page" touch different files. "Rewrite the database" and "add a field to the user profile" touch the same ones, and you'll spend the time you saved fixing merge conflicts. If two tasks depend on each other, run them one after the other.
Watch them all from one screen
Switching between terminals gets old fast. Claude Code has a view for this, in research preview:
claude agents
It lists your background sessions grouped by state: waiting for you, working, idle, done or failed. Press Space on a row to see the latest output and reply without leaving the list, Enter to open the full conversation, and β on an empty prompt to go back. You can also send tasks straight to the background from a shell:
claude --bg --name "contact-form" "add a contact form that emails me"
To move a session you already have open into the background, type /bg in it. Background sessions keep running after you close the view or the terminal.
Prefer windows? Use the desktop app
In Anthropic's desktop app, press Cmd+N (Ctrl+N on Windows) for a new session and switch on Worktree before you send the first message. Worktrees land in the same .claude/worktrees/ folder. Open sessions side by side in split view, and review each one's changes in its Changes panel. (If you're weighing other apps, here's a comparison of Claude Code GUIs.)
Review and merge one branch at a time
When an agent says it's done, look at what changed against your main branch before anything else:
git diff --stat main...worktree-contact-form
If it matches what you asked, open a pull request from inside the session ("create a pr"), or merge it yourself:
git switch main
git merge worktree-contact-form
Merge one, run your app, then merge the next. If the second branch conflicts with the first, ask its agent to update from main and resolve it: it knows its own changes best.
Clean up
When you leave a worktree session, Claude Code checks for unsaved work. A clean, unnamed worktree is removed with its branch. If there's work in it, you're asked whether to keep it, and Claude Code prints the command to come back later. To see and remove leftovers yourself:
git worktree list
git worktree remove .claude/worktrees/contact-form
Keep an eye on usage
Every session draws on your plan's quota independently, so four agents use it roughly four times as fast. Start with two or three, see how far your plan goes, and add more once you know.
Questions
How many agents can I run at once?
There's no fixed number in the docs, but each session uses your plan's quota on its own. Three or four at once is a sensible start.
What's the difference between worktrees and subagents?
Worktrees give separate sessions their own copy of the files. Subagents split work inside one session. Use worktrees when the tasks are independent features.
Why is my .env missing in the worktree?
A worktree is a fresh checkout, so ignored files aren't there. List them in a .worktreeinclude file at the project root and Claude Code copies them in.
Do I need GitHub for this?
No. Worktrees are plain git. You only need GitHub if you want a pull request for each branch.
Sources
- Claude Code docs: run parallel sessions with worktrees
- Claude Code docs: common workflows
- Claude Code docs: background agents (agent view)
- Claude Code docs: desktop app
- Git documentation: git worktree
Checked on 23 November 2026.
Originally published on escadreai.com. Escadre is a Mac app that runs several coding agents side by side and tells you whether each result matches what you asked: free macOS beta.
Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.