ワンクリックで
cleanup
Remove worktrees and local branches whose pull request has been merged or closed.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
Remove worktrees and local branches whose pull request has been merged or closed.
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Research a work item, draft an implementation plan, and begin work after approval.
Guided one-shot install — discover installed plugins (or help install new ones), pick install scope, calibrate risk tolerance into a concrete allowlist + hooks, scaffold or merge CLAUDE.md, and sanity-check the result.
Finalize work — commit via /commit, push, and create PRs on feature branches.
Reviewer-side PR workflow — checks out the branch in a worktree, runs focus-area reviews plus a senior-engineering pass, optionally cross-checks against an autonomous reviewer, and posts inline findings only on explicit approval. Read-only — never edits, commits, or pushes.
Fetch PR review comments, classify by severity and confidence, and fix the selected subset.
Triage CVE and SBOM scanner output (Trivy, Grype, Snyk, Docker Scout, Dependabot) into a ranked, deduplicated action list.
| name | cleanup |
| description | Remove worktrees and local branches whose pull request has been merged or closed. |
| user-invocable | true |
| disable-model-invocation | true |
| allowed-tools | Bash |
Clean up local worktrees and branches whose pull request has been merged or closed on GitHub.
This is a user-invoked, full-repo sweep. It is safe to run from inside a worktree — every removal runs from the main working tree.
/cleanup
No arguments. The skill determines what is safe to remove automatically.
A branch with zero commits ahead of origin/main is not necessarily
finished work. A freshly created worktree branched from origin/main is
graph-identical to a fully merged branch — both have nothing ahead of
origin/main. Judging "done" by the commit graph (git branch --merged)
therefore destroys brand-new, in-progress worktrees that parallel sessions are
actively using.
Instead, a worktree counts as finished only when GitHub reports a merged or closed PR for its branch. No PR → not finished → keep it.
origin/main so PR/branch state is currentgit worktree prune)# 1. Fetch latest state from origin
git fetch origin main
# 2. Resolve the main working tree — the first entry of `git worktree list`.
# Running removals from here makes removing the *current* worktree safe.
MAIN_TREE=$(git worktree list --porcelain | awk '/^worktree /{print $2; exit}')
# 3. Iterate every worktree except the main tree
git worktree list --porcelain | awk '/^worktree /{print $2}' | while read -r WT; do
[ "$WT" = "$MAIN_TREE" ] && continue
BRANCH=$(git -C "$WT" rev-parse --abbrev-ref HEAD)
# Finished work only — a merged or closed PR must exist for this branch.
MERGED=$(gh pr list --head "$BRANCH" --state merged --json number --jq 'length')
CLOSED=$(gh pr list --head "$BRANCH" --state closed --json number --jq 'length')
if [ "${MERGED:-0}" -eq 0 ] && [ "${CLOSED:-0}" -eq 0 ]; then
echo "KEEP $WT ($BRANCH) -- no merged or closed PR"
continue
fi
# Never discard uncommitted or untracked work.
if [ -n "$(git -C "$WT" status --porcelain)" ]; then
echo "KEEP $WT ($BRANCH) -- uncommitted or untracked changes"
continue
fi
# Remove from the main tree so removing the current worktree is safe.
if git -C "$MAIN_TREE" worktree remove "$WT"; then
git -C "$MAIN_TREE" branch -d "$BRANCH" 2>/dev/null \
&& echo "REMOVED $WT ($BRANCH) -- worktree + branch" \
|| echo "REMOVED $WT ($BRANCH) -- worktree only (branch not safe to delete)"
else
echo "KEEP $WT ($BRANCH) -- worktree remove failed"
fi
done
# 4. Prune any stale worktree references
git -C "$MAIN_TREE" worktree prune
Report the output to the user: which worktrees were removed, which were kept (and why), and the final state.
git branch -d (safe delete), never
-D; a branch that is not safe to delete is reported and left in place