# 🧹 #1884 stale-worktree sweep — predicate playground

SessionStart hook that removes sibling directories matching `<repo-name>-*` left behind by aborted `git worktree add` attempts (truncation, OOM, force-quit). Without this, the next session's `git worktree add` fails with "already exists" and needs manual `rm -rf`. Toggle the four predicates below to see when the sweep fires.

## Toggle the predicate inputs

name matches `<repo>-*` in `git worktree list` contains regular files mtime < 1h old (in-flight?)
SWEEP → rmSync(path, recursive: true)

## Predicate breakdown — ALL four must hold to sweep

# | Predicate | Why
--- | --- | ---
1 | name matches `<repo>-*` | Only orchestkit-`*` siblings — never touch unrelated dirs
2 | NOT in `git worktree list` | Real worktrees are registered; orphans aren't
3 | zero regular files | `.DS_Store` and `Thumbs.db` ignored; nested empty dirs OK
4 | mtime > 1 hour old | Race protection — don't kill a worktree-add that's mid-flight

## Opt-out

    $ ORK_NO_STALE_SWEEP=1 claude
    # Skips the hook entirely. Useful if you have known empty -* dirs you
    # want to keep (e.g. you're staging a worktree-add manually).

## The exact case that motivated this PR

    $ ls coding/yonatangross/orchestkit-build-diag
    .DS_Store

    $ find coding/yonatangross/orchestkit-build-diag -maxdepth 3 -type f
    .../orchestkit-build-diag/.DS_Store
    # 1 file (just Finder metadata) — qualifies as "empty" once .DS_Store ignored
    # created May 20 17:22, "now" May 20 22:36 → 5h+ old ✓
    # not in `git worktree list` ✓
    # pattern matches `orchestkit-*` ✓
    # → SWEEPS on next SessionStart