Bug: 31 stale agent worktrees accumulating across repos #243
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/pal-e-platform#243
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
Bug
Lineage
Repo
Fix target:
forgejo_admin/claude-custom(hooks/cleanup-worktrees.sh). pal-e-platform is the worst-affected repo but contains no fixable code.What Broke
Agent worktrees are not being cleaned up after agent completion. ~70 stale worktree directories found across 4 repos (~1.8GB disk waste):
~/.claude/worktrees/agent-*/tmp/basketball-api-*/tmp/pal-e-api-199/tmp/pal-e-docs-app-94Root cause:
cleanup-worktrees.shonly iteratesgit worktree list --porcelain. Orphaned directories (git lost registration, directory remains on disk) are invisible to the script. 37 of 64 pal-e-platform directories are orphans — the cleanup script never sees them. Script needs filesystem scan of.claude/worktrees/agent-*and/tmp/{repo}-*patterns in addition to git-tracked worktrees.Repro Steps
ls ~/.claude/worktrees/ | wc -l— shows 64+ directoriesgit -C ~/pal-e-platform worktree list | wc -l— shows only 27 (git-tracked)Expected Behavior
Post-merge cleanup hook should remove both git-tracked worktrees AND orphaned directories for merged branches.
Environment
~/.claude/worktrees/agent-*(Claude Code managed) and/tmp/*(agent-created)File Targets
hooks/cleanup-worktrees.sh— add filesystem scan for orphaned directories alongside git worktree listhooks/forgejo-helper.sh—remove_worktree_for_branchfunction (may need orphan-aware cleanup)Acceptance Criteria
Constraints
Checklist
Related
Scope Review: NEEDS_REFINEMENT
Review note:
review-637-2026-03-28Root cause identified during review:
cleanup-worktrees.shonly iteratesgit worktree list --porcelain— orphaned directories (git lost registration, dir remains on disk) are invisible. 37 of 64 pal-e-platform worktree dirs are orphans.Issues found:
claude-custom(hooks/cleanup-worktrees.sh,hooks/forgejo-helper.sh).claude/worktrees/agent-*and/tmp/{repo}-*patternshooks/forgejo-helper.shScope Refinement Applied (review-637-2026-03-28)
5 body changes per review recommendations:
Re-running scope review.
Scope Review: APPROVED
Review note:
review-637-2026-03-28-v2Re-review after refinement. All 5 BODY fixes from the previous review have been applied correctly. Template complete, traceability intact, file targets verified against codebase, acceptance criteria testable. Ready for dispatch.