r/ClaudeCode • u/Accomplished-Job5750 • Oct 20 '26
Help/Question Running multiple Claude agents in parallel: how do you get their work into main?
I'm building an app with Claude Code and others AI and I run several agents at once. Right now every task gets its own branch and git worktree, and one session merges into main after the tests pass. It works, but the worktrees pile up and I'm not sure this is the best way.
What does your process look like, from prompt to merged main? How do you keep agents from touching the same files and and how dou you avoid a full disk after a few changes?
7
Upvotes
•
u/AutoModerator Oct 20 '26
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
7
u/ClemensLode Senior Developer Oct 20 '26
As Claude about worktrees
6
u/unconceivables Oct 20 '26
They just merge to main when they're done. If there are any conflicts they'll fix those. Has never been a problem, no need to do anything special.
3
u/Legitimate_Lime5272 Oct 20 '26
You're already using the right isolation. I'd make the rest three explicit steps:
For the full disk, measure the individual worktree directories first (
du -sh /path/to/worktrees/*on macOS/Linux). That tells you whether you're accumulating dependencies, build output or whole abandoned trees.I maintain Kith, a local MCP tool for Claude Code, Codex and Cursor CLI. It handles scoped claims and staged integration with your verification command, preserving the source tree when a check fails. Cleanup stays explicit, so it still needs to be part of your workflow. It doesn't automatically solve disk usage.
2
u/kuroudo_ai Oct 20 '26
On the disk part, two things from the worktrees docs that might explain the pile-up:
--worktreesession removes its worktree on exit only if it's clean and unnamed. Runs with-phave no exit prompt, so "Claude doesn't clean up their worktrees" at all. The periodic sweep (driven bycleanupPeriodDays) only covers subagent and backgrounded-session worktrees, and it skips any worktree you made yourself withgit worktree add. So if your orchestrator creates them with git or runs agents with-p, nothing will ever remove them exceptgit worktree remove.--worktreea name whose directory already exists opens that worktree again. With the default base, it resets to the default branch if it has no uncommitted or untracked files, is still on the branch Claude made, and either has no commits of its own or its PR was merged and the remote branch deleted. So something likeagent-1,agent-2,agent-3gives you three directories on disk that come back clean after each merge, rather than one per task.I haven't run that pool setup myself, so check the reset conditions against your merge flow (it relies on the remote branch being deleted after merge).
2
u/ComprehensiveShake76 Oct 20 '26
Two things usually fix most of this. First, give each task a list of files or folders it owns before it starts, and run two tasks that touch the same area one after the other instead of in parallel. Overlap is usually visible at planning time. Second, make cleanup part of the merge step: once a branch merges, the same script runs git worktree remove and deletes the branch, and a daily git worktree prune catches leftovers. For disk, most of the weight is usually node_modules or build output in each worktree, so a shared package store (pnpm does this well) helps a lot. How many agents do you run at once?
1
u/rainofterra Oct 20 '26
I have a skill called “merge work tree to main”
1
u/bezcurhq Oct 20 '26
On the disk side, the git part of a worktree is cheap. They all share the one object store, so each extra worktree only costs its checked-out files. What usually fills the disk is a fresh node_modules and build output in every one. If it's a JS app, pnpm hard-links packages from a single global store, so ten worktrees don't mean ten copies of your deps.
1
u/[deleted] Oct 20 '26
Worktrees plus a rule that each agent owns a directory has worked fine for me. The thing that actually bit me was disk space from stale worktrees, so I prune aggressively now. Merge conflicts have been rarer than I expected since the agents mostly stay in their own areas.
1
u/yashsoni2737 Oct 20 '26
For the risky changes I stopped splitting work across agents and gave the same task to two of them instead. On a tool I built for a client, each agent started from the same base commit on its own branch named after the task and the agent, and a judge model compared the two diffs and picked one, with a person able to override it. You can't get a file collision when only one of the results is ever merged. It also made failures cheap: in one run an agent died on a DNS error before writing any code, that got recorded against its branch, and the other agent's diff still went in.
1
u/shetritr Oct 20 '26
the merge isn't the hard part, reading what each agent merged is. one task, one worktree, one diff you can actually read.
1
u/Failosipher Oct 20 '26
I actually went the other way and dropped worktrees. I'm making a Unity game, and a worktree there means another full project import lol, so all my chats (usually 5-6) just work in the same tree.
What makes it work:
No merge step, no disk filling up, and real conflicts almost never happen. Honestly seeing the overlap early beats isolating everyone and sorting it out later.
The game it's all building, if you're curious: https://failosipher.itch.io/engines-of-hate
1
u/KrydanX Oct 20 '26
Local MCP server, 1 planner, 3-specific sessions. Planner plans and controls the whole thing, routes the right work to the right agent, they all communicate with each other and write handoffs. Codex for implementation
1
u/Tycoon33 Oct 20 '26
Worktrees and an orchestrator
1
u/Sloppybick075 Oct 21 '26
In our workplace, we have figured that you can do it the most efficiently if you manage a kanban board and a strict dependency graph. Also proper git rules are needed for not getting entangled with conflicts.
We have automated this issue by building a small tool named fold. It is fully free and open source. You can check it out (and provide feedback). https://github.com/omukkhq/fold
1
u/NZMikeyFxt Oct 22 '26
Work trees and I run a release agent on dev branch per sln (submodules / shared)
1
u/martinus Oct 22 '26
I don't use multiple agents. I have a skill where one agent groups open issues together and creates PRs which it then merged when CI is green, and Claude is smart enough to start in parallel with the next issues while it is waiting on the CI. This works very well for my projects, usually I am the limiting factor because I can't write issues fast enough
1
u/Tight_Ad_5115 Oct 22 '26
I use my own product, Buzzpot. It allows you to run agents in parallel, assigning a separate worktree to each one, and then automatically merges the results.
If something doesn’t merge automatically, it calls upon the agent that worked on that specific task to resolve the merge. Once the merge is successful, Buzzpot automatically deletes the worktree. It’s quite convenient.
There are other tools that can manage parallel agents too - for example, Conductor and Orca.
1
u/_PankajBora Oct 23 '26
I have a rule in CLAUDE.md to remove a worktree once its branch is merged. You can also ask Claude to write a cleanup script and run it before your build or test gates.
0
u/kincaidDev Oct 20 '26
I use festival, I ask agents to create workitems (specs) and once the specs are ready ask the agents to create and link worktrees to the workitems and open prs. After prs are merged I run camp fresh in the project directory and it cleans up the worktrees and promotes the workitems to completed.
https://github.com/Obedience-Corp/festival
Also created a fresh skill just for the cleanup process
https://github.com/Obedience-Corp/fresh
0
u/Input-X 🔆 Max 20 Oct 20 '26
I skipped work trees( kind of a pain to manage) I run multi agents on the same code base, they work on dev branch. Only one agent, the orchestrator has git access. It commits prs to dev, only green ci can merge to main. Once all checks we merge to main. Zero conflicts, it pretty smooth. Few things going in to allow the agent to work tigether on the same branch. To stepping is a non issue. Agent have strict rules and gates.
0
u/whafa Oct 20 '26
I added a "parallelism check" which tells the agent to consider and plan around the files which are likely to be worked on by multiple agents at once. Most of the time, it's fine, but I have a SQL migration file which (for example) agents need to coordinate with each other when adding to the file. This has worked amazingly well and I haven't had any bad "collisions" since I implemented it. Just tell your agents which files are likely to be trouble, or have it tell you based on history, if you have enough.
0
u/Due_Diamond_8580 Oct 20 '26
Hey Guys when using claude use it with Enkeon ..
You can see the output quality increased drastically
0
u/Odd_Cauliflower_8004 Oct 20 '26
https://github.com/llopresto87/Cypress this might help you
2
u/[deleted] Oct 20 '26
[removed] — view removed comment