How to run AI coding agents in parallel without chaos
Worktrees stop agents from overwriting files, not from colliding on work. A five-rule method for running 2 to 5 Claude Code or Codex sessions at once.

Here is a Tuesday that will look familiar if you have tried this.
You open three terminals. Session one is adding an export endpoint. Session two is fixing a flaky login test. Session three is "cleaning up the auth module". Forty minutes later session two has fixed the flaky test by raising a timeout, session three has fixed the same test by mocking the clock, and both changed auth/session.ts. Session one restarted the dev server on port 5173 to check its endpoint, which killed the server session two was running Playwright against. All three tell you they're done. You now have three branches, one of them broken, and no idea which change to keep.
Nothing in that story is a model failure. Each agent did a reasonable job with what it could see. The failure is coordination, and coordination is a solved problem in human teams. We just forget to apply it to agents.
Why do parallel AI agents step on each other?
There are four kinds of collision, and only the first one is about files.
- Files. Two sessions edit the same working directory. One reads a file the other has half rewritten, or commits on top of it.
- Work. Two sessions pick up the same problem from different angles because nobody wrote down who owns it. That's the flaky test above.
- Shared resources. Ports, a local Postgres, a seeded test database, a logged-in browser profile, a staging deploy, an API with a rate limit. Separate directories don't separate any of those.
- Your attention. Every session ends with "please review". Three sessions finishing in the same ten minutes is a queue, and you are the only server.

Are git worktrees enough?
They are necessary, and they solve exactly one of the four. Anthropic's own docs put it plainly: worktrees "isolate file edits" (Claude Code docs). That is precisely what they do.
In Claude Code a worktree is one flag:
claude --worktree export-endpoint # terminal 1
claude --worktree flaky-login-test # terminal 2
Each session gets its own directory under .claude/worktrees/ and its own branch. Add .claude/worktrees/ to .gitignore, and list the gitignored files every checkout needs (.env, local config) in a .worktreeinclude file so new worktrees can actually run. Codex, Cursor and the rest can use plain git worktree add ../app-export -b export, which does the same thing.
What worktrees don't give you:
- a way to know that
flaky-login-testandauth-cleanupare the same problem, - a separate port, database or browser per session,
- any idea which of the three finished branches you should look at first.
People who run agents in parallel every day say the same thing in different words. In an Ask HN thread on whether parallel sessions are even workable, the complaints are about context switching, ports and "hanging worktrees", not about git.
The method: one task, one owner, one worktree, one lock
These five rules work with any agent and any tracker, including a Markdown file. They're the part worth copying even if you never use our product.
1. Every session has a name
"Claude" is not a name when three of them are running. Give each session a handle that says what it is for: claude-api, claude-ui, codex-tests. Use it in the branch name, the worktree name, the commit trailer and wherever the session reports progress. When something breaks at 6 pm you want git log and the board to tell you which session did it, not just "an AI".
2. Claim before code
A session may not start writing code until it has claimed a task on a list that every session reads. Claiming means: the task has an owner, a status of "in progress", and a one-line plan. If the task is already claimed, the session takes the next one.
This single rule would have prevented the flaky-test story. Session three would have seen RAP-31 flaky login test · in progress · @claude-tests and left auth/session.ts alone, or asked.
3. Split by ownership, not by topic
"Backend" and "frontend" are topics. Ownership is "this session owns src/billing/** and tests/billing/** for the next hour". Tasks for parallel sessions should touch different files and be finishable in one session, with checkable acceptance criteria. If two tasks must touch the same file, they're sequential: put the second in the first owner's queue instead of giving it to a new session. Anthropic gives the same advice for its experimental agent teams: break the work so each teammate owns a different set of files (agent teams docs).
4. Lock what worktrees still share
Make a list of everything the sessions share and give each item a capacity:
| Resource | Capacity | Why |
|---|---|---|
dev-server on :5173 | 1 | Hot reload and E2E tests fight over it |
browser (logged-in profile) | 2 | More than two Playwright runs and the laptop fans take off |
test-db reset | 1 | A reset in the middle of someone else's suite looks like a flaky test |
staging-deploy | 1 | Two deploys race and the loser wins |
A session acquires the lock before it uses the resource, releases it right after, and the lock expires on its own if the session dies. If the lock is busy, the session does something else instead of "just quickly" using it anyway. A lock with no expiry will eventually be held by a session that crashed an hour ago, so put a timeout on every one.
5. Make pauses visible and keep one integrator
A session waiting on CI, on another session or on you should say so on the task, not sit at "in progress". And exactly one party, you or a designated reviewer session, decides what gets merged and in which order. Letting three agents independently resolve the same merge conflict is how you get the timeout fix and the clock mock in the same commit.

Can I do this with a Markdown file?
For two sessions on one machine, yes. A TASKS.md with an owner column, a LOCKS.md with "dev-server: claude-api until 14:20", and a line in CLAUDE.md or AGENTS.md that says "read TASKS.md before starting, claim a task by writing your handle next to it" gets you most of rules 1 to 3.
It starts breaking in predictable places. Sessions don't re-read the file mid-task, so a claim made at 10:05 is invisible to a session that loaded the file at 10:00. Two sessions write the file at the same moment and one claim disappears. Locks never expire. And nothing tells you that a session is waiting, so you find out when you happen to look. If you're past two sessions, or the sessions run on different machines, you want the list to be a service that every session talks to, not a file each of them caches.
How does Rappy run parallel agent sessions?
The five rules map to a handful of tool calls. These are real calls and real output shapes, trimmed.
Names. Every tool takes as=<handle>, or you connect a session to https://rappy.space/mcp?as=claude-ui. Handles that start with claude- are created on first use, so a new session needs no setup. The lead session can hand each new one a ready-to-paste brief with agent_brief: its identity, role, queue and who it hands work to.
Claims and queues. A session starts with whats_next, which shows its own ordered queue and what changed since last time. Taking a task is one call:
update_task key=APP-31 status=in_progress assignees=[@claude-tests] progress=10 remaining="45m" as=claude-tests
→ OK: APP-31 [in_progress] Fix flaky login test · @claude-tests · AC 0/3 · 10% ~45m left
The board now shows @claude-tests on the card, with a progress bar. A second session that tries to work the same area sees the owner before it writes a line. Ordered work goes in a queue (queue tasks=[APP-32, APP-35]), so finishing one task shows the next instead of a session improvising.
Locks. Shared resources are first-class:
resource action=define name=dev-server capacity=1
resource action=acquire name=dev-server task=APP-30 ttl_minutes=30 as=claude-api
→ Acquired: dev-server until 14:20 UTC. Release it as soon as you're done.
resource action=acquire name=dev-server task=APP-31 as=claude-tests
→ BUSY: dev-server is held by @claude-api (APP-30) 4 min. Do something else and try again later (or update_task waiting="dev-server").
Holds lapse on their own and are released when the task leaves "in progress", so a crashed session can't keep the server forever. The board shows who holds what.
Visible pauses. update_task waiting="dev-server" waiting_on=@claude-api puts a ⏸ on the card instead of a silent "in progress". You can see at a glance which sessions are blocked and on whom.
One integrator. configure_team sets roles once per product: executors, a QA or lead session that reviews, and which stage routes to whom. Executors finish with submit, which sends work to the reviewer, not to you. The reviewer checks it and forwards with send_to_approval only what you asked to see in your approval guide. We cover that part in human-in-the-loop approvals that don't slow you down.
A minimal block for CLAUDE.md or AGENTS.md so every session follows the rules without being told:
## Parallel sessions
- Work in your own worktree. Use your handle (as=claude-<area>) on every Rappy call.
- Claim before code: whats_next, then update_task status=in_progress on ONE task.
- Shared resources (dev-server, test-db, browser, staging-deploy): resource acquire
before use, release right after. BUSY means do something else.
- Waiting on something? update_task waiting="…" waiting_on=@who.
- Finish with submit. Never merge another session's branch.
How many agents should I run at once?
As many as you can review, which is fewer than you think. Anthropic suggests starting with three to five teammates for agent teams and notes that token costs scale with every extra session (source). Our own rule of thumb: start with two, add a third when you notice you're waiting for agents rather than the other way round. If finished work sits unreviewed for more than an hour, you have one session too many.
Review capacity grows when you stop reviewing everything. A QA session that checks tests and screenshots before you look, and acceptance criteria with real evidence, mean you read a short report instead of a diff. See definition of done for AI agents for how to make "done" checkable.

FAQ
Can Claude Code and Codex work on the same repo at the same time?
Yes, if each has its own worktree and branch and both read the same task list. Mixing vendors is actually useful for review: a second model tends to catch different mistakes. Give each its own handle (claude-api, codex-tests) so the history stays readable.
Do I need Claude Code agent teams for this?
No. Agent teams are an experimental Claude Code feature where one lead session spawns teammates that share a task list. They're useful for research and review inside one session, but the task list belongs to that session and teammates don't survive a resume. The method here works across vendors, machines and days.
How do I stop two agents from using the same port?
Either give each worktree its own port through its .env (copied by .worktreeinclude and then edited), or treat the dev server as a shared resource with capacity 1 and a lock with an expiry. Per-worktree ports are better for dev servers. Locks are better for things you can't duplicate, like a staging deploy.
Does running agents in parallel cost more?
Yes, roughly linearly: three sessions use about three times the tokens of one. The win is wall-clock time, not cost. Compact tool outputs help a bit; claiming tasks up front helps more, because the most expensive tokens are the ones spent on work that gets thrown away.
What should I read next?
Parallel sessions make two other problems louder: agents forgetting context between sessions (give Claude Code memory between sessions) and agents blocked on a question while you're away (how an AI agent should ask you a question).

