Files
skills/skills/kvb-cleanup/worktrees.md
T
Kevin Veen-BirkenbachandClaude Opus 5.5 fea80f40f7 fix(kvb-cleanup): hand sandbox worktree removal to the operator
An agent sandbox mounts every .git/worktrees/<id> read-only, so git worktree remove unregisters the worktree and then fails with EBUSY; container-owned files fail with EACCES. The worktree rules now forbid removal inside the sandbox and hand the operator the ownership count, chown and removal command in one message. A dirty worktree is a candidate only when all its changed and untracked content is preserved at a branch tip, and an untagged image with RepoDigests counts as a medium-risk digest pull. Both files were trimmed so the skill text does not grow.

🎯 Fix: 92 %
💥 Break: 2 %
💸 Cost: 100 %
⏱️ Time: 100 %
🛡️ Security: 100 %
🏆 Score: 90
🚦 Gate: ✅ 90/5, cost and time <= 100, security 100 %

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 09:34:03 +00:00

27 lines
1.2 KiB
Markdown

# Worktrees
## Inventory
Per worktree: size (`du -sh`), dirty state, whether its branch is pushed and
whether its HEAD is in an integration line (the default branch and every
branch the project merges features into; ask the operator or the project's
memory). With `pkgmgr`, `pkgmgr branch gc --json --sizes --merged-into
<line>` (one per line) measures it all; merged-clean items go to the
`kvb-git-branch-gc` skill.
Clean and in a line: medium, its ignored files (`node_modules`, build output,
evidence) are lost. Dirty: a candidate only when every changed, staged and
untracked file is a blob at some branch tip and a detached HEAD is reachable
from another ref; else it is unique work and stays.
## Removal
The way it was made: a slot worktree through the project's teardown target
(e.g. `make worktree-down`), a sidetree through `git worktree remove`,
`--force` only for a dirty one cleared above. Never in an agent sandbox: its
read-only `.git/worktrees/<id>` mounts make git unregister and then fail with
`Device or resource busy`, container-owned files with `Permission denied`.
Hand the operator in one message, per worktree, its count of `find <wt> -not
-user "$USER" -prune | wc -l`, `sudo chown -R "$USER": <wt>` where it is not
0, then the removal command.