Agent Skills › perber/leafwiki › worktree-cleanup

worktree-cleanup

GitHub

列出并清理 Git worktree,展示分支状态(合并、PR、变更等),仅在用户确认后删除已完成或过期的工作树,防止误删。

.claude/skills/worktree-cleanup/SKILL.md perber/leafwiki

Trigger Scenarios

PR 已合并后 用户说 'clean up the worktrees'

Install

npx skills add perber/leafwiki --skill worktree-cleanup -g -y
More Options

Non-standard path

npx skills add https://github.com/perber/leafwiki/tree/main/.claude/skills/worktree-cleanup -g -y

Use without installing

npx skills use perber/leafwiki@worktree-cleanup

指定 Agent (Claude Code)

npx skills add perber/leafwiki --skill worktree-cleanup -a claude-code -g -y

安装 repo 全部 skill

npx skills add perber/leafwiki --all -g -y

预览 repo 内 skill

npx skills add perber/leafwiki --list

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/main contains the branch, or gh 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 prunable by git (directory already gone).

2. Propose

Show a table grouped as:

  1. Safe to remove — merged (or PR merged), no uncommitted changes.
  2. Probably done — no open PR, last commit older than 30 days, no uncommitted changes.
  3. 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

Same Skill Collection

.claude/skills/develop/SKILL.md
.claude/skills/run/SKILL.md
.claude/skills/tidy-tests/SKILL.md
.claude/skills/docs-review/SKILL.md

Metadata

Files
0
Version
8c5843f
Hash
271e6832
Indexed
2026-10-19 00:23

Главная - Вики-сайт
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-19 17:45
浙ICP备14020137号-1