clean-worktrees
Skill1 starsChanged 41 days agoMITView on GitHub
Clean up git worktrees on the local machine — remove worktrees that are clean and fully merged, delete their merged branches, and skip anything with pending work. Use when the user wants to clean, remove, prune, or tidy up git worktrees, mentions "limpia los worktrees", "elimina worktrees", "clean up worktrees", or asks to get rid of leftover worktree directories.
- Deletes or force-pushes
2 other projects use a version of this.
Adopted by
Most recently taken up by
- mxrsv/spacevibe-decktheir own version, first seen Nov 1, 2026
- 7zrv/claude-code-monitortheir own version, first seen Mar 2, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- mxrsv/spacevibe-deck★ 41same name
- 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 repository20 other files it gives its agents.
- api-designSkill
- create-prSkill
- deprecationSkill
- developSkill
- diagnoseSkill
- disk-cleanupSkill
- domain-modelingSkill
- grillingSkill
- grill-meSkill
- grill-with-docsSkill
- handoffSkill
- observabilitySkill
- prototypeSkill
- receiving-code-reviewSkill
- security-hardeningSkill
- setupSkill
- tddSkill
- to-specSkill
- to-ticketsSkill
- write-a-skillSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
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
- could be automatic: a setting could enforce it
- Distinctive: line 15
Analyse (dry run): Run from inside the target repo (the script is global, so use its absolute path):
- Very specific: line 27
Confirm: Ask for an explicit OK before deleting.
- Distinctive: line 49
After removal it runs git worktree prune to clear stale references.
- Very specific: line 53
Never run rm -rf or git worktree remove --force yourself — permissions and the auto-mode classifier block both.
- Distinctive: line 57
Before executing, state per worktree whether its local branch will be deleted, as the script's plan reports it — never from memory.
≈ “Common” is an estimate: at least 1 in 5 of the 372,429 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
Safely removes throwaway git worktrees from the local repo. Only touches worktrees that are clean and fully integrated; anything with uncommitted changes, unmerged commits, a detached HEAD, or a lock is skipped and reported so the user decides manually. Always shows a plan and gets confirmation before deleting.
Workflow
- Analyse (dry run). Run from inside the target repo (the script is global, so use
its absolute path):
The script auto-detects the repo from the current working directory.~/.claude/skills/clean-worktrees/scripts/worktree-cleanup.sh --plan - Present the plan to the user in Spanish, in the script's three groups: SAFE (removed
by
--execute), REMOVABLE (open/closed PR or no PR, but clean and pushed — offer each one individually) and SKIP, each with its reason. Do not paraphrase away the reasons — the user needs them to decide. - Confirm. Ask for an explicit OK before deleting. If the user only wants a subset,
use
worktree-cleanup.sh --remove <path>per item rather than--execute, which acts on all SAFE entries. - Execute once confirmed:
~/.claude/skills/clean-worktrees/scripts/worktree-cleanup.sh --execute - Report what was removed and what remains.
Rules (baked into the script)
- The main worktree is never touched.
- The script delegates to the sibling
disk-cleanupskill'sscripts/worktree-cleanup.sh(canonical copy; disk-cleanup covers Docker and caches too). - It runs
git fetchand compares againstorigin/<default>, never the local default branch. - SAFE = not main, not locked, not detached, clean, and either contained in
origin/<default>or its PR is MERGED (squash) with the branch tip equal toorigin/<branch>. - REMOVABLE = clean and pushed but PR open/closed/absent: no code is lost, but ask first.
- Branches are deleted with
git branch -donly (never-D) — an unmerged branch is kept even if its worktree was removed. - After removal it runs
git worktree pruneto clear stale references.
Agent rules (not enforced by the script)
- Never run
rm -rforgit worktree remove --forceyourself — permissions and the auto-mode classifier block both. When a directory survives removal ("Directory not empty") or a worktree needs a forced removal, list the exact command and ask the user to run it with! <command>; then re-run--planto confirm. - Before executing, state per worktree whether its local branch will be deleted, as the script's plan reports it — never from memory.
Manual commands (for a subset or edge cases)
git worktree list # inspect
worktree-cleanup.sh --remove <path> # remove one, only if clean and pushed
git worktree remove --force <path> # user-only (`! …`): remove one WITH pending changes (data loss)
git worktree unlock <path> # unlock a locked worktree first
git branch -d <branch> # delete its merged branchDoes 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.

