Agent Skills
› perber/leafwiki
› worktree-cleanup
worktree-cleanup
GitHub列出并清理 Git worktree,展示分支状态(合并、PR、变更等),仅在用户确认后删除已完成或过期的工作树,防止误删。
Trigger Scenarios
PR 已合并后
用户说 'clean up the worktrees'
Install
npx skills add perber/leafwiki --skill worktree-cleanup -g -y
SKILL.md
Frontmatter
{
"name": "worktree-cleanup",
"description": "List this repository's git worktrees with their branch state (merged, PR open, uncommitted changes, age) and remove the ones that are done — only after the person confirms. Use after a PR is merged, or when the person says \"clean up the worktrees\"."
}
Worktree cleanup
Agent work creates one worktree per branch; they pile up. Never delete anything without showing the list and getting an explicit OK.
1. Collect
git fetch -q --prune origin
git worktree list --porcelain
For every worktree except the main checkout, determine:
- branch (or detached HEAD) and last commit date (
git -C <path> log -1 --format=%cr), - uncommitted changes:
git -C <path> status --porcelain(count tracked + untracked), - merged:
git branch --merged origin/maincontains the branch, orgh pr list --state merged --head <branch>finds a merged PR (squash merges don't show up as merged in git), - open PR:
gh pr list --state open --head <branch>, - prunable: marked
prunableby git (directory already gone).
2. Propose
Show a table grouped as:
- Safe to remove — merged (or PR merged), no uncommitted changes.
- Probably done — no open PR, last commit older than 30 days, no uncommitted changes.
- Keep — open PR, uncommitted changes, or recent work. List why.
3. Remove (after OK, per group or per entry)
git worktree remove <path> # refuses if there are uncommitted changes — good
git branch -d <branch> # only for merged branches; -D only if the person says so
git worktree prune
Never use --force on a worktree with uncommitted changes unless the person explicitly asked
for that specific one. Report what was removed and what was kept.
Version History
- 8c5843f Current 2026-10-19 00:23


