Dev.to AI πŸ€– Ai πŸ‘ 2 πŸ“– 8 min read

Autonomous Agents: 3 AI coders on one repo, zero conflicts, with git worktrees + events

Give one coding agent a whole feature and two things happen: it works through everything serially, and it ends up reviewing its own code. The obvious fix is a team (someone to plan, a few to build, one to review). The le

Autonomous Agents: 3 AI coders on one repo, zero conflicts, with git worktrees + events

Give one coding agent a whole feature and two things happen: it works through everything serially, and it ends up reviewing its own code. The obvious fix is a team (someone to plan, a few to build, one to review). The less obvious problem is that the moment two agents share a folder, they trample each other: files get overwritten, they fight over which branch is checked out, and their dev servers race for the same port.

This post walks through a setup that avoids all of that. We ran it end to end on November 29, 2026, taking a single request ("gift cards for checkout") from plan to merge.

TL;DR

  • Four roles: Planner, Builder (fanned out into forks), Reviewer, and you.
  • Each role is its own AgentRQ workspace with its own folder, queue and agent.
  • Named events do the handoffs: plan_ready β†’ code_changed β†’ review_passed / changes_requested. Nothing polls.
  • Each parallel builder runs in a fork that gets its own git worktree on its own branch, so three builders can hit one repo at once.
  • The loop ends with a human task: an agent never merges to main.
you ──request──▢ planner
                   β”‚ plan_ready (Γ—N, one per work item)
                   β–Ό
          builder fork 1   builder fork 2   builder fork 3   (each in its own worktree)
                   β”‚ code_changed
                   β–Ό
                reviewer ──changes_requested──▢ back to the builder that wrote it
                   β”‚ review_passed
                   β–Ό
           you: "Merge a reviewed branch"

Why split a coding agent into roles at all?

Separation of concerns works for agents for the same reason it works for people. A planner that never edits code can think about how to slice the work. A reviewer that never fixes code has no incentive to wave its own change through. And builders that each own one slice can run concurrently.

AgentRQ maps this onto three primitives:

  • A workspace is an isolated queue with its own agent, MCP token and working directory. The role goes in the workspace's mission, so whatever agent connects reads it.
  • An event is just a name, like code_changed. A trigger subscribes a workspace to it: every publish creates a new task in that workspace from a template, with the publisher's payload pasted in.
  • A fork is a copy of a workspace with its own queue and agent. On the machine it gets a git worktree on a fresh branch.

How do you stop agents from stepping on each other's files?

Git worktrees. Several checkouts of one repository, sharing history but not working files. You need three folders; the forks get theirs automatically later.

cd ~/code/shop                                    # the planner reads the main checkout
git worktree add --detach ~/code/shop-build main  # the builder's base
git worktree add --detach ~/code/shop-review main # the reviewer's checkout
git worktree list

Why --detach? Git allows a branch to be checked out in only one worktree, and main is already checked out in ~/code/shop. A detached reviewer can later git switch --detach onto any builder's branch, even while that builder still has it checked out.

Prerequisites: an AgentRQ account, a machine enrolled with agentrqd 0.9.3+ (the first version that creates fork folders), a git repo, and Claude Code or any agent started via the ACP Gateway.

What goes in each role's mission?

Create three workspaces (planner, builder, reviewer), point each one's Working Directory at its folder, and put the role in the Mission Description: what it does, what it never does, and what it fires when finished.

Planner workspace settings: working directory set to the main checkout, mission beginning "Role: Planner. You plan, you never edit code."

The missions from our run:

planner:  Role: Planner. You plan, you never edit code.
          Read the request and the code in this folder, then split the work into small
          tasks that can be built in parallel without touching the same files. For each
          one, call workspace publishEvent with name plan_ready, this task's id, and a
          payload holding the task's title, the files it may change, the branch name to
          use (feat/<slug>) and how to test it. Then complete your task.

builder:  Role: Builder. You write code for one plan item at a time.
          Work on the branch the plan names, commit small, run the tests, and never push
          to main. When the item is done, publish code_changed with the branch, the
          commit and what to look at.

reviewer: Role: Reviewer. You read and test changes, you never fix them yourself.
          Check out the branch from the payload (git switch --detach <branch>), read the
          diff against main and run the tests. Publish review_passed when it is ready to
          merge, or changes_requested with a numbered list of what to fix.

The single most important line is the planner's "without touching the same files." Separate folders prevent filesystem collisions; only good slicing prevents merge conflicts.

How are the handoffs wired?

Four events, each with payload guidelines that tell the publishing agent what to include:

Event Payload
plan_ready title, files it may change, branch (feat/...), how to test
code_changed branch, last commit SHA, what changed, what to check first
changes_requested branch, numbered list of fixes
review_passed branch, last SHA, one-line merge summary

Then one trigger per event. In the trigger form, {{EVENT_PAYLOAD}} and {{EVENT_FAQ}} get replaced with whatever the publisher sent. The "When the task is completed, fire" option makes AgentRQ append an instruction telling the agent to publish the next event, with its task id, before completing.

Trigger form on plan_ready: builder workspace, title "Build a plan item", instructions containing the event payload and FAQ placeholders

Event Workspace Who Title Then fire
plan_ready builder Agent Build a plan item code_changed
code_changed reviewer Agent Review a change none (instructions pick one of two)
changes_requested builder Agent Fix review comments code_changed
review_passed planner Human Merge a reviewed branch none

Two design choices worth calling out. The reviewer's trigger chains nothing, because a trigger can only chain one event and the reviewer has two possible outcomes; its instructions name both and it publishes the right one itself. And the final trigger is assigned to Human, so the pipeline terminates in your inbox, not in a merge.

What happens when you ask for a feature?

We created a planner task: "Plan gift cards for checkout. Customers should be able to buy a gift card and redeem it at checkout." The planner read the code and published plan_ready three times. Three builder tasks appeared (model, redeem, field). We renamed them so each said which slice it was, which also gives the forks readable names, since spin-up names a fork after its task.

How do the builders actually run in parallel?

Three tasks in one builder workspace would still be processed one by one. So each task gets its own fork: hover the task, click the bolt (Spin up in a fork), pick the machine and agent, and AgentRQ forks the workspace, moves the task in, and starts an agent, in one step. (You can also right-click the workspace β†’ Fork workspace, then Move Task.)

Spin up popover forking builder as build-gift-card-redeem on dev-laptop with Claude Code selected

On first start, agentrqd creates the fork's folder under ~/.agentrq/forks/<fork-id>:

  • Because the builder's folder is a git repo, the fork gets a worktree on a new branch agentrq/fork-<fork-id>, at the builder's HEAD. The agent then creates the plan's feat/... branch inside it. (A non-git folder gets a plain copy.)
  • The fork's terminal shows the exact git worktree add it ran.
  • The untracked .mcp.json and .claude folder are copied in with the parent's AgentRQ entry removed, so the fork connects as itself. If .mcp.json is committed, the fork's copy is marked skip-worktree so its token never appears as a diff.

Forks keep their own name, queue, agent and folder, but share the builder's memory, skills and settings. When one builder saves a lesson like "run make generate before the tests", the other two pick it up on their next task.

How does review work across worktrees?

A finished builder publishes code_changed, for example:

Branch: feat/gift-card-ui
Commit: a3f91c2
What changed: a gift card field on the checkout page, with code validation and an error state.
Check first: the error message when a code is expired.

The reviewer runs git switch --detach feat/gift-card-ui in ~/code/shop-review. Since all worktrees share one repository, the fork's commit is already visible. No push, no fetch.

In our run the UI change passed, but the redeem change had a bug: a gift card balance bigger than the order total produced a negative total. The reviewer published changes_requested. That fix task lands in builder (the workspace the trigger names), so you Move Task it into the fork that owns the branch; the fork fixes it in the same worktree and code_changed loops it back to review.

Move Task dialog listing the builder's three forks, with build-gift-card-redeem selected

How does it end?

review_passed gives you a Merge a reviewed branch task. Merge however you normally would:

cd ~/code/shop
git merge --no-ff feat/gift-card-ui     # or open a pull request from it

Then right-click the fork β†’ Merge into builder. Optionally tick "Delete the fork's folder" to remove the worktree; the branch survives, but uncommitted changes don't. Merging stops the agent and moves the fork's tasks, threads included, back to builder. A merge is refused while any fork task is unfinished, and forks can't be deleted or archived, only merged.

Merge into builder dialog showing the fork's folder path and the delete-folder checkbox

What are the gotchas?

  • Same lines, different builders: only the planner's slicing prevents this.
  • Ports: give each builder a port in its plan item, or tell builders to grab any free one.
  • Missing .env / node_modules: a worktree has only tracked files plus .mcp.json and .claude. Copy env files and install dependencies per fork.
  • Uncommitted work in builder isn't in the fork; forks start from the last commit.
  • Triggers vs. workflows: you can model the same loop as a workflow graph starting from plan_ready, but pick one. A trigger and a workflow step on the same event both create a task, so you'd get duplicates.
  • Headless: the supervisor workspace exposes workspace.fork, workspace.mergeFork and events.createTrigger; workers publish with workspace publishEvent. See MCP integration.

FAQ

Is a fork required for every builder task? No. Without forks, the builder just processes tasks serially in ~/code/shop-build. Fork when you want concurrency.

Can forks run different agents? Yes: Claude Code in one, Codex or Gemini CLI via ACP in another. Choose under What to run when spinning up.

Where do fork folders live? ~/.agentrq/forks/<fork-id> on the machine, on branch agentrq/fork-<fork-id>. agentrqd serve --forks-dir relocates them.

Can you fork a fork? No, forks are one level deep. The supervisor and archived workspaces can't be forked either.

YOLO mode for builders? Only if you trust what they execute. Otherwise each permission request waits for you, which is the point. YOLO mode is a per-trigger switch.

How are you splitting work between multiple coding agents today: one agent per branch, per worktree, or something else entirely?

Originally published on agentrq.com. The full tutorial has every screenshot and step.

πŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes β€” full credit and traffic to the original publisher.