Post-merge worktree cleanup — auto-delete on PR merge #194
Labels
No labels
domain:backend
domain:devops
domain:frontend
status:approved
status:in-progress
status:needs-fix
status:qa
type:bug
type:devops
type:feature
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
ldraney/claude-custom#194
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type
Feature
Lineage
Standalone — scoped during worktree lifecycle enforcement brainstorm (2026-03-28).
Spec:
pal-e-platform/docs/superpowers/specs/2026-03-28-worktree-lifecycle-enforcement-design.mdPlan:
pal-e-platform/docs/superpowers/plans/2026-03-28-worktree-lifecycle-enforcement.md— Task 2Repo
forgejo_admin/claude-customUser Story
As a session operator,
I want merged worktrees to be automatically deleted when a PR merges,
So that stale worktrees don't accumulate on disk.
Context
After PR merge, agent sessions are over but worktrees persist in
.claude/worktrees/. Current cleanup is age-based (>7 days via SessionStart hook). The merge event is the natural cleanup trigger. 700MB incident on 2026-03-13 from accumulated stale worktrees. Both post-merge hooks already fast-forward local main — extending them with worktree cleanup is the minimal change.File Targets
Files the agent should modify:
hooks/post-merge-rebase.sh— add worktree cleanup after existing fast-forward (gh path:gh pr viewfor branch name)hooks/post-mcp-merge-rebase.sh— add worktree cleanup after existing fast-forward (MCP path: Forgejo API for branch name)Files the agent should NOT touch:
hooks/cleanup-worktrees.sh— separate safety net hook, handled by different ticketsettings.json— no new registrations neededAcceptance Criteria
gh pr viewto get head branch namegit worktree list --porcelain, finds worktree on merged branchgit worktree remove --forcegit branch -D[post-merge-cleanup] Removed worktree for branch <name> at <path>Test Expectations
echo '{"tool_input":{"command":"gh pr merge 207 --admin --squash"},"tool_response":{"exitCode":"0"},"cwd":"/home/ldraney/pal-e-platform"}' | bash hooks/post-merge-rebase.shConstraints
$HOME/secrets/pal-e-services/forgejo.env— verify env var name before usingexit 0Checklist
Related
project-pal-e-agency— agent infrastructure projectworktree-workflow— SOP this enforcesScope Review: READY
Review note:
review-508-2026-03-27Scope is solid — all template sections present, both file targets verified (post-merge-rebase.sh line 66, post-mcp-merge-rebase.sh line 62), traceability triangle complete, no blocking dependencies among 4 related worktree tickets, and blast radius is low (leaf hooks, cleanup-worktrees.sh correctly excluded). 8 AC are tightly coupled (same pattern in two files), fits single agent pass.