
How to Run Claude Code and Codex in Parallel on One Repo (Git Worktrees, Step by Step)
Run Claude Code and Codex on the same repository at once without them overwriting each other: one git worktree per agent, scoped briefs, and a safe merge. Step by step.
Give each agent its own git worktree: a separate folder and branch that shares your repository's history. Start Claude Code in one, Codex in the other, give each a scoped task, then review and merge the branches one at a time. Two agents in one folder overwrite each other; two worktrees can't. The full procedure takes about ten minutes the first time.
What you need before you start
- Git 2.17 or newer. Worktrees exist since 2.5;
git worktree removearrived in 2.17. - Claude Code and the Codex CLI, each installed and logged in to its own account.
- A clean main branch. Commit or stash your changes first.
- Two tasks that don't touch the same files. Step 1 shows how to pick them.
Connect the Claude or Codex you already pay for — the rest runs on workers that cost a fraction.
Download meshcode →Step 1: Pick two independent tasks
| Good split | Bad split |
|---|---|
Refactor the API client in src/api/ and write UI tests in src/ui/ |
Two agents both cleaning up the auth flow |
| A new endpoint and its documentation | Renaming a shared type while another agent builds a feature on it |
| A backend migration and frontend copy changes | Anything that edits package.json or the lockfile from both sides |
If two tasks overlap in the same files, run them one after the other. Parallel work on overlapping files costs more to reconcile than it saves.
Step 2: Create one worktree per agent
cd ~/code/myapp
git switch main && git pull
git worktree add ../myapp-claude -b agent/claude-api
git worktree add ../myapp-codex -b agent/codex-ui
git worktree list
Each git worktree add creates a sibling folder with a new branch based on your current commit. Both folders share one .git history, so this is fast and light on disk. Claude Code can also create its own: claude -w api-refactor starts a session in an isolated worktree at <repo>/.claude/worktrees/api-refactor, according to Anthropic's CLI reference.
Step 3: Prepare each worktree
A new worktree contains only tracked files. Anything git ignores, such as .env, node_modules and build output, is not copied over.
cp .env ../myapp-claude/.env
cp .env ../myapp-codex/.env
(cd ../myapp-claude && npm install)
(cd ../myapp-codex && npm install)
Give each dev server its own port (for example 3001 and 3002), and don't point both worktrees at the same development database, or two agents will run migrations against one schema.
Step 4: Start each agent in its own folder
# terminal 1
cd ../myapp-claude && claude
# terminal 2
cd ../myapp-codex && codex
Give each agent a scoped brief. A template that works:
Task: refactor the API client in src/api/ to use the shared retry helper.
Scope: only files under src/api/ and their tests. Do not edit src/ui/,
package.json or the lockfile.
Done when: the test suite passes and all changes are committed to this branch.
The scope line is what keeps two agents from wandering into each other's files. If your project has shared rules, keep them in one AGENTS.md that both agents read; our guide to using both agents shows the CLAUDE.md import that makes this work.
Step 5: Review each branch before merging
cd ~/code/myapp
git diff main...agent/claude-api --stat
git diff main...agent/codex-ui --stat
Read the diff, not the agent's summary of it. For a second opinion, ask the other agent to review the branch and list problems without editing anything; the pattern is covered in building a code review agent with a second model.
Step 6: Merge one branch at a time
git merge --no-ff agent/claude-api
npm test
git merge --no-ff agent/codex-ui
npm test
Merging one, testing, then merging the second makes conflicts and broken assumptions show up one at a time instead of together.
Step 7: Clean up
git worktree remove ../myapp-claude
git worktree remove ../myapp-codex
git branch -d agent/claude-api agent/codex-ui
If git refuses because a worktree has uncommitted changes, commit or stash them, or pass --force to discard them.
Common errors and fixes
| Symptom | Cause | Fix |
|---|---|---|
fatal: 'agent/...' is already checked out at ... |
Git allows a branch in only one worktree | Create a new branch per agent |
| Tests fail only in the new worktree | Ignored files (.env, node_modules) were not copied |
Repeat step 3 |
Port already in use |
Both dev servers use the default port | Assign each worktree its own port |
| Lockfile conflicts on merge | Both agents changed dependencies | Let one agent own dependency changes |
| Old worktree folders linger after deleting by hand | Git still lists them | Run git worktree prune |
Want to skip the bookkeeping?
Several tools automate the worktree setup, from terminal managers to desktop apps and the vendors' own apps. We compare them in the best AI workspaces for Claude Code and Codex.
The meshcode angle
In meshcode you point two panes at the two worktree folders, one running your Claude Code login and one running Codex, and watch both in a single window. Each pane keeps its own history, so you can interrupt one without touching the other. Your skills, hooks, MCP servers and CLAUDE.md carry over untouched, and Claude and Codex bill you directly with no meshcode token charge. meshcode's own delegated write tasks can also run in isolated worktrees through an opt-in per-repo setting.
See the pricing yourself: meshcode is free to start — download it
FAQ
Do I need worktrees, or are branches enough?
Branches alone are not enough. Two agents in one working directory still share the same files on disk, whatever branch is checked out. A worktree gives each agent its own folder.
Can both agents use the same branch?
No. Git refuses to check out one branch in two worktrees at once, and two agents committing to one branch would tangle their history anyway.
How much disk space do worktrees use?
Git history is shared, so the cost is the working files plus anything you install per worktree, such as node_modules.
Does this work on Windows?
Yes. Git for Windows supports worktrees, and the commands are the same in PowerShell or Git Bash apart from path syntax.
Sources: the git-worktree documentation at git-scm.com and Anthropic's Claude Code CLI reference, read September 21, 2026.
👉 Download meshcode — Mac, Windows
More from the blog
The Cheapest Way to Use Grok for Coding in 2026
The cheapest way to use Grok for coding depends on how you work: API tokens from about $1 per million, Cursor Pro at $20 with a dedicated Grok pool, or SuperGrok at about $30. What each route really costs.
Can You Use Claude Code and Codex at the Same Time? (2026 Guide)
Yes. Claude Code and Codex have separate logins, billing and usage limits, so you can run both on one project today. How to set it up, what goes wrong, and what it costs.
Best AI Workspaces for Running Claude Code and Codex Together (2026)
Terminal panes with git worktrees, Claude Squad, Conductor, Zed, the Codex and Claude desktop apps, Vibe Kanban and meshcode compared: what each runs, what it costs, who it fits.