Skip to content

Add worktree and OrbStack modules to disk-cleanup - #266

Merged
haacked merged 1 commit into
mainfrom
haacked/disk-cleanup-orphans
Oct 28, 2026
Merged

haacked merged 1 commit into
mainfrom
haacked/disk-cleanup-orphans

Conversation

@haacked

@haacked haacked commented Oct 28, 2026

Copy link
Copy Markdown
Owner

My disk filled up, partly with worktrees nothing cleans up. Supacode's merged-worktree action is off, so worktrees stay after their PR merges. Some deletions also left directories behind. In posthog worktrees created before its flox manifest set GOFLAGS=-modcacherw, git worktree remove --force fails partway on the read-only Go module cache in .flox/cache/go. It drops git's record of the worktree and leaves the files. OrbStack also left a 16G data.img.raw.corrupt after a disk-image recovery.

This adds two disk-cleanup modules. worktrees lists directories under the worktree roots that no git repo tracks, plus worktrees whose PR merged. orbstack lists corrupt OrbStack data images. Both only list by default and delete with --aggressive.

The deletion rules lean toward keeping things. A checkout git no longer tracks is only listed, because git can't tell whether it holds edits. --aggressive deletes only leftover directories with no .git inside. A merged worktree stays when it has an open Supacode tab, a process working in it, changes or commits after the merged head, ignored files that aren't build output (such as .notes/ or .env), skip-worktree flags, a nested checkout, or a lock Supacode doesn't hold. The module makes directories writable before removing them, so a read-only Go cache can't stop a removal partway.

tree-me remove and git-bclean-local don't make read-only directories writable yet. The merged check calls gh once per worktree, so a run takes about 40 seconds.

Test plan

  • bin/lib/test-cleanup-worktrees.sh (79 assertions) and bin/lib/test-cleanup-orbstack.sh (7) pass under macOS /bin/bash
  • Disabling each guard makes at least one test fail
  • disk-cleanup --module worktrees lists real orphans and merged worktrees, and keeps worktrees with open Supacode tabs or .notes/
  • Run disk-cleanup --module worktrees --aggressive and confirm only the listed directories go away

https://claude.ai/code/session_01AovXvYZu2bc85xrmWjjkz2

The worktrees module lists worktree directories that no git repo tracks
and worktrees whose PR merged. With --aggressive it removes leftover
directories that hold no checkout, and merged worktrees that would lose
nothing: no changes or commits after the merge, no ignored files beyond
build output, no open Supacode tab, and no process working in them.
Checkouts git no longer tracks are only listed, because git cannot tell
whether they hold edits.

The orbstack module lists data images OrbStack set aside as corrupt and
removes them with --aggressive.

Claude-Session: https://claude.ai/code/session_01AovXvYZu2bc85xrmWjjkz2
@haacked
haacked marked this pull request as ready for review October 28, 2026 22:57
@haacked
haacked merged commit 77a21f4 into main Oct 28, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant