PR Post-merge Cleanup
Trigger
- The task requester explicitly says "cleanup after merge" or "clean up the task."
- This SKILL is invoked directly.
Preconditions
- The target PR is actually merged on GitHub:
gh pr view {number} --json state,mergeCommit. - The task requester approved Issue close, or the PR body included
closes #Nand the Issue was automatically closed.
Procedure
- Check PR and Issue state.
gh pr view {number} --json state,mergedAt,mergeCommit,headRefName gh issue view {N} --json state- If PR
state != MERGED, stop immediately and report to the task requester.
- If PR
- Close the Issue only if it was not already closed.
gh issue close {N} - Update
{BASE_BRANCH}.git fetch origin --prune git checkout {BASE_BRANCH} git pull --ff-only - Delete the remote publish branch. Skip if the branch was already deleted by PR merge with
--delete-branch.git push origin --delete publish/task{N} 2>&1 || echo "already deleted" - Remove the separate worktree if one was used.
git worktree remove ../{repo}-task{N} git worktree prune - Delete the local work branch only when it is no longer needed.
git branch -d local/task{N} # Forced deletion requires explicit task requester approval: git branch -D local/task{N} - Final daily task board check: confirm the #{N} row in
mydocs/orders/{yyyymmdd}.mdisDonewith a completion time. - Report the cleaned items briefly to the task requester.
Verification
gh pr view {number}showsstate == MERGED.git branch -vv | grep local/task{N}has no output if the branch was deleted.git ls-remote origin publish/task{N}has empty output.git worktree listdoes not include the cleaned worktree.git branch --show-currentis{BASE_BRANCH}.
Never Do
- Close an Issue when the PR is not merged.
- Delete another task branch or the main worktree.
- Run
git branch -Dwithout explicit approval; unmerged commits may be lost. - Delete another worker's stash.
Invocation
- Codex:
$pr-merge-cleanupor the/skillsmenu - Claude Code:
/pr-merge-cleanup