Two Agents, One Working Tree — What Broke When I Ran Parallel Claude Code Sessions in One Git Repository
说明与用途
在同一 Git 仓库中并行运行 Claude Code 会话可能会无意中将彼此的更改合并到提交中,覆盖工作并破坏可追溯性。解决方案包括使用 git commit --only <paths>、将索引检查与提交分离,以及为每个会话分配单独的工作树。
问题
Parallel Claude Code sessions operating in the same Git working tree can unintentionally incorporate or overwrite each other’s changes, leading to incorrect commits, lost work, and traceability issues.
结果
Parallel sessions caused commits to include unintended files, overwritten work, and lost traceability. The author identified five real incidents and derived countermeasures such as using git commit --only <paths>, separating index inspection from commit, and assigning each session its own worktree.
工作流
- 1. Start Claude Code session with a clean working tree.
- 2. Stage changes using
git add -Aorgit add <file>. - 3. Commit with
git commit -m "…"(no path). - 4. (Optional) Run
git statusafter commit, which is too late.
证据
A session sees a repository with no pending changes when it starts. If a new or modified file appears during its run because a parallel session or the human has just created or changed it, that looks to the session exactly like a file its own tooling produced.
git commit without a path then commits the entire index, including everything someone else has already put there.
The rule file of this blog spells it out anyway, because then the command shows its intent.
- 记录日期: 2026-09-17T14:30:15.520Z