agentsclimarketplace

Worktree cleanup

Skill Enverge-Labs/skills/skills/worktree-cleanup

Agent skills for Claude Code and other coding agents

Install
npx -y skills add Enverge-Labs/skills --skill worktree-cleanup

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Tear down a finished task's git worktree and branch once its PR is merged or closed. Use when a task is done, a PR was merged/closed, or the user asks to clean up / remove / prune worktrees or stale branches. Companion to the `worktree-new` skill; applies to whatever repository Claude is currently in.

SKILL.md

2.5 KB, 597 tokens by cl100k_base, as published. Nobody here has run it

Worktree cleanup

Remove worktrees and branches whose PR is merged or closed. Destructive — never discard uncommitted or unpushed work.

Find the repo

ROOT="$(git rev-parse --show-toplevel)" || { echo "not a git repo"; exit 1; }

If $ROOT/WORKTREES.md exists, follow its naming/location — the repo's doc is the source of truth. Defaults below: worktrees under .claude/worktrees/<slug>/, branches worktree-<slug>.

Decide what's done

List worktrees and check each branch's PR state (MERGED / CLOSED / OPEN, or no PR):

git -C "$ROOT" fetch --prune origin
git -C "$ROOT" worktree list --porcelain          # path + branch per worktree

# per candidate branch:
gh pr view "$BRANCH" --json state,url --jq '"\(.state)\t\(.url)"'   # no PR ⇒ non-zero exit

A worktree is a cleanup candidate only if its PR is MERGED or CLOSED. Leave OPEN and no-PR worktrees alone.

Verify it's safe (per candidate)

Before removing, confirm nothing would be lost — skip and report any that fail:

git -C "$WORKTREE" status --porcelain            # must be empty (no uncommitted/untracked)
git -C "$WORKTREE" log --oneline "@{u}.." 2>/dev/null   # must be empty (no unpushed commits)
  • Dirty or unpushed → stop, show the user, do not --force.
  • Present the full candidate list and get a go-ahead before deleting.

Remove

Run from $ROOT (never from inside the worktree you're removing):

git -C "$ROOT" worktree remove ".claude/worktrees/${SLUG}"   # refuses if dirty — that guard is intentional
git -C "$ROOT" branch -d "worktree-${SLUG}" \
  || git -C "$ROOT" branch -D "worktree-${SLUG}"             # -D only after PR confirmed MERGED/CLOSED (squash-merge leaves -d "not fully merged")
git -C "$ROOT" worktree prune

Notes

  • Squash/rebase merges make git branch -d report "not fully merged"; the -D fallback is safe because the PR state is already confirmed merged/closed — not as a blanket habit.
  • Never delete the main checkout or its default branch.
  • Unreachable ≠ deletable: a failed gh call (network/auth) is not a closed PR. Confirm state before removing.

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Gives 0 of the 12 instructions most pr commit review skills give in 597 tokens

Counted across 888 of the 1,342 authors here whose files we hold, read 2026-08-07

  • Use conventional commits formatin 127 of 888, across 115 files
  • Keep subject line under 72 charactersin 62 of 888, across 48 files
  • Delete branches after mergein 51 of 888, across 38 files
  • Use imperative mood in subject linein 51 of 888, across 42 files
  • Use imperative mood in commit messagesin 44 of 888
  • Verify directory is ignored before creating worktreein 43 of 888, across 12 files
  • Generate a conventional commit messagein 43 of 888
  • Add unignored worktree directories to gitignorein 42 of 888, across 10 files
  • Make atomic commitsin 39 of 888, across 27 files
  • Run tests before committingin 36 of 888, across 25 files
  • Verify clean test baselinein 35 of 888, across 9 files
  • Split unrelated changes into separate commitsin 35 of 888, across 30 files

Said here and by no other author read

  • follow WORKTREES.md if it exists
  • list all worktrees and check PR state
  • prune worktrees after removal

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.