SIGN IN SIGN UP
tw93 / Mole UNCLAIMED

🐹 Deep clean and optimize your Mac.

0 0 83 Shell

feat(clean): reclaim stale AI agent git worktrees (#985)

* feat(clean): reclaim stale AI agent git worktrees

AI coding agents (Claude Code and similar) create isolated git worktrees
under <project>/.claude/worktrees/ for background or parallel runs. Each is
a full project checkout (node_modules, build output, and so on) that is
never cleaned up automatically, so they accumulate across repos and can
reach several GB. Existing cleanup only handled agent binary versions and
global ~/.claude state, so these were missed entirely.

Add clean_dev_agent_worktrees to the developer-tools flow:

- Skipped by default; reports reclaimable size plus the opt-in hint.
- With MOLE_AGENT_WORKTREES=1, removes only worktrees that are fully clean
  (no uncommitted or untracked changes and no commits missing from a
  remote); anything that might hold unsaved work is kept and listed.
- Deletes via safe_clean (Trash routing, op log, dry-run) and honors
  should_protect_path; no raw rm.
- Reaps the parent repo's worktree registry with unlock + prune
  --expire=now, because agents lock their worktrees and a plain prune skips
  locked entries even when the directory is already gone.
- Search roots overridable via MOLE_AGENT_WORKTREE_PATHS.

Adds two bats cases: the skip-by-default report, and opt-in removal of a
locked clean worktree while keeping a dirty one.

* refactor(clean): wrap agent worktree git calls with run_with_timeout

Match the surrounding lib/clean/dev.sh pattern so a hung git repo
cannot stall the cleanup section.

---------

Co-authored-by: Fabián Delgado <8621547+fabdelgado@users.noreply.github.com>
F
Fabián Delgado committed
bbf50d9ddbbdc19d5b8de7580272bb7bae10273a
Parent: 1eac15d
Committed by GitHub <noreply@github.com> on 5/26/2026, 11:02:09 PM