Bug: cleanup-worktrees.sh misses orphaned directories not registered with git #222

Closed
opened 2026-03-29 03:21:42 +00:00 by forgejo_admin · 0 comments
Contributor

Type

Bug

Lineage

Repo

forgejo_admin/claude-custom

What Broke

cleanup-worktrees.sh only iterates git worktree list --porcelain. Orphaned directories (git lost registration, directory remains on disk) are invisible to the script. 37 of 64 pal-e-platform worktree dirs are orphans that never get cleaned up (~1.8GB disk waste across repos).

Repro Steps

  1. ls ~/pal-e-platform/.claude/worktrees/ | wc -l — shows 67 directories
  2. git -C ~/pal-e-platform worktree list | wc -l — shows only 31 (git-tracked)
  3. Difference = 36 orphaned directories invisible to cleanup script
  4. All orphans are empty (no .git file, 12K each)

Expected Behavior

Post-session cleanup should remove both git-tracked worktrees AND orphaned directories for merged/stale branches.

Environment

  • All repos on archbox
  • Worktree paths: {repo}/.claude/worktrees/agent-* (Claude Code managed) and /tmp/{repo}-* (agent-created)
  • Related PRs #194 and #195 were merged but only scan git-tracked worktrees

Acceptance Criteria

  • Filesystem scan added to cleanup-worktrees.sh for orphaned directories
  • Orphans with .git file: branch extracted, merge verified, then removed
  • Orphans without .git file: removed if old enough (age-based)
  • remove_worktree_for_branch in forgejo-helper.sh handles orphan dirs
  • git worktree prune called after cleanup to clear dangling refs
  • forgejo_admin/pal-e-platform#243 — parent issue
  • claude-custom#194 — post-merge worktree cleanup (merged but insufficient)
  • claude-custom#195 — cleanup-worktrees.sh repo list fix (merged)
### Type Bug ### Lineage - Parent: forgejo_admin/pal-e-platform#243 - Board: board-pal-e-platform - Story: story:superuser-deploy - Arch: arch:worktree ### Repo forgejo_admin/claude-custom ### What Broke `cleanup-worktrees.sh` only iterates `git worktree list --porcelain`. Orphaned directories (git lost registration, directory remains on disk) are invisible to the script. 37 of 64 pal-e-platform worktree dirs are orphans that never get cleaned up (~1.8GB disk waste across repos). ### Repro Steps 1. `ls ~/pal-e-platform/.claude/worktrees/ | wc -l` — shows 67 directories 2. `git -C ~/pal-e-platform worktree list | wc -l` — shows only 31 (git-tracked) 3. Difference = 36 orphaned directories invisible to cleanup script 4. All orphans are empty (no .git file, 12K each) ### Expected Behavior Post-session cleanup should remove both git-tracked worktrees AND orphaned directories for merged/stale branches. ### Environment - All repos on archbox - Worktree paths: `{repo}/.claude/worktrees/agent-*` (Claude Code managed) and `/tmp/{repo}-*` (agent-created) - Related PRs #194 and #195 were merged but only scan git-tracked worktrees ### Acceptance Criteria - [ ] Filesystem scan added to cleanup-worktrees.sh for orphaned directories - [ ] Orphans with .git file: branch extracted, merge verified, then removed - [ ] Orphans without .git file: removed if old enough (age-based) - [ ] remove_worktree_for_branch in forgejo-helper.sh handles orphan dirs - [ ] git worktree prune called after cleanup to clear dangling refs ### Related - forgejo_admin/pal-e-platform#243 — parent issue - claude-custom#194 — post-merge worktree cleanup (merged but insufficient) - claude-custom#195 — cleanup-worktrees.sh repo list fix (merged)
forgejo_admin 2026-03-29 03:43:19 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
ldraney/claude-custom#222
No description provided.