Isolated Codex tasks with Git worktrees
Codex worktrees isolate mutable files so parallel tasks can inspect, edit, install dependencies, and run tests without sharing one working directory. The Codex app can create a managed worktree for a task. Codex CLI 0.146.0 has no --worktree flag, so terminal workflows create the checkout with Git and start Codex inside it.
Choose the surface
Section titled “Choose the surface”| Need | Use | Boundary |
|---|---|---|
| App-managed isolated task | Create a Codex task with the worktree environment | Start from an explicit repository state and inspect the resulting diff |
| CLI session in an isolated checkout | git worktree add, then run codex in that directory | Git owns creation, branch naming, listing, and removal |
| Non-Git directory | Direct local task | Worktree isolation is unavailable; copy or initialize only when policy allows |
The app workflow is documented in Codex worktrees. CLI availability was checked with codex --help on 4 September 2026.
CLI workflow
Section titled “CLI workflow”-
Check the repository and current changes.
Terminal window git status --shortgit branch --show-currentgit worktree listDo not base a new worktree on uncommitted changes unless you deliberately commit or otherwise transfer them.
-
Create a branch and checkout.
Terminal window git fetch origingit worktree add -b codex/fix-auth ../project-codex-fix-auth origin/mainReplace the branch, path, and base with verified values. Never invent the default branch.
-
Start Codex in the worktree.
Terminal window cd ../project-codex-fix-authcodexLoad project-specific environment setup without copying production credentials. Run separate ports for parallel dev servers.
-
Verify and integrate.
Run the repository gates, inspect
git diff, commit on the task branch, and open a PR. Merge through the normal review path; do not apply several agent patches blindly. -
Remove only after preserving work.
Terminal window git -C ../project-codex-fix-auth status --shortgit worktree remove ../project-codex-fix-authgit worktree pruneThe remove command refuses dirty worktrees by default. Do not add
--forceuntil the exact disposable state is proven.
Parallel-task contract
Section titled “Parallel-task contract”Give every task:
- one outcome and non-goals;
- a distinct worktree and branch;
- non-overlapping ownership where possible;
- its own ports, caches, and local service state;
- explicit shared-cloud prohibitions;
- exact tests and a proof report;
- an integration order and human owner.
Work only in this checkout and branch.Implement the accepted plan.md without touching shared cloud state.Run the documented gates and report commands plus exit codes.Stop if another task changed the same interface or if the plan must change.Do not merge, deploy, or remove the worktree.Failure modes
Section titled “Failure modes”A branch is already checked out elsewhere. Inspect git worktree list and create a distinct branch; Git permits one checked-out worktree per branch.
The task sees no local environment file. Use the repository’s documented bootstrap or copy only explicitly allowed gitignored development files. Never solve setup by copying production secrets.
Parallel servers collide. Assign a port block per worktree and pass it explicitly to the dev server and tests.
Changes conflict during integration. Rebase or merge in a human-chosen order, rerun the full gates, and update plan.md when the design changed.
Verify isolation
Section titled “Verify isolation”- Every running task maps to one path and branch in
git worktree list. - Development ports and local databases are distinct.
- No task can mutate shared production or third-party state.
- Each task reports its own commands, exit codes, and diff.
- Integration runs the combined test suite.
- Cleanup preserves every wanted commit and branch.
Continue with Codex
Section titled “Continue with Codex”Use the Codex AI-native SDLC adapter for plan, build, review, and automation. Recheck Codex developer commands before scripting CLI flags.