Running two coding agents in one repository
Run a second Claude Code or Codex session on the same checkout and the two overwrite each other. Git worktrees let any Mira session start in its own.


What actually goes wrong when two agents share a working tree
Running one coding agent in a repository is a solved problem, but running two at once is not. Both agents operate on the same working tree without knowing the other exists, overwriting and mixing each other's changes. Nothing crashes, which makes the failure quieter and worse: you end up with a diff that neither agent intended and no one can explain.
- Agent A is editing files
Both agents operate in the same shared working tree
- Agent B checks out a branch
Agent B may also stage a file that Agent A just rewrote
- Tests run on half-written changes
Git raises no error while the two changes mix
- You get a diff neither agent intended
- Clone the repo for each agent
- Duplicates history and isolates branches
- Run the agents one after another
- Gives up the point of using two agents
- Tell each: “Only these files”
- No enforcement; agents can still cross
The three usual workarounds for running two agents in one repository—separate clones, taking turns, or verbal file rules—are all worse than they look.
Linked worktrees: give one repository several independent checkouts
Git has had the answer since version 2.5. Running git worktree add creates another working directory backed by the same object database and refs—a second checkout, not a second repository. Each worktree sits on its own branch with its own index and HEAD, so two agents working in separate worktrees cannot see each other's uncommitted changes, stage each other's files, or switch each other's branch.
- ../feature-a
- Worktree checked out on branch feature-a
- Has its own staging index and HEAD
- Agent A edits files here in isolation
- ../feature-b
- Worktree checked out on branch feature-b
- Has its own staging index and HEAD
- Agent B edits files here in isolation
# one repository, two checkouts, two branches
git worktree add ../feature-a -b feature-a
git worktree add ../feature-b -b feature-b
# each has its own HEAD and index; the objects are shared
git worktree listBuilt-in worktrees in Claude Code and Codex
Both Claude Code and Codex now ship worktree support so you don't have to run git worktree add by hand every time.
- Claude Code (
--worktree/-w) - Run
claude --worktree feature-auth(or omit the name for a generated one) to create a worktree under.claude/worktrees/<name>/on branchworktree-<name>, or ask Claude mid-session to “work in a worktree”. Add.claude/worktrees/to.gitignore. On exit, a clean unnamed worktree is removed automatically; one with edits or commits prompts you to keep or remove it, and you can return withclaude --worktree <name> --resume <session-id>. - Codex (Worktree mode and Hand off)
- In the ChatGPT desktop app, select **Worktree** under the composer, choose the starting branch (or your current branch with unstaged edits), and optionally pick a local environment to run setup scripts. Codex starts on a detached HEAD by default. When you're ready, either click **Create branch here** to commit and push from the worktree, or click **Hand off** to move both chat and changes into your Local checkout.
# Start two isolated Claude Code sessions in separate terminals
claude --worktree feature-auth
claude --worktree fix-billing
# Return to a kept worktree later
claude --worktree feature-auth --resume <session-id>
# Remove a worktree left behind by a non-interactive -p run
git worktree unlock .claude/worktrees/<name>
git worktree remove .claude/worktrees/<name>A new worktree has no .env and no node_modules
A worktree is a fresh checkout, so the files git ignores aren't there: no .env, no node_modules, no build output. To carry ignored files over, list them in a .worktreeinclude file at the repository root, in .gitignore syntax. Claude Code and Codex both read it, and only copy files that git ignores.
# .worktreeinclude
.env
.env.local
config/secrets.json- Claude Code
- Copies the files in
.worktreeincludeinto every worktree it creates. Dependencies are up to you: install them in the worktree, or ask Claude to. - Codex
- Copies the files in
.worktreeincludeinto the worktrees it manages. In the ChatGPT desktop app, a local environment's setup script runs when Codex creates a new worktree. - Mira
- Copies the files in
.worktreeinclude, or the ignored.envfiles at the root when there is none, and runs one setup script: one you write in Mira, or the one already set up in Conductor, Cursor, Orca or T3 Code. The first time, it lists every file and command and asks.
The setup script runs in the background, so the agent can start its first turn while dependencies install.
Why Mira builds linked worktrees into sessions
git worktree add manually for one branch at a timeParallel sessions in Mira mean several coding agents working at the same time, each on its own task. Mira does not act as an orchestrator that splits one task among worker agents. Nothing plans across panes or merges their code for you—you review the diffs side by side and merge them yourself.
Article · Claude Code agent teams, and teams that mix agents and people → Claude Code's agent teams, and letting sessions on different agents message each other.
Conductor alternative: move to Mira → Used Conductor for parallel agents? How Mira compares, and moving over in one click.
Article · A Claude Squad alternative with a desktop app, phone apps and shared sessions → Running agents with Claude Squad in tmux? A desktop alternative.
Article · A Vibe Kanban alternative with a shared board → Used Vibe Kanban's board of agents in worktrees? Where to go now that it has shut down.
Article · Mira vs Orca: How to choose → Orca also gives every task its own worktree; how it compares with Mira.
Article · Claude Code /rewind and /undo: checkpoints, what isn't tracked, and branching sessions → Undoing edits with Claude Code `/rewind` and `/undo`, plus visual rewind and branching in Mira.
Article · Setting up Claude Code and Codex in a monorepo or large codebase → Configuring Claude Code and Codex for a monorepo: nested instructions, Read deny rules, and sparse worktrees.
Questions
- Why does Codex start a worktree in detached HEAD?
- Git only allows a branch to be checked out in one worktree at a time. Starting detached lets Codex base multiple worktrees on the same branch without colliding with your main checkout; click Create branch here when you want to commit and push.
- Do Claude Code worktrees clean themselves up?
- For interactive sessions, an unnamed worktree with no changes is removed on exit, while one with changes or commits asks whether to keep or remove it. Non-interactive
-pruns don't prompt and leave their worktrees locked until you unlock and remove them. - Can I run Claude Code and Codex in worktrees side by side?
- Yes. Because git worktrees are standard Git checkouts, you can point Claude Code at one and Codex at another — or start both as separate sessions in Mira, each with its own worktree, terminal, and diff pane.
Sources
Checked on November 29, 2026 against Anthropic's worktrees guide (code.claude.com/docs/en/worktrees) and OpenAI's Codex worktrees and local environments docs (learn.chatgpt.com/docs/environments/git-worktrees and local-environment). Check those pages for the latest flags and options.
Keep reading

Fixing OpenAI and Codex 403 “unsupported_country_region_territory”
Why OpenAI and Codex return 403 unsupported_country_region_territory, how to fix false positives on VPNs or cloud IPs, and compliant alternatives.

Running Claude Code and Codex on Amazon Bedrock, Vertex AI, and Microsoft Foundry
Connect Claude Code and Codex to Amazon Bedrock, Vertex AI, and Microsoft Foundry: env vars, config.toml, auth, model pinning, and limits.

Using Claude Code with Chrome and Codex Browser: live debugging, Playwright, and previews
How to connect Claude Code to Chrome (extension, console logs, login limits) and use Codex Browser or Playwright, plus live dev-server previews in Mira.