You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat: git worktree isolation for write-capable rescue tasks #135
When /codex:rescue runs with --write, it uses Codex's native workspace-write sandbox, which edits files directly in the current working directory. This creates conflicts when:
Concurrent uncommitted work — The user has staged/unstaged changes in their working tree. Codex's edits interleave with the user's in-progress work, making it hard to separate what Codex changed from what the user was already doing.
Parallel Claude + Codex work — Claude Code may be actively editing files in the same directory while Codex rescue is running in the background. Both agents writing to the same files creates race conditions and merge conflicts.
Safe rollback — If Codex's changes are unwanted, the user has to manually git checkout individual files or use git stash tricks. With a worktree, you just git worktree remove and it's gone.
Proposed Solution
For write-capable rescue tasks, optionally create a git worktree so Codex operates in an isolated copy of the repository:
Then run the Codex task against the worktree path instead of the main working directory. After completion:
Keep: Generate a patch from the worktree and apply it to the main tree, or let the user merge the branch
Discard: git worktree remove + git branch -D
This could be exposed as a --worktree flag on /codex:rescue, or made the default for background write tasks where the risk of conflict is highest.
Prior Art
I built a custom Codex skill for Claude Code that uses this exact pattern — subagent creates a worktree, runs codex exec -s workspace-write inside it, then presents a diff for review before applying. It works well in practice and eliminates the concurrent-edit problem entirely.
Alternatives Considered
Stash-based isolation: git stash before Codex runs, restore after. Fragile and loses staged vs unstaged distinction.
Branch-based: Just create a branch. Doesn't help — still editing the same working directory.
Do nothing: Users accept the risk. Works for simple cases but breaks down with background tasks or concurrent editing.
+1 — hit this concretely. A Codex adversarial review of a rescue change in our fork (axisrow/codex-plugin-cc#8, defaulting rescue to --background) flagged exactly this: rescue defaults to --write (agents/codex-rescue.md) and runs Codex in the caller's checkout via workspace-write, with no writer isolation, so a background rescue races the main Claude thread / user editing the same files. Verified in code — no per-workspace writer lock, no worktree.
The race is pre-existing (independent of foreground/background); defaulting rescue to background just makes it reachable from one more path. Confirmed the proposing PR doesn't touch the --write default.
Tracked in our fork as axisrow/codex-plugin-cc#10. We're porting @peterdrier's #137 (the --worktree flag + isolation) into the fork to validate and adapt it — including the #493 (forward worktree cwd to the detached task) and #198 (don't clean up the worktree before Codex finishes) intersections. Happy to feed back anything we find that #137 needs upstream.
cc @peterdrier — your #137 looks like the right shape; planning to dogfood it in the fork.
Activity
feat: add --worktree flag for isolated write-capable rescue tasks
axisrow commentedon Jul 19, 2026
+1 — hit this concretely. A Codex adversarial review of a rescue change in our fork (axisrow/codex-plugin-cc#8, defaulting rescue to
--background) flagged exactly this: rescue defaults to--write(agents/codex-rescue.md) and runs Codex in the caller's checkout viaworkspace-write, with no writer isolation, so a background rescue races the main Claude thread / user editing the same files. Verified in code — no per-workspace writer lock, no worktree.The race is pre-existing (independent of foreground/background); defaulting rescue to background just makes it reachable from one more path. Confirmed the proposing PR doesn't touch the
--writedefault.Tracked in our fork as axisrow/codex-plugin-cc#10. We're porting @peterdrier's #137 (the
--worktreeflag + isolation) into the fork to validate and adapt it — including the #493 (forward worktree cwd to the detached task) and #198 (don't clean up the worktree before Codex finishes) intersections. Happy to feed back anything we find that #137 needs upstream.cc @peterdrier — your #137 looks like the right shape; planning to dogfood it in the fork.
feat(worktree): isolated rescue worktree, leave-branch cleanup (based…