Skip to content
GUIDES#Claude Code#Codex#Git Worktrees

How to Run Claude Code and Codex in Parallel on the Same Project with Git Worktrees

Two AI agents, one repo, no stepping on each other's toes. Here is how to set up an environment where Claude Code and Codex work like two real developers, each in their own directory.

Yaakov Tzedek
Yaakov Tzedek · AI expert·11 min read
THE BOTTOM LINE
  • A practical guide to running Claude Code and Codex simultaneously on the same repo without conflicts, using Git Worktrees, separate branches, and commit/pull sync.

Yes, you can run Claude Code and Codex in parallel on the same repo and give each one a separate task without them overwriting each other's work. The right way to do it is Git Worktrees: a separate working directory and branch for each agent, both sharing the same Git history. But there is no real-time sync between them: handoffs happen only through commit, merge, and pull, not on their own.

In short

QuestionShort answer
Can they work in parallel on the same repo?Yes, with a Git Worktree per agent: separate directory and branch, shared history.
Do they see each other's changes in real time?No. Only after a commit followed by an explicit merge, rebase, or pull.
Are worktrees required?Not strictly, but they are the easiest and recommended approach. A separate clone also works, just heavier.
How do you prevent file conflicts?Each agent writes only inside its own worktree. The main checkout stays off-limits.
How does one agent continue from where the other stopped?Merge the branch into main, then fetch and merge or rebase in the other agent's worktree.

What Git Worktree actually is

A worktree is an additional working directory of the same repo, with its own files and branch, but sharing the same history and the same object store. Instead of cloning the entire repo again every time you want to work on two things in parallel, you open a second directory that points to the same .git, without duplicating disk space and without losing history.

The practical result: one agent can build a feature in one directory while a second agent fixes a bug in another, and both are working on the same repo without seeing each other's open files.

Claude Code and Codex: built-in worktree support

Neither tool requires you to run git worktree manually anymore. Each has a built-in way to create a worktree directly from within the tool.

AspectClaude CodeCodex
How to openclaude --worktree <name> in the terminalSelect "Worktree" in the new-chat composer
Starting branchThe repo's default branch, unless configured otherwiseChoose an existing branch, including the current branch with uncommitted changes
Where it is saved.claude/worktrees/<name>/ in the repo root$CODEX_HOME/worktrees
Branch stateA new branch named worktree-<name>Detached HEAD, not a regular branch
CleanupPeriodic sweep, with a prompt before deletion if there is work insideKeeps roughly 15 worktrees by default and deletes the oldest ones automatically

One important limitation that comes from Git itself and applies to both tools: you cannot check out the same branch in two worktrees at the same time. This is not a Claude Code or Codex restriction, it is core Git behavior, and it is exactly what prevents two agents from "fighting" over the same branch without anyone asking for that (Anthropic, Worktrees documentation) (OpenAI, Worktrees in Codex documentation) (both checked on 2026-09-28).

Do they see in real time what the other changed?

The short answer is no, and it also depends on where each one is running. There are two completely different scenarios here:

  1. Both agents run locally, as worktrees of the same repo on the same machine. In this case they share the same .git, so the moment one agent runs git commit, that commit is already in the shared history and can be seen with git log from any other worktree of the same repo, without a push or a fetch. But that does not mean the files in the second agent's working directory have updated: they will only update after an explicit merge or rebase.
  2. Codex runs in a separate cloud environment (as in Codex Cloud tasks). In this case there is no local .git sharing at all, and the only sync path goes through a push to the remote (such as GitHub) and a pull from it.

In both scenarios the conclusion is the same: none of these tools "listens" to the other by default. If you want one agent to know that something happened on the other side, you have to tell it, either by running git fetch yourself or through a coordination file. Claude Code also has an internal mechanism called cross-session messaging for passing findings between Claude Code sessions, but it does not bridge Claude Code and Codex, because those are two products from two different vendors.

How to sync between them: through commit and pull, not through magic

This is the practical process for setting up two working environments on the same repo, one per agent:

  1. Open a worktree for Claude Code from the main repo root: claude --worktree feature-a. Claude Code creates a directory under .claude/worktrees/feature-a and a new branch named worktree-feature-a, and you can give it the first task.
  2. Open a worktree for Codex in the terminal or a separate window: git worktree add -b codex-task-b ../myapp-codex-b main, then cd ../myapp-codex-b and run Codex there. You can also do this through the Codex composer by selecting "Worktree", if you are working through the app.
  3. Ask each agent to do its work and commit on its own inside its worktree: git add -A && git commit -m "...". This is compatible with Claude Code's sandbox protections, because git commit writes to the shared .git and not to the main checkout.
  4. When one agent finishes a task, go back to the main checkout and run git merge worktree-feature-a (or open a pull request if you are working through a shared remote like GitHub).
  5. Before the second agent continues, run git fetch inside its worktree and then git merge main or git rebase main, so it actually sees what was merged.
  6. When work is done, remove the old worktree: git worktree remove ../myapp-codex-b, so stale open directories do not pile up.

How to have one agent continue from where the other left off

There is no "continue automatically" button. What actually works in practice: before handing a task from one agent to another, make sure the merged branch is at the base of the new worktree. When you set up a new worktree with a base branch of head instead of the default branch, it will start from the already-existing unmerged work rather than from the old main branch. This is useful when you want the second agent to continue directly on top of what the first one already wrote, without waiting for a full merge into main.

Using one agent to review and fix the other's work

This is exactly the situation where the "you cannot check out the same branch twice" rule can get in the way, and there is a simple workaround: open a third worktree in detached HEAD mode, pointed directly at the commit you want to inspect, not at the branch name itself. That way you can give the second agent access to exactly that point in history without conflicting with the branch the first agent still has open. This is precisely the approach Codex itself uses by default when you open a new worktree through the app.

In practice, you give it something like "review the changes in this diff against main, run the tests, and fix anything that broke," and you get a second agent doing a real code review, fixes included, on work that another agent wrote, without touching the original branch.

AGENTS.md: the shared briefing file that prevents some of the conflicts

Since September 21, 2026, if there is no CLAUDE.md file in the directory, Claude Code will check for and read an AGENTS.md file instead, a standard that Codex itself helped popularize. The practical implication: you can write one briefing document, "who works on what," "which files not to touch right now," "which test commands to run before committing," and place it in the repo root so both agents read it, each at the start of its own session, without writing two separate instruction documents (announcement coverage, InfoWorld) (checked on 2026-09-28).

This does not replace Git-based sync, but it greatly reduces the chance that both agents start working on the same file at the same time without knowing it, because both read the same "who does what" list before they touch any code.

Common mistakes that lead to conflicts

  • Giving both agents the same main checkout to work in, with no worktree at all. This is the fastest path to a file getting overwritten mid-write.
  • Assuming a merge will happen on its own. It will not. Someone, you or the agent, has to actually run merge or rebase.
  • Forgetting untracked files like .env. A new worktree is a clean checkout, and a file like .env will not appear in it automatically unless a .worktreeinclude has been configured in the repo root.
  • Leaving old worktrees open. They take up space and create confusion when you try to figure out which agent is working where, so it is worth running git worktree list occasionally and cleaning up.
  • Expecting to see changes "in real time". As explained above, visibility between agents depends on an explicit commit, not on magic.

The bottom line

The answer to the original question is yes, you can turn Claude Code and Codex into two AI developers working in parallel on the same repo, but the coordination between them does not happen on its own. Git Worktrees give each one its own directory and branch so they do not overwrite files, and commit, merge, and pull are the actual coordination mechanism, not a suggestion. A shared AGENTS.md file adds another coordination layer, so both agents know who is working on what before they touch any code.

If you are just getting started with Codex and want to understand first how to hand it a task and check what came back, before bringing a second agent into the picture, you will find that in the interactive OpenAI Codex 2026 course for 9.90 ILS.

For further reading: What is OpenAI Codex? The complete guide, How to work with Claude Code, a practical guide for beginners, and Claude Code vs. Antigravity, which is better when you already have an existing subscription.

Sources

Frequently asked questions

Was this article helpful?
Share:WhatsAppLinkedInX
Yaakov Tzedek
WRITTEN BY

Yaakov Tzedek

An Israeli AI lecturer, consultant and implementer who has supported 100+ organizations in AI implementation and lectured for 200+. Official content partner of Meta, Google, Canva and TikTok, featured on Israel's Channel 13.

More about Yaakov →