Guide

How to run multiple AI coding agents with git worktrees

The best way to run multiple AI coding agents in one repository is to avoid making them share one checkout. Git worktrees give each agent a real directory, a real branch, and a reviewable diff.

The core rule: one task, one branch, one directory

AI coding agents are much easier to manage when every task has its own branch and working tree. The agent can edit files freely inside that directory while other agents work elsewhere.

This works for Claude Code, Codex CLI, OpenCode, Gemini CLI, and custom terminal-based agents. The agent does not need to know much about worktrees. It just runs inside a normal directory.

What goes wrong without worktrees

A practical parallel-agent workflow

  1. Start from a clean main checkout.
  2. Create one worktree and branch per agent task.
  3. Launch the chosen agent inside that worktree.
  4. Monitor each session until it finishes or needs input.
  5. Review each branch diff separately.
  6. Merge, push, open a pull request, or delete the branch.

How Baton fits

Baton wraps this workflow in a desktop app. It creates workspaces backed by git worktrees, launches your agent CLI, tracks status, opens files and diffs, and keeps every task visible from one sidebar.

Which tasks should run in parallel?

Good candidates are independent: bug fixes, test improvements, documentation updates, exploratory refactors, UI polish, or competing implementation attempts. Avoid parallel sessions when each task depends on another task's result.

Agent-specific workflows

For more focused examples, see OpenCode multiple sessions, Codex CLI multiple sessions, Claude Code, and Gemini CLI.

To try this workflow, download Baton or compare all supported CLI coding agents.