agentleFS
pabloleonalcaidepabloleonalcaide/development-skills/skills/clean-worktrees/SKILL.md

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

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
  1. Distinctive:

    Analyse (dry run): Run from inside the target repo (the script is global, so use its absolute path):

    line 15
  2. Very specific:

    Confirm: Ask for an explicit OK before deleting.

    line 27
  3. Distinctive:

    After removal it runs git worktree prune to clear stale references.

    line 49
  4. Very specific:

    Never run rm -rf or git worktree remove --force yourself — permissions and the auto-mode classifier block both.

    line 53
  5. Distinctive:

    Before executing, state per worktree whether its local branch will be deleted, as the script's plan reports it — never from memory.

    line 57

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Analyse (dry run). Run from inside the target repo (the script is global, so use its absolute path):
    ~/.claude/skills/clean-worktrees/scripts/worktree-cleanup.sh --plan
    The script auto-detects the repo from the current working directory.
  2. 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.
  3. 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.
  4. Execute once confirmed:
    ~/.claude/skills/clean-worktrees/scripts/worktree-cleanup.sh --execute
  5. 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-cleanup skill's scripts/worktree-cleanup.sh (canonical copy; disk-cleanup covers Docker and caches too).
  • It runs git fetch and compares against origin/<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 to origin/<branch>.
  • REMOVABLE = clean and pushed but PR open/closed/absent: no code is lost, but ask first.
  • Branches are deleted with git branch -d only (never -D) — an unmerged branch is kept even if its worktree was removed.
  • After removal it runs git worktree prune to clear stale references.

Agent rules (not enforced by the script)

  • Never run rm -rf or git worktree remove --force yourself — 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 --plan to 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 branch

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.