chore(claude): aggressive worktree cleanup via Forgejo PR API #498

Merged
lekss361 merged 1 commit from chore/agents-view-aggressive-cleanup into main 2026-05-24 09:34:49 +00:00

1 commit

Author SHA1 Message Date
lekss361
bd73ff2209 chore(claude): aggressive worktree cleanup via Forgejo PR API
Сложение к safe cleanup-merged-worktrees.sh — script на Python который
запрашивает Forgejo PR API чтобы поймать squash-merged branches (где local
SHA не ancestor remote main).

Decision matrix per worktree branch:
- merged (any style)    → REMOVE
- closed (no merge)     → REMOVE (abandoned)
- open                  → KEEP (active PR)
- no PR + age <14d      → KEEP (recent WIP)
- no PR + age >=14d     → REMOVE (stale orphan)

Two-phase removal:
1. git worktree remove --force --force (overrides Claude supervisor locks)
2. shutil.rmtree on orphan dirs (git-untracked but FS-leftover)

Graceful PermissionError handling — dirs locked by running Claude Code
supervisor printed with hint to re-run after restart.

Real run results (single pass, before this commit):
- Before: 102 worktrees, 14GB
- After:  13 git worktrees + 23 FS orphans (PermissionError-locked), 3.7GB
- Removed: 82 git entries (80 merged + 2 closed), -10.3GB (-74%)
- Remaining 12 keep (recent WIP, no PR yet) + 1 current branch
- 23 FS orphans cleanable after next Claude Code restart

Requires:
- FORGEJO_TOKEN env (already set via ~/.claude/settings.json)
- python 3 stdlib only (urllib + json + shutil — no jq/curl/external deps)

Usage:
  python scripts/cleanup-worktrees-aggressive.py --dry-run   # show plan
  python scripts/cleanup-worktrees-aggressive.py             # execute
  AGE_DAYS=30 python scripts/...                             # override threshold
2026-05-24 12:30:15 +03:00