r/OnlyAICoding • • 2h ago

Something I Made With AI Worktrees stop parallel AI agents from overwriting each other's files. They don't stop two green PRs from breaking main

Post image

I run 5 to 10 coding chats on one repo at the same time. Most tools now have a worktree option, and it solves the first problem: two chats editing the same files.

**What kept breaking after that**

- **Green against an old base.** Two PRs, each green, merged back to back and broke main. Each had only been tested against the code from before the other.

- **Every suite at once.** All the agents started their full test suites at the same moment and the machine choked.

- **Same-model review.** The model that wrote the code reviewed it and missed the same things twice.

- **Leftovers.** Merged worktrees and branches piled up.

**What the skill does**

- a worktree per chat, outside the main checkout

- a machine-wide queue: N test suites at a time

- PR through `gh`; critical paths reviewed by a different model (Codex, Gemini or Claude), and the reviewer can fix, not only approve

- one merge at a time per repo, only when the branch already contains the latest main, with the tests re-run on that base

- deploy health check, then cleanup

**A real run** (two chats, one repo, same moment)

```

chat B | [deliver] PR 1

chat A | [deliver] PR 2

chat A | [deliver] waiting for the merge lock...

chat B | [deliver] merged PR 1

chat A | [deliver] base or code moved since the tests: running the suite again

chat A | [deliver] merged PR 2

exit codes: A=0, B=0

main contains both branch heads: true

worktree A exists: false, worktree B exists: false

PROOF PASSED

```

**How it compares**

- superpowers `using-git-worktrees` gives one agent an isolated worktree and stops there. This starts at the worktree and goes on to tests, PR, review, merge, deploy and cleanup, for several chats at once.

- Claude Code `/ship` opens a PR and follows it, one change at a time, and doesn't merge. This merges, behind a gate, and also works with Codex and Gemini CLI.

**Install**

```

npx skills add mestrecs/skills

```

On first run it detects your setup and asks a few questions: who reviews, where it deploys, how many chats at once. Windows, macOS and Linux; Claude Code, Codex and Gemini CLI.

Repo: https://github.com/mestrecs/skills

If you run several agents in parallel, what still breaks for you?

1 Upvotes

0 comments sorted by