Back to Home
AI Development

How to Run Multiple AI Coding Agents in Parallel Without Git Chaos

Claude Code's --worktree flag, tmux panes, and five overnight guardrails that stop parallel agents overwriting each other's work while you sleep.

13Labs Team5 August 20268 min read
AI coding agentsgit worktreesparallel agentsClaude Codemulti-agent

Contents

What's the short answer?

Isolate every parallel AI coding agent in its own git worktree, keep file writes single-threaded per worktree, and cap the run with a token or dollar budget before you leave it unattended overnight. Claude Code shipped `--worktree` as a first-class flag (Claude Code documentation, code.claude.com/docs/en/worktrees): by default it creates the worktree under `.claude/worktrees/<name>/`, on a branch named `worktree-<name>`, so two agents never share a working directory or a branch history. This is the real pain point for builders running multiple agents right now, not a theoretical one. One 13Labs buildDay registrant, running vibestation.vaulted.ventures, named their blocker directly: "properly deploying multi-agent dev teams and getting them to use git correctly." Another, from worthchasing.com.au, described what they actually wanted: to hand off work overnight, with agents working on other parts of the startup while they slept, instead of babysitting one session at a time.

How do you set up one git worktree per agent?

Run `claude --worktree feature-auth` to create and enter an isolated worktree in a single command, then run it again with a different name in a second terminal for your second agent. That's the Claude Code native path, and it's the fastest way to get two agents working without either one touching the other's files. For any other agent or tool (Cursor, Codex, Aider), the manual git version does the same job: `git worktree add ../project-feature-a -b feature-a`, then `cd ../project-feature-a` and start your agent as normal inside that directory. `git worktree list` shows every active worktree at a glance, and `git worktree remove ../project-feature-a` cleans one up once you've merged its branch. Add `.claude/worktrees/` to your `.gitignore` so Claude Code's own worktree directory never gets committed. One catch worth knowing before you hit it: gitignored files like `.env` don't carry into a fresh worktree automatically, because `git worktree` only checks out tracked files. A `.worktreeinclude` file, written in gitignore syntax, tells Claude Code which gitignored files to copy in on creation (Claude Code documentation).

How do you watch three or more agents running at once?

Split your terminal into panes with tmux, the standard way to monitor several agent sessions in parallel without switching windows constantly. Anthropic's own agent-teams documentation recommends tmux, or iTerm2 with the `it2` CLI, and is upfront about the trade-off: "tmux has known limitations on certain operating systems and traditionally works best on macOS" (Claude Code documentation, code.claude.com/docs/en/agent-teams). The suggested entry point is `tmux -CC` run inside iTerm2, which layers native pane management on top of tmux's session persistence. If you want the worktree, the tmux pane and the branch created together in one step rather than three, `dmux` (MIT licence, installed with `npm install -g dmux`) does exactly that per task. It supports Claude Code, Codex, OpenCode, Cline CLI and Gemini CLI (github.com/formkit/dmux), so it works whether you're standardised on one agent or running several side by side.

What are Claude Code's own multi-session primitives?

Claude Code gives you two built-in ways to run more than one agent inside a single project, subagents and agent teams, and they solve different problems. Subagents run in their own context window and report a summary back to the caller, which keeps token cost down. Adding `isolation: worktree` to a subagent's frontmatter forces it into its own worktree permanently, so it never touches the calling session's files even by accident. Agent teams are experimental, enabled with `CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1`. They run multiple full Claude Code instances that message each other via a shared task list, with file locking that stops two instances claiming the same task at once. Codex takes a different approach entirely. Its cloud tasks run in fully separate, OpenAI-managed sandboxed containers per task, so there's no local worktree to set up and no filesystem contention between parallel cloud runs. The trade-off is that you're working inside a managed container, not your own working directory, versus the local CLI model that Claude Code and Cursor both use.

How do you avoid merge conflicts between agents?

Split file and directory ownership before you start, not after two agents collide on the same file. Real-time messaging between agents reduces structural merge conflicts, but it doesn't improve whether the merged code actually passes tests, according to the controlled testing covered in our guide on multi-agent orchestration. The concrete rule: assign non-overlapping file or directory globs to each agent before any of them start working. Anthropic's own agent-teams file locking exists for exactly this reason, to stop two teammates claiming the same task simultaneously, and its documentation states the underlying failure mode plainly: "Two teammates editing the same file leads to overwrites. Break the work so each teammate owns a different set of files" (Claude Code documentation, code.claude.com/docs/en/agent-teams). Applied manually across worktrees rather than inside Claude Code's own task list, it's the same principle. Ownership boundaries prevent the conflict in the first place; coordination only cleans it up after the fact.

What are the five things that actually let you run agents overnight?

Cap the spend, choose the safer permission mode, isolate the filesystem, phase the work, and expect context to degrade as the session runs longer. These five come from the one real documented 24-hour run published so far: Eva Khmelinskaya's "Running Claude Code Autonomously Overnight - What Breaks and How to Fix It" (Medium, 18/05/2026). First, guardrail the spend by capping it at $10 per phase with `--max-budget-usd 10.00`, so a runaway loop can't burn through your budget while you're asleep. Second, be deliberate about permissions: `--dangerously-skip-permissions` is what lets a run proceed unattended, but the safer alternative is `--permission-mode auto`, which Khmelinskaya describes as the mode "where a classifier reviews each command before execution." Third, expect context window exhaustion, because "every tool output goes into the context window" and a long-running session fills it fast. Fourth, watch for instruction degradation: she found that "even essential instructions from CLAUDE.md lose effectiveness after multiple compaction rounds," so the rules you set at 11pm carry less weight by hour six. Fifth, and this is the fix for the other four, phase the work instead of running one long session. Her framing: "treat autonomous Claude Code sessions like a CI pipeline, not like a conversation." Each phase gets a fresh context budget rather than inheriting a degraded one. On isolation specifically, her recommendation matches the worktree approach above: "Consider running inside a dev container, using git worktrees for isolation, or limiting tools with --allowedTools."

Are there purpose-built tools for this?

Yes, though plain git worktrees plus tmux cover the same mechanics for free, and that's still where most teams should start. Conductor is a native macOS app built for Apple Silicon that gives each agent its own worktree with a visual diff-review layer on top, and it supports Claude Code, Codex, Cursor and OpenCode. container-use, built by Dagger and released under the Apache 2.0 licence with around 4,000 GitHub stars, is an MCP server that gives each agent a fresh Docker container on its own git branch. Install it with `brew install dagger/tap/container-use`, then wire it into Claude Code with `claude mcp add container-use -- container-use stdio`. This tool category moves fast. Check a tool's own site or changelog before adopting it, because feature sets, pricing and even continued support in this space can change within a few months of a guide like this one being written.

Frequently asked questions

Do I need a paid tool to run parallel AI coding agents, or does plain git worktree work? Plain `git worktree add` works with any coding agent, free. Claude Code adds a native `--worktree` flag that automates the same thing. Paid tools like Conductor mainly add a visual diff-review layer on top of the same worktree mechanism. Can two AI agents edit the same file safely if I ask them to communicate first? No. Real-time messaging between agents reduces structural merge conflicts but does not improve whether the merged code actually passes tests, according to controlled testing referenced in our multi-agent orchestration guide. Split file ownership before the agents start instead of coordinating after they collide. What is the safest way to let Claude Code run unattended overnight? Use `--permission-mode auto` rather than `--dangerously-skip-permissions` where possible, isolate the run in its own git worktree or container, cap spend with `--max-budget-usd`, and break the work into short phases rather than one long session, since context degrades with each compaction round. Is Codex cloud better than a local CLI agent for overnight work? Codex cloud tasks run in fully separate sandboxed containers per task with no shared filesystem, so there is no file-conflict risk between parallel cloud tasks. A local CLI agent needs a git worktree per session to get the same isolation on your own machine. Should each AI agent get its own git branch as well as its own worktree? Yes. A worktree without its own branch risks two sessions committing to the same branch history. Claude Code's default `--worktree` behaviour already creates both together, on a branch named `worktree-<name>`.

Ship with multiple agents without waking up to a mess

buildAcademy teaches builders the git and orchestration discipline that keeps parallel AI agents from overwriting each other, the same habits we run in every buildDay session.

See buildAcademy