Back/Engineering/Codex
IntermediateEngineering

How to Manage Parallel Development with AI using Git Worktrees and Codex

Give parallel Codex tasks separate Git worktrees so each agent has its own branch and directory. Alex creates French and German variants, runs both at once, and keeps their changes independently testable.

How to Manage Parallel Development with AI using Git Worktrees and Codex

Alex asks Codex to create French and German worktrees from main, opens each in its own terminal tab, and runs the two translation tasks in parallel.

Before you start

What you need

  • A clean Git repository with a main branch
  • Codex CLI
  • Two changes that can be developed independently

What you’ll make

Two isolated worktree directories and branches where Codex can run concurrently without writing into the same checkout.

Tools used

  • Codex

    OpenAI's cloud-based AI software engineering agent that can execute code, run tests, and handle complex multi-file tasks autonomously.

    VisitCodex

Step by step

The workflow

Follow the sequence once, then adapt the prompts, checks, and handoffs to your own setup.

3 steps

Step01

Let Codex Create Your Worktrees

From the main checkout, ask Codex to create one worktree and branch for each independent experiment. Use names that describe the work so the directory, branch, and terminal tab are easy to match.

Example prompt
Create two Git worktrees from the current main branch. Name one branch and directory `french` and the other `german`. Show me the resulting paths and confirm the active branch in each worktree.
Step02

Run Parallel Tasks in Isolated Environments

Open one terminal tab in each worktree and run a separate Codex task. Alex translated the same placeholder into French and German, which made the separation visible while both agents worked concurrently.

Example prompt
# In the french worktree
Translate the input field placeholder strings to French. Keep the change limited to user facing placeholder copy and run the relevant tests.

# In the german worktree
Translate the input field placeholder strings to German. Keep the change limited to user facing placeholder copy and run the relevant tests.
Step03

Review and Merge Changes Independently

Review each branch from its own directory, run the app or tests there, and keep or discard the experiments independently. Merge the chosen branch first, then update and retest the other branch if you still want both changes.

What good looks like

  • Each worktree has its own branch and directory.
  • Changes in one worktree do not appear in the other.
  • Both tasks can run and be tested at the same time.
  • Each branch can be reviewed or merged independently.

Build your next product with ChatPRD

Turn an idea into a PRD, user stories, and a plan.

Try ChatPRD free

After the steps

Runbook notes

How to recover when the loop fails and where human judgment helps.

Recover

If it goes sideways

Git reports that a branch is already checked out
Use a new branch name or inspect `git worktree list` to find the directory that already owns the branch.
Both agents are editing the same checkout
Stop one task and reopen it from the second worktree directory. Confirm each terminal prompt shows a different path and branch.
The branches still conflict when combined
Merge one branch at a time, resolve the shared lines in the target branch, and rerun the project checks after the combined result.

Start shipping
better products.

Join 100,000+ product managers who use ChatPRD to write better docs, align teams faster, and build products users love.

Free to start
No credit card
SOC 2 certified
Enterprise ready