Delegate implementation to Codex in an isolated git worktree.
- Well-defined implementation tasks
- When you want Codex to write code independently
- For tasks where worktree isolation prevents conflicts with ongoing work
- When the primary AI is better used for review than generation
-
Extract spec from user input.
-
Verify git repository. Stop if not in one.
-
Create isolated worktree:
BRANCH="codex/$(date +%s)" git worktree add "/tmp/$BRANCH" -b "$BRANCH" HEAD
-
Run Codex in full-auto mode:
codex exec --full-auto -C "/tmp/$BRANCH" "<spec>" 2>&1
-
Capture output and check exit code.
If Codex exits with a non-zero code, report the error to the user and offer to show the full output. Clean up the worktree regardless of success or failure.
-
Show diff:
git -C "/tmp/$BRANCH" diff HEAD -
Present results:
## Codex Implementation ### Files Changed [list with +/- lines] ### Diff [key changes summarized — full diff on request] ### Primary AI Assessment [Review of Codex's implementation: correctness, style, completeness] ### Options 1. Merge into current branch 2. Cherry-pick specific files 3. Discard -
If merge:
git -C "/tmp/$BRANCH" add -A && git -C "/tmp/$BRANCH" commit -m "codex: <spec summary>" # From your original working directory (not the worktree): git merge "$BRANCH" git worktree remove "/tmp/$BRANCH"
-
If discard:
git worktree remove --force "/tmp/$BRANCH" git branch -D "$BRANCH"
- Created fresh for each implementation
- Isolated from main working tree
- ALWAYS cleaned up — on success, failure, or discard
- Never leave orphaned worktrees
Worktree isolation means Codex can work freely without affecting your current state. Review the diff carefully before merging — Codex is the implementer, the primary AI and the human are the reviewers. If Codex's implementation is partially correct, cherry-pick rather than wholesale merge.