Repository navigation
Description
Problem
pr_review.py cleanup <number> scripts only the remote half of post-merge cleanup: verify-then-delete of the merged head branch on GitHub. The local half is still prose: removing the task worktree, deleting the local task branch, and fast-forwarding the base clone. That prose is repo-worktree "Listing and Cleanup" and drive-pr step 4. It says to run git worktree remove <path> and git branch -D <branch> "from the base clone", but gh-write-guard denies both against a primary checkout.
So a session that follows the skills literally ends with the remote branch gone and the local branch still in the maintainer's primary clone. The maintainer then has to run git branch -D by hand after every drive. That is the outcome the maintainer asked not to have.
A path through the guard does work, but no skill states it, so each session has to rediscover it:
git -C <primary> worktree add --detach <helper> origin/develop, as its own callgit -C <helper> worktree remove <task-worktree>, if it is still registeredgit -C <helper> branch -D <task-branch>git -C <helper> worktree remove <helper>, since a linked worktree can remove itselfgit -C <primary> pull --ff-only origin develop, which the guard allows
Proposal
Give pr_review.py cleanup the local half too, so one guard-allowed command (Bash(python3 scripts/pr_review.py:*)) finishes the whole cleanup. It would take a --checkout <primary clone>, or find the clone from the worktree list. Before deleting anything it verifies, from live state:
- the pull request is merged into
developfrom a head in the same repository, as the remote half already checks; - the local branch tip equals the pull request's
headRefOid, so a branch with unpushed commits is never deleted; - the task worktree, where one is registered, is clean and resolves to that head.
It then removes the worktree and the branch through a temporary detached helper worktree, removes the helper, and fast-forwards the base clone, stopping and reporting where the base clone is dirty or cannot fast-forward. It reads back each removal, and keeps the existing exit contract: 0 done, 1 refusal, 2 unconfirmed.
repo-worktree "Listing and Cleanup" and drive-pr step 4 then name the command instead of the raw git steps.
Example
With a constructed task example-task merged as pull request 42, pr_review.py cleanup 42 --repo owner/example --checkout ~/repos/example would:
- delete
origin/example-task; - remove the
example-taskworktree; - delete the local
example-taskbranch; - leave
~/repos/exampleclean atorigin/develop, withgit worktree listshowing only the primary.
Related: #1682 and #1693 cover the remote-delete half of the same guard and procedure mismatch.
Activity
ptr727 commentedon Oct 17, 2026
Correction to the premise, measured against the installed
gh-write-guard: it does not denygit branch -D <branch>or an unforcedgit worktree remove <path>against a primary checkout. Rule 6 denies only the forced remove andpush. What actually stops an agent finishing the local half is that none of the raw git steps is on the permission allowlist, whilepython3 scripts/pr_review.py:*is. So an attended agent has to prompt for each step and an unattended one cannot run them. The proposal holds for that reason. The helper-worktree route in the issue body is not needed, since the script runs git itself.In progress on
feature/agent-cleanup-local-half:cleanup <n> --checkout <primary>for the local half, andcleanup --sweep --checkout <primary> [--apply]for what crashed or abandoned sessions leave behind.Script the Local Half of Post-Merge Cleanup and Sweep Finished Worktr…
Point Every Worktree-Finishing Skill at pr_review.py cleanup (#3188)
Promote Scripted Post-Merge Cleanup and Its Skill Wiring to Main (#3189)