Two agents at once: one git worktree and one branch each

Introduction

This article is part of a larger manual, OpenCode in Docker on Ubuntu 24.04.

The manual shows how to run OpenCode with the --auto option inside a Docker container.

With --auto the agent does not ask you before each command, so the container limits what it can reach: the agent works only in one git worktree, a separate copy of the project.

In step 2 (a worktree for the agent) of the manual, the agent gets its own worktree on its own branch.

This article runs two agents at the same time in this way.

It also shows what goes wrong when both agents work on main.

Two agents at once

Say one container runs OpenCode and another runs Claude Code.

Each agent gets its own worktree and branch:

git worktree add ../site-opencode -b agent/opencode-about

git worktree add ../site-claude -b agent/claude-index

You review and commit each worktree, then merge the branches one after the other from your folder.

Tested on a small repo in which OpenCode changed about.php and Claude Code changed index.php:

git merge agent/opencode-about

Updating e63b53d..952eff2 Fast-forward container/src/about.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

git merge --no-edit agent/claude-index

Merge made by the 'ort' strategy. container/src/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)

git log --graph --format=%s

* Merge branch 'agent/claude-index' |\ | * Renames the home page * | Renames the About page |/ * Two pages

When both change the same line

In a second test both agents changed the title of the home page, on the branches agent/opencode-title and agent/claude-title.

The first merge went through, and the second one stopped and kept both versions in the file:

git merge --no-edit agent/claude-title

Auto-merging container/src/index.php CONFLICT (content): Merge conflict in container/src/index.php Automatic merge failed; fix conflicts and then commit the result.

cat container/src/index.php

<?php <<<<<<< HEAD $title = "Start"; ======= $title = "Main page"; >>>>>>> agent/claude-title echo "<h1>$title</h1>";

Keep one line, then git add and git commit.

Or run git merge --abort and give the task back to one of the agents on top of the new main.

And if both work on main?

git worktree add --force puts two worktrees on main anyway.

Tested: OpenCode's worktree commits a new About title to main.

In Claude Code's worktree, where nothing was done, that commit shows up as a staged change that undoes it:

git -C ../site-claude status --short

M container/src/about.php

Claude Code's next commit -a takes it along.

Its commit "Renames the home page" also puts the old About title back, without a conflict or a warning:

git -C ../site-claude show --stat --format=%s HEAD

Renames the home page container/src/about.php | 2 +- container/src/index.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)

Your own folder is on main too and gets the same. What one branch per agent gives:

Article author: Klavdiya Kondakova