worktree-cleaner
Ce qu’il fait
Ce skill inventorie les worktrees git d'un dépôt, montre ce que contient chacun, et ne supprime que ce que vous approuvez. Il s'adresse aux développeurs dont le projet a accumulé de nombreux worktrees au fil de tâches parallèles.
Quand l’utiliser
- ✓Quand git worktree list est devenu long et que vous voulez faire le ménage.
- ✓Quand votre agent ou un flux parallèle a créé un worktree pour chaque tâche sans jamais les supprimer.
- ✓Quand vous voulez savoir quels worktrees sont fusionnés, périmés ou contiennent encore des travaux non poussés.
Lien du skill
https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/git/worktree-cleaner/SKILL.mdCopiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.
Comment l’utiliser
Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.
Message prêt à coller
Pour Claude Code, Codex ou Cursor : lancez-la dans le dossier du projet et le skill est installé.
Téléchargez le SKILL.md et placez-le dans le dossier de skills de votre agent.
Exemple de demande à votre IA
“Mon dépôt contient des dizaines de worktrees oubliés. Montre-moi lesquels peuvent être supprimés sans risque, et demande-moi avant de supprimer quoi que ce soit.”
5 nouveaux skills par semaine. 1 minute de lecture.
Comment ça marche
L'agent rassemble des preuves pour chaque worktree, comme l'état de fusion, l'état de la demande de fusion et les modifications non validées, recommande ce qu'il faut supprimer, et ne lance les suppressions qu'après votre approbation à chaque étape.
Contenu technique (SKILL.md original)
Texte original de l’auteur, en anglais, directement depuis GitHub.
Worktree Cleaner
Agents and parallel workflows create one git worktree per task, and nobody removes them. This skill finds them, shows the user what each one holds, and removes only what the user approves, checking the result after every step.
The user decides. You gather evidence, recommend, and execute exactly what was approved. Nothing is removed in bulk without the user seeing the list first.
Hard rules
- Ask before every destructive command.
git worktree remove,git worktree prune,git worktree unlockandgit branch -d/-Deach need the user's approval for that worktree or that named group. Approval of one group does not carry to the next. - Never
--forceon work that would be lost. If a worktree has uncommitted changes, untracked files, or commits that exist nowhere else, show the exact files and commits and ask a separate, explicit question ("remove it and lose these changes?"). A general "yes, clean everything" is not that confirmation. - Never touch the main worktree, the worktree you are running in, or a worktree with live processes inside it (another Claude Code session, an editor, a dev server). Report them and move on.
- Never delete a remote branch (
git push --delete,git push origin :branch, API calls). Remote branches are out of scope; mention them in the report if they look stale. - Deleting the local branch is a separate question, asked after the worktree is gone. Removing a worktree never deletes its branch.
- Re-check right before acting. State changes while you talk to the user: re-run the inventory for that one path immediately before removing it, and stop if the verdict got worse.
- Verify after every action and report what you checked. If a check fails, stop and tell the user; do not retry with stronger flags.
Step 1: Inventory (read-only)
Run the bundled script from anywhere inside the repository. It changes nothing; --fetch only runs git fetch --prune so the merged/pushed checks use fresh remote refs. Ask before fetching if the user is offline or on a metered connection; otherwise fetch.
bash "${CLAUDE_SKILL_DIR}/scripts/worktree-inventory.sh" --fetch
If CLAUDE_SKILL_DIR is not set, the script is at .claude/skills/worktree-cleaner/scripts/worktree-inventory.sh (project install) or ~/.claude/skills/worktree-cleaner/scripts/worktree-inventory.sh (user install).
Flags: --path <worktree> reports a single worktree (use it for the re-check in rule 6; it exits 3 with an error when no worktree matches, so a typo never looks like an empty result), --no-gh skips the GitHub CLI PR lookup, --repo <dir> targets another repository. The fetch never prompts for credentials; if it cannot authenticate it reports fetch: FAILED.
It prints a header (default_branch, whether the fetch worked, whether gh and git merge-tree were available) and then one block per worktree. Key fields:
| Field | Meaning |
|---|---|
modified_tracked, untracked_files, changed_paths |
Uncommitted work. git worktree remove refuses these without --force. |
ignored_local_files |
Gitignored files and directories that are not regenerable artifacts (dependencies, build output and caches such as node_modules/, dist/, .venv/ are left out): .env, .dev.vars, local settings, keys, a whole secrets/ directory. git worktree remove deletes ignored files without warning, so these must be shown to the user. |
commits_not_on_any_remote |
Commits reachable from this worktree's HEAD and from no remote-tracking ref. On a branch, removing the worktree keeps them on the branch, but deleting the branch afterwards loses them. On a detached worktree there is no branch: removing it makes them unreachable (the script marks it AT_RISK). |
git_error |
git could not read the worktree (broken .git file, safe.directory ownership, permissions). Nothing else in the block is reliable. |
head_merged_into_default |
HEAD is an ancestor of the default branch (merge or fast-forward). |
content_already_in_default |
Merging HEAD into the default branch would change nothing (git merge-tree). This catches squash and rebase merges, where the commits differ but the content landed. |
pr |
#N STATE url from gh, none, or unknown when gh is not available. |
processes_inside |
Running processes whose working directory is inside the worktree. |
claude_session_hours_ago |
Hours since a Claude Code |
Questions fréquentes
Va-t-il supprimer mon travail ?
Le skill demande votre approbation avant chaque commande destructrice, et pose une question distincte avant de supprimer tout élément contenant des modifications non enregistrées ou des commits non poussés.
Supprime-t-il les branches distantes ?
Non. Le skill considère les branches distantes hors périmètre, même s'il peut mentionner les branches périmées dans son rapport.
Touche-t-il au worktree que j'utilise ?
Non. Il ne touche jamais au worktree principal, à celui dans lequel il s'exécute, ni à aucun worktree contenant des processus actifs.
Détails
Description originale de l’auteur
Inventory the git worktrees of the current repository, classify each one with evidence (merged, PR state, uncommitted or unpushed work, locked, stale, in use by a running session) and remove them one at a time or by group, always asking the user first and verifying every removal. Use when worktrees have piled up (for example one per Claude Code task or thread), when `git worktree list` is long, or when the user asks to clean up, prune or tidy worktrees.
Popularité
- Étoiles GitHub
- 33k
- Position au classement
- #8856
- Licence
- MIT
- Mis à jour
- 02/11/2026
Commentaires
- …
Autres skills de ce dépôt
owasp-security
33kApprend à votre agent les recommandations de sécurité OWASP pour les applications web, les API, le mobile, les conteneurs et les agents d'IA, afin qu'il repère les faiblesses courantes et propose des correctifs.
agent-management
33kPermet à votre agent de créer, lister, mettre en veille, réveiller, renommer et supprimer des agents d'IA à l'aide de l'outil en ligne de commande AI Maestro, en gérant le cycle de vie de chaque agent.
agent-messaging
33kPermet à votre agent d'envoyer, de recevoir et de répondre à des messages signés entre agents d'IA, grâce au protocole Agent Messaging, principalement sur votre propre machine.
docs-search
33kPermet à votre agent de rechercher dans la documentation de code générée automatiquement les signatures de fonctions, les définitions de classes et les commentaires, pour vérifier la véritable API avant de modifier le code.
Skills similaires
openclaw-update
394kAide votre agent à mettre à jour une passerelle OpenClaw existante, en choisissant la méthode adaptée à son installation et en gardant votre session active.
diagnose-gateway
394kAide votre agent à trouver pourquoi votre passerelle OpenClaw échoue, en vérifiant les paramètres, les canaux et les ports sans rien modifier.
crabbox-apps
394kAide votre agent à ouvrir et exécuter une application sur une machine cloud temporaire, puis à afficher sa vue dans le panneau latéral de votre chat.