Leverage git worktree to parallelize work with Codex, Claude Code, etc.
Source: Dev.to
The problem
In a traditional Git repository you have:
- The source code in a working directory, e.g.
/Users/qlerebours/Projects/traveledmap. - A checked‑out branch, e.g.
feat/my-main-feature. - The
.gitfolder that contains the project history.
Switching branches changes the files in your current directory, which makes it difficult to run tools like Codex, Claude Code, etc., on multiple features at the same time. Cloning the project into a second folder is not ideal because it duplicates the (potentially large) .git folder.
git worktree
git worktree lets you attach multiple working directories to the same Git repository while keeping a single .git directory.
# Add a new worktree for a parallel task
git worktree add ../traveledmap-fix-wording fix/add-form-validations
After running the command the folder structure looks like this:
/Users/qlerebours/Projects/traveledmap/ (branch feat/my-main-feature)
/Users/qlerebours/Projects/traveledmap-fix-add-form-validations/ (branch fix/add-form-validations)
- A single
.gitfolder lives in/Users/qlerebours/Projects/traveledmap/. - Each worktree uses its own branch.
- Commits are visible instantly across all worktrees.
This setup lets your code assistant work on two features in parallel.
Using git worktree with AI development assistants
-
Start a new conversation in Codex (or Claude Code) and choose Worktree and from develop as the base for the new branch.
-
When you send the prompt, Codex announces that it’s creating the worktree. You can verify it with:
git worktree list -
The worktree will appear under a path similar to
/Users/qlerebours/.codex/worktrees//traveledmap.
Test the changes
If you want to test the changes without pulling them locally:
-
Enter the worktree folder.
-
Since the worktree starts from the
developbranch, set up the environment:cp .env.example .env pnpm i -
Run the project:
pnpm run dev -
If new changes are needed, Codex will add them to the existing worktree so you can test again.
Taking control of the changes
You have several options to continue work locally:
- Open the worktree folder in your preferred code editor and make the desired changes.
- Use the “Hand off to local” button in the Codex conversation; this commits the changes to the repository.
- Use the “Create a branch” button, which creates a new branch and pushes it, allowing you to open a PR directly.
Further reading
The full documentation for this workflow is available in the Codex docs.
Understanding git worktree opens the door to efficient collaboration with AI development assistants. If you have questions, feel free to reach out by email or on LinkedIn.