claude-worktree-cleanup

Daily reaper for stale Claude Code worktrees under /home/claude/.claude/worktrees — each carries a ~15 GB .claude/remote plugin cache; stale ones filled the 387 GB disk on 2026-07-16 (17 worktrees, 117G) and 2026-07-22 (10 worktrees, 149G, disk 98%).

  • Script: /opt/scripts/claude-worktree-cleanup.sh (committed 482bfdf, pushed by the 02:45 cron)
  • Cron: /etc/cron.d/claude-worktree-cleanup — daily 03:30 ET as claude (installed from claude-worktree-cleanup.cron)
  • Log: /var/log/claude-worktree-cleanup.log (self-rotates past 1 MB, scheduler-watchdog pattern)

Removal requires ALL of: dir mtime > 3 days AND no file modified in 24 h; clean git status AND 0 commits ahead of upstream (or master when no upstream — the normal case for claude/* session branches); no process with cwd inside the worktree (/proc/*/cwd scan via sudo). Removes via git -C /home/claude worktree remove --force + worktree prune, then deletes orphaned claude/* branches that are 0 ahead of master; orphans with unmerged commits are kept and logged for manual review.

Also logs df % for / and warns above 90%. Telnyx SMS alert (scheduler-watchdog pattern) is wired but disabled (ENABLE_SMS=0) pending Dustin’s approval — enable in the cron file.

--dry-run flag reports without changing anything. First live run 2026-07-22: removed the synthetic selftest worktree, deleted 9 orphaned branches, kept claude/adoring-meitner-c7cd91 (stranded session-58 rollup commit, flagged for recovery).

Related: disk-bloat-patterns, scheduler-watchdog