Guide
Git worktrees for AI coding agents
Git worktrees let one repository have several working directories at once. For AI coding agents, that means each agent can work in a real branch with its own files while you keep every experiment, fix, and refactor separate.
Why worktrees matter for AI agents
Running one coding agent in a terminal is straightforward. Running several agents on the same checkout is where things get fragile: one task edits files another task depends on, branch switching interrupts active work, and half-finished changes pile up in a single working tree.
A git worktree avoids that shared-state problem. Each agent gets a separate directory and branch, so Claude Code, Codex CLI, Gemini CLI, OpenCode, or a custom CLI agent can run in parallel without overwriting another agent's files.
The manual workflow
A basic worktree workflow looks like this:
- Create a new branch and worktree for the task.
- Start the coding agent from that worktree directory.
- Review the diff on that branch when the agent finishes.
- Merge, push, open a pull request, or delete the worktree.
The commands are simple, but the operational overhead grows quickly when you have many agents running at once. You need to remember which directory maps to which task, watch terminal status, compare branches, and clean up old worktrees.
What Baton adds
Baton uses git worktrees as the isolation layer, then adds a desktop workspace around them. You can create a workspace, launch an agent, watch status, inspect changed files, review diffs, and open the branch in your editor without hand-managing directories.
Best fit
Baton is useful when you want to run several agent tasks at once: one branch for a bug fix, one for a refactor, one for test cleanup, and another for exploration. If you only run one short agent session at a time, a normal terminal is often enough.
Recommended setup
- Keep the main checkout clean and use worktrees for agent tasks.
- Give each worktree a branch name tied to the prompt or issue.
- Review every diff before merging or opening a pull request.
- Archive or delete worktrees once the branch is merged or abandoned.
Supported agents
Baton has first-class support for Claude Code, Codex CLI, Gemini CLI, and OpenCode. It also works with any custom CLI agent that runs in a terminal.
To try this workflow, download Baton or compare the supported CLI coding agents.