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
Prevent cleanup from deleting active agent cwd (#536)
Cleanup and finish commands can be launched through wrappers that run their destructive worktree prune subprocesses from a repo root instead of the caller's nested agent cwd. The finish/prune path now forwards the original cwd, resolves it back to the managed worktree for the same git common dir, and skips any worktree containing that cwd.
Constraint: Codex and Claude hooks reload skills after tool use and fail with os error 2 when their cwd disappears.
Rejected: Only pivot finish to repo root | wrapper and cleanup entrypoints still lose the caller cwd before prune.
Confidence: high
Scope-risk: narrow
Directive: Do not remove GUARDEX_FINISH_ACTIVE_CWD or GUARDEX_PRUNE_ACTIVE_CWD propagation without reproducing finish/cleanup from a nested active worktree cwd.
Tested: node --test test/worktree.test.js test/finish.test.js test/metadata.test.js
Tested: bash -n scripts/agent-branch-finish.sh
Tested: bash -n scripts/agent-worktree-prune.sh
Tested: openspec validate --specs
Co-authored-by: NagyVikt <nagy.viktordp@gmail.com>
`gx branch finish --cleanup`, `gx cleanup`, and `gx worktree prune` can be invoked from a process whose real cwd is inside a managed agent worktree while the subprocess that performs cleanup runs from the repo root. In that shape, cleanup can remove the caller's worktree and leave Codex/Claude hooks or skill reloads with `No such file or directory (os error 2)`.
6
+
7
+
## Change
8
+
9
+
- Forward the caller cwd into finish and prune subprocesses.
10
+
- Treat a worktree as active when the forwarded cwd is inside it, not only equal to the worktree root.
11
+
- Preserve the active worktree/branch during cleanup and tell the user to leave that directory before pruning it.
0 commit comments