Created
October 2, 2026 13:35
-
-
Save felipebernardes/777d497997db2c481245bf90fe789f00 to your computer and use it in GitHub Desktop.
prompt for creating a skill to save disk space by removing unused worktrees
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Create a skill called `cleanup-worktrees` that frees disk space by removing git worktrees and local branches for work that's already finished. | |
| **What "finished" means.** A worktree is finished if any of these is true: | |
| - Its ticket in the issue tracker is done, canceled, or a duplicate. This wins no matter what state the PR is in. | |
| - Its PR was merged or closed. | |
| - Its PR is still open but hasn't been touched in 30+ days. | |
| - It has no PR and no commits or file changes in 30+ days. | |
| **What to keep:** | |
| - A worktree with no PR that has been active in the last 30 days. That's work in progress. | |
| - An open PR updated in the last 30 days. | |
| - Anything locked with `git worktree lock`. | |
| - Anything where a lookup (PR status, ticket status) failed. If it can't be checked, it isn't safe to delete. | |
| **Safety rules. None of these can be skipped:** | |
| 1. Never force-remove. Stash uncommitted work first (`git stash push -u`), then use a plain `git worktree remove` so git refuses anything the stash missed. Ignored files like `node_modules` can go; that's most of the disk being freed. | |
| 2. Only delete a local branch when the remote already has its tip commit (a live remote branch, a PR head, or a commit the remote reports it holds). Whether the branch was merged doesn't matter. Whether the commits are safe on the remote does. | |
| 3. Never touch protected branches (`main`, `master`, release branches, anything configured as long-lived). | |
| 4. Check every worktree git knows about (`git worktree list`), not just the ones in an expected folder. Separately, flag directories that look like worktrees but that git doesn't recognise. | |
| **How it runs:** | |
| - Put the logic in a script, not in the skill text. The skill only calls the script, so the rules can't drift between runs. | |
| - Do a dry run first. Print every worktree under **Remove** or **Keep** with its reason, how many uncommitted files will be stashed, which branches will be deleted, and which finished branches are being kept because their commits aren't on the remote. | |
| - The rules are fixed, so the only question for the user is "proceed?". If the user already asked for a cleanup, treat that as the go-ahead. | |
| - Require an explicit flag for unattended runs. A non-interactive run without the flag reports and removes nothing. | |
| **Final report:** worktrees removed, disk freed, every stash with its recovery command, every deleted branch with a one-line restore (`git branch <name> <sha>`), branches kept as unpushed, and any failure with git's own error message. If anything failed, exit non-zero and say so. Don't report partial success as success. | |
| Add trigger phrases to the skill description, like "clean up worktrees", "remove merged branches", "prune stale worktrees", and "my disk is full of worktrees", so it gets used without anyone having to name it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment