Can Claude Code and Codex work in the same repo?
Yes, with one worktree and branch per agent, one owner per task and shared rules in AGENTS.md. The commands, the files that collide, and how to merge.
Yes. Claude Code and Codex can work in the same repository at the same time, as long as each one has its own git worktree on its own branch, each task has one owner, and both read the same rules from AGENTS.md. What goes wrong is two agents in one folder on one branch: they overwrite each other's files and mix their changes into one diff. A worktree per agent fixes the files, and a claim per task fixes the duplicated work.
Why not just open both in the same folder?#
Because both agents write to the same working tree. Claude Code edits src/api.ts, Codex rewrites the same file a minute later from the version it read earlier, and one set of changes disappears. Even when they touch different files, git status shows one pile of changes from two agents, and you cannot review or revert one without the other. Tests get confusing too: a failure may come from the other agent's half-finished edit.
How do I give each agent its own worktree?#
A worktree is a second checkout of the same repository, in another folder, on another branch. It shares the history, so it costs almost nothing.
cd ~/code/shop
git worktree add ../shop-claude -b claude/csv-export
git worktree add ../shop-codex -b codex/refund-emails
git worktree listThen start each agent in its own folder:
cd ../shop-claude && claude
cd ../shop-codex && codexEach folder needs its own dependencies and its own environment file, because untracked files are not copied:
cd ../shop-codex
cp ../shop/.env .env
npm ciIf both run a dev server, give them different ports. When the work is merged, remove the worktree so old folders do not pile up:
git worktree remove ../shop-codex
git branch -d codex/refund-emailsRunning parallel Claude Code sessions goes deeper on worktrees, including how many sessions are worth running at once.
How do I stop them doing the same task?#
Worktrees keep files apart. They do nothing about two agents picking the same job. The fix is a claim before any code is written, kept somewhere both agents read. A small TASKS.md on the main branch is enough for one person:
## Tasks
- [ ] CSV export for orders (claimed: claude, branch claude/csv-export)
- [ ] Refund confirmation emails (claimed: codex, branch codex/refund-emails)
- [ ] Audit the checkout page for accessibility (unclaimed)And the rule, in AGENTS.md, so both agents follow it:
## Working with other agents
- Before starting, read TASKS.md. Take only an unclaimed task.
- Write your name and branch on it, commit, then start.
- Stay inside the files your task needs. If you must change a shared
file (routes, schema, package.json), say so in TASKS.md first.Claude Code reads CLAUDE.md, so add a CLAUDE.md that imports the rules with the line @AGENTS.md. Sharing context between Claude Code and Codex shows the file layout.
Which files cause most collisions?#
The same few, in almost every project:
| File | Why both agents touch it | What helps |
|---|---|---|
package.json, lockfiles | Both add a dependency | One agent adds dependencies; the other asks |
| Route tables, navigation | Every feature registers itself | Add entries at the end; merge often |
| Database schema, migrations | Two features need new columns | One migration owner per day |
| Shared types | An API shape changes | Write the decision down before coding |
| Test fixtures | Both add sample data | Separate fixture files per feature |
Git catches overlapping lines. It does not catch two agents making different assumptions about the same function. Stopping agents from editing the same files covers those quieter conflicts and the instructions that prevent them.
How do I merge their work?#
Through pull requests, one per branch, like any two developers:
cd ../shop-claude
git push -u origin claude/csv-export
gh pr create --fill --draftMerge the smaller change first, then rebase the other branch on main and run the tests again before it merges. A cross-review helps here: ask Codex to review Claude Code's pull request and the other way round. A reviewer with no memory of writing the code is the main reason to run two agents.
What changes when two people run them?#
On one computer, you are the coordinator. You see both terminals, and TASKS.md is a file on your disk. When Claude Code runs on your laptop and Codex runs on a teammate's, the claims only meet after a push and a pull, and two agents can take the same task within the same minute.
Joxo moves the claim out of a file. Each person pastes one line into their own agent, and the agents share a task board where only one agent can hold a task: a second claim is refused, and that agent is told who has it. A decision one agent publishes reaches the other agent on its next turn, and a handoff carries the branch and the commit. The worktrees and pull requests stay exactly as above. How to use Claude Code and Codex together compares this with the other setups, and the setup page has the line for each agent.
Frequently asked questions#
Can Claude Code and Codex share one branch?#
They can, but only one should be editing at a time. Two agents writing to one branch in one folder overwrite each other's changes. If they must share a branch, hand over explicitly: the first agent commits and pushes, then the second pulls and continues.
Do git worktrees prevent merge conflicts?#
No. Worktrees stop two agents from overwriting each other's files while they work. The branches can still conflict when you merge. Claiming tasks up front and keeping each agent inside the files its task needs makes conflicts rarer and smaller.
Does Codex read CLAUDE.md?#
No. Codex reads AGENTS.md. To give both agents the same rules, keep them in AGENTS.md and make CLAUDE.md import it with the line @AGENTS.md, which Claude Code expands when a session starts.
How many agents can work in one repository?#
As many as you can review. Each extra agent adds a branch to merge and a diff to read. Two or three parallel tasks are a common ceiling for one person; a team can run more because each person reviews their own agent's work.