Skip to content

devlog/agent-loops/two-coding-agents-two-branches-one-worktree-11.md

Two Coding Agents, Two Branches, One Worktree

Give each agent its own working directory

Two agents can work at once without stepping on each other, as long as they do not share a checkout. Git worktrees give each branch a separate directory while keeping one repository and its history. Start from the project’s main checkout, with a clean working tree:

  • Run git status --short and commit or stash any changes you need to keep.
  • Run git fetch origin to bring your local view of the remote branches up to date.
  • Run git worktree add -b agent/auth ../app-auth origin/main to create a branch and checkout for the first agent.
  • Run git worktree add -b agent/tests ../app-tests origin/main to create a second branch and checkout for the other agent.

Replace origin/main with the base branch your team actually uses. The two directories, ../app-auth and ../app-tests, are siblings of the original checkout; choose paths that are easy to recognize from your terminal.

Give each agent a bounded assignment

Before launching anything, define tasks that can be reviewed and merged independently. For example, one agent can add a missing authentication check while the other writes regression tests for the existing behavior. Avoid asking both agents to edit the same files or make overlapping architectural decisions. Each agent should know its branch, directory, expected result, and verification command.

  • In terminal one, run cd ../app-auth and then start Claude Code or another coding agent.
  • Tell the first agent to work only in this checkout, implement the authentication check, run the focused tests, and summarize changed files.
  • In terminal two, run cd ../app-tests and start a second agent, such as Codex.
  • Ask the second agent to add regression tests for the agreed behavior, run them, and report any assumptions.

Read each agent’s summary, but verify the work yourself. In each terminal, run git status --short and git diff --check; then inspect the full diff with git diff. Run the project’s relevant test command in both directories. Agents are useful at producing changes, but the branch and test results are the evidence you merge.

Keep API configuration local to each checkout

When both agents need model access, configure their tools independently and keep credentials out of tracked files. Fluxo uses one key and one base URL, https://api.fluxorelay.com, across Claude, GPT, Gemini, DeepSeek, Kimi, GLM, Qwen, Grok, and more. It works with Claude Code, Codex, Gemini CLI, and any OpenAI SDK. For a concrete comparison, you might run one task with Claude Sonnet 5.5 and another with GPT-6.1 Sol, choosing based on the task and your own results.

Fluxo bills per real token, including cache reads and writes, with no monthly fee. That makes separate agent runs easier to inspect against actual usage rather than a flat subscription. If you already manage model access from your terminal, create a Fluxo account and configure the key and base URL in each agent’s supported settings.

Review and merge without mixing branches

Once both agents finish, inspect and commit each result in its own worktree. Keep commits scoped so you can cherry-pick or revert one independently if review reveals a problem.

  • In ../app-auth, run git add -A and git commit -m "Add authentication check".
  • In ../app-tests, run git add -A and git commit -m "Add authentication regression tests".
  • Push each branch with git push -u origin agent/auth and git push -u origin agent/tests.
  • Open separate pull requests, review the diffs, and run required CI before merging.

If the test branch depends on code that exists only in the authentication branch, state that dependency in its pull request and merge the implementation first. Otherwise, keep both pull requests independently reviewable. After the changes are merged and you no longer need the worktrees, remove them with git worktree remove ../app-auth and git worktree remove ../app-tests, then prune stale entries with git worktree prune.

Next in the buffer

Sign up in a minute and get credit to try every model mentioned here. Sign up →