worktree-janitor
Skill4 starsChanged 25 days agoMITView on GitHub
Sweep .claude/worktrees/ across every repo in the workspace — list each worktree's branch, dirtiness, age, and merge state; remove the safe ones, flag the rest. Use when the user says "/worktree-janitor", "clean up worktrees", or a checkout fails with "already used by worktree".
1 other project uses a version of this.
Adopted by
Most recently taken up by
- ritmillio/skillstheir own version, first seen Aug 23, 2026
Other versions1 project uses a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 1
- ritmillio/skills★ 0same 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 repository8 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- babysit-prSkill
- babysit-ticketSkill
- babysit-worktreeSkill
- kill-worktreeSkill
- masterdeck-notesSkill
- masterSkill
- queueSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 61
Never worktree remove --force on a DIRTY row without the user naming it explicitly.
- Distinctive: line 62
Never delete branches — this skill removes worktree *directories* only.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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
worktree-janitor — sweep stale Claude worktrees
Goal: reclaim disk and unblock branch checkouts by removing worktrees that are safe to remove, while never deleting work. Report-then-delete, not delete-then-apologize.
Steps
1. Inventory
Find every repo with worktrees under the configured workspace (workspace in
~/.claude/master/config.json) — the workspace root itself, if it is a repo, plus the
repos directly inside it:
ws=$(~/.claude/skills/master/master config get workspace)
# A workspace that is itself a repo sits next to its sibling repos: sweep the folder around it.
root="$ws"; [ -e "$ws/.git" ] && root=$(dirname "$ws")
for r in "$root"/*/.git "$root"/.git; do
[ -e "$r" ] || continue
repo=$(dirname "$r")
[ -d "$repo/.claude/worktrees" ] && echo "== $repo" && git -C "$repo" worktree list
doneFor each worktree collect, via git -C <wt>:
- branch (
branch --show-current; empty = detached HEAD) - dirty? (
status --porcelainnon-empty, untracked included) - age (last commit date,
log -1 --format=%cr) - merged? (
git -C <repo> branch --merged <default-branch>contains it, orgh pr list --head <branch> --state mergedshows its PR merged) - pushed? (
git -C <repo> ls-remote --heads origin <branch>non-empty)
2. Classify
| Class | Criteria | Action |
| SAFE | clean AND (branch merged into default, or detached with no unique commits) | remove |
| PUSHED | clean, unmerged, but branch exists on origin | remove worktree, branch survives locally + remotely — say so |
| DIRTY | uncommitted changes | never auto-remove — list files, offer kill-worktree-style rescue (stash → remove → checkout in main repo) |
| UNPUSHED | clean but has commits on no remote and not merged | flag with commit list; remove only on explicit per-item approval |
Detached-HEAD worktrees (e.g. random-named session leftovers): check
git log --oneline <sha> --not --branches — empty means every commit is reachable
from a branch → SAFE; non-empty means orphaned commits → UNPUSHED class.
3. Report first
Print the classification table (repo, worktree, branch, class, reason) BEFORE removing anything. Then:
git -C <repo> worktree remove <path> # SAFE + PUSHED rows
git -C <repo> worktree pruneNever worktree remove --force on a DIRTY row without the user naming it explicitly.
Never delete branches — this skill removes worktree directories only; branch
cleanup is a separate ask.
4. Summary
Removed / kept / needs-decision counts per repo, disk freed if easily available
(du -sh before/after is optional, skip if slow), and the exact command for any
row left for the user.
Rules
- A worktree currently in use by a live Claude session may refuse removal or break that session — if a removal errors with "is locked" or the user says a session is active there, skip it.
- The workspace root repo (if the workspace folder is itself a git repo) gets swept too, not just the repos inside it.
- One-shot skill: no monitor, no schedule. For recurring hygiene, wrap it in a
/loopor a scheduled routine explicitly.
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.

