clean-worktrees
Skill41 starsChanged 23 days agoMITView on GitHub
Report which git worktrees and local branches of this repo are safe to remove, then remove only the rows the owner confirms. Use when the owner asks to clean or prune worktrees or branches, or `git worktree list` shows more than the three-worktree limit. Not for creating worktrees, merging, or deleting `backup/*` branches.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- 7zrv/claude-code-monitortheir own version, first seen Mar 2, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- 7zrv/claude-code-monitor★ 1same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- landing-syncSkill
- night-digestSkill
- night-runnerSkill
- respond-to-pr-commentsSkill
- test-deck-appSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Run git fetch --prune origin first so the origin/main and unpushed columns are not judged against stale remote-tracking refs.
- Very specific: line 49
Never propose remove for: the primary checkout, a dirty worktree (ignored files included), one with unpushed or unreachable commits, a live …
- Distinctive: line 58
Stop here until the owner replies.
- Distinctive: line 62
Only rows the owner named.
- Distinctive: line 71
If any command fails or times out, stop.
- Distinctive: line 77
Run git worktree prune --dry-run and show its output.
≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Clean worktrees
AGENTS.md sets no cap on live worktrees; this skill
clears the ones made by hand under ../spacevibe-deck-worktrees/. It reports first and removes only what the owner confirms, row by row. Run all
git commands from the primary checkout and read plans there by absolute path.
Step 1: report only
Run git fetch --prune origin first so the origin/main and unpushed columns are not judged
against stale remote-tracking refs. No other git write command in this step. For every
worktree in git worktree list --porcelain, except the primary checkout, collect:
| Column | How |
Path, branch or detached | porcelain output |
| Last commit date | git log -1 --format=%cs <head> |
| Merged | git merge-base --is-ancestor <head> origin/main exits 0, or the tip equals the head.sha of a merged PR (command below). Squash and rebase merges leave the branch off origin/main, so the ancestor test alone misses them. Note "local main only" separately |
| Dirty | the ignored-aware status below prints anything. Ignored files count: git worktree remove deletes them without --force, and .env* and docs/plans/ are ignored here |
| Unpushed | git rev-list <head> --not --remotes is non-empty. A tip that equals a merged PR's head.sha has nothing unpushed |
| Detached, orphaned | git branch -a --contains <head> is empty |
| Live process | lsof -a -d cwd -Fn lines equal to n<path> or starting with n<path>/ (the slash keeps landing from matching landing-standout). Never lsof +D (slow) |
| Recently touched | find <path> -mmin -1440 -not -path '*/node_modules/*' -not -path '*/.git/*' -print -quit prints a file. Agent sessions run from the primary checkout and edit worktrees by absolute path, so the process column cannot see them; this one can |
| Named by a plan | grep -rl the path and the branch name in the primary checkout's docs/plans/ |
# Merged PR for a branch: prints "<number> <head.sha>"; compare with `git rev-parse <branch>`
gh api "repos/mxrsv/spacevibe-deck/pulls?state=closed&head=mxrsv:<branch>" \
--jq '.[] | select(.merged_at) | "\(.number) \(.head.sha)"'
# Dirty, ignored files included; build output at any depth is dropped
git -C <path> status --porcelain --ignored \
| grep -vE '^!! (.*/)?(node_modules|dist|dist-electron|dist-electron-app)/$'Then list local branches that have no worktree, with the merged, unpushed and named-by-a-plan
columns. backup/* branches are left out of the table; report only their count.
Print one table and propose a verdict per row:
remove: merged, clean, nothing unpushed, not orphaned, no live process, not recently touched, not named by a plan.keep (reason): dirty, unpushed, orphaned or a live process — name which.ask: every other case — named by a plan, recently touched, merged into localmainonly.
Never propose remove for: the primary checkout, a dirty worktree (ignored files included), one
with unpushed or unreachable commits, a live process, a recent touch, a plan naming it, or a
backup/* branch.
End the report with two lines:
Not checked:each column that could not be computed, and why.Skill gaps:edits you would make to this skill. Suggest only; do not edit it.
Stop here until the owner replies.
Step 2: remove the confirmed rows
Only rows the owner named. Re-run the merged, dirty, unpushed, process and recently-touched checks on each one first; the state may have changed since the report.
git worktree remove <path>. No--force.git branch -d <branch>. Never-D, with one exception:-drefuses a squash- or rebase-merged branch, so-Dis allowed only when the re-check just showed its tip equals a merged PR'shead.sha(those commits stay on GitHub asrefs/pull/<n>/head); name the PR in the report. Any other refusal: report it and leave the branch.
If any command fails or times out, stop. Report git worktree list and whether the directory
still exists. Do not retry, do not force, do not clean up the half-done state: a timed-out
worktree command is not a rollback (see traps).
After removals
Run git worktree prune --dry-run and show its output. Run git worktree prune only if the
owner agrees. Finish by showing git worktree list and the count against the limit.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

