Claude Code in 4 Git Worktrees: 23 Tasks, 9 Collisions, 1.5x Speed
说明与用途
在单独的 git worktree 中运行多个 Claude Code 代理将已发布任务数量提升了 1.5 倍,但导致分支冲突、端口和数据库冲突,并增加了审查时间。通过实施端口隔离、单一迁移分支、文件所有权约束并将代理数量限制为三,提升了效率并减少了冲突。
问题
Running multiple Claude Code agents in parallel on a shared monorepo caused port conflicts, database race conditions, merge collisions, and increased human review time, limiting throughput.
结果
Parallel Claude Code agents increased shipped tasks by 1.5x but introduced 9 branch collisions and 6.5 hours of review. After applying isolation strategies and limiting to three agents, throughput improved further with minimal collisions.
工作流
- Create four git worktrees, each on a feature branch
- Run a Claude Code session in each worktree
- Assign tasks via prompts with file‑ownership constraints
- Agents rebase onto origin/main and run tests before reporting completion
- Merge agent branches into main manually, resolving conflicts per guidelines
- Apply conventions file for cache keys, route registration, and env vars
- Limit to three agents to stay within usage and review capacity
证据
Running Claude Code in 4 git worktrees for 5 working days, I queued 23 tasks. 17 shipped, 4 needed heavy rework, 2 got thrown away.
9 of the 23 branches collided with another agent's work: 5 textual merge conflicts, 4 clean merges that broke main or staging anyway.
My throughput went from 11 shipped tasks the week before (one agent, sequential) to 17. That's 1.5x, not 4x.
I spent 6.5 hours reviewing diffs, more than any single agent spent working.
- 记录日期: 2026-09-18T16:02:48.199Z