/colin-shipping:colin-git-cleanupfrom colin-shipping
Cleans up stale local git branches and worktrees using a mechanical scanner. Prefers worktrunk for squash-aware removal and cross-checks Paseo agent workspaces.
Ships in colin-shipping. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description, though model invocation is off: only you can start it.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Gather the current state first. Run these in a single tool-turn batch:
git branch --show-current
git remote show origin | grep 'HEAD branch' | awk '{print $NF}'
git branch --list | wc -l
git worktree list | wc -l
command -v wt >/dev/null && echo "worktrunk: yes" || echo "worktrunk: no"
command -v paseo >/dev/null && echo "paseo: yes" || echo "paseo: no"
command -v git-cleanup-scan >/dev/null && echo "scan: PATH" \
|| { test -x "${CLAUDE_SKILL_DIR}/scripts/git-cleanup-scan" && echo "scan: skill-scripts" || echo "scan: missing"; }
Help the user clean up stale local branches and, when useful, stale worktrees. Prefer worktrunk (wt) over raw git when it is installed — it understands squash merges and can remove worktree + branch together.
Prefer the mechanical scanner over hand-rolled inventory. Run git-cleanup-scan first, before any free-form git branch / git worktree archaeology (see Step 1). It fetches, lists branches/worktrees, attaches live /proc/*/cwd holders, runs cheap integration + optional wt step prune --dry-run, and emits JSON categories (protect / auto_delete / keep / ask) plus blanket_wt_prune_safe. When paseo is on PATH, immediately follow with paseo ls -g --json and strip any active agent workspaces from the delete set (Step 2). You still present the plan, handle ambiguous ask leftovers (deep patch-id / MR corroboration), get confirmation, and execute.
Hard rule: Do not invent inventory scripts or re-derive cwd-holder loops in the session. If the scanner is missing, install from scripts/git-cleanup-scan beside this SKILL.md (or ~/.local/bin/git-cleanup-scan) and only then continue. Hand-rolled inventory is a last resort when the scanner itself fails.
These are the usual defaults from real cleanup sessions. Override only when $ARGUMENTS or the user says otherwise.
master, main, or the current branch.git branch -D alone — use wt remove (or remove the worktree first).cwd (agents, shells, MCP servers, etc.) — even if content is integrated into the default branch. Same-commit-as-main is irrelevant while agents still hold the tree.cwd of an active Paseo agent (see Paseo cross-check below). /proc may miss agents the daemon still owns.release/* worktrees/branches unless the user explicitly asks to remove a specific release line.[gone] (remote branch deleted). Safe; usually squash-merged MRs.git switch <branch> / re-fetch later. This is the main "thin the local branch list" cleanup.wt remove -y (add -f if dirty, -D if git still thinks unmerged).backup/* restack snapshots, open bugfix stacks).glab mr list --source-branch <branch>.Many repos use master as origin HEAD (not main). Detect via remote HEAD; do not assume main. Some worktrees (e.g. knowledge-base) track a different remote (kb-remote); do not judge those against origin/master.
Do not treat "tracked and 0 ahead of feature remote" as "merged to master" — that only means the local ref matches origin/feature. Still safe to delete locally because the remote copy remains.
When wt is available:
wt step prune --dry-run (add --min-age=0s to include young worktrees) previews integrated worktrees and branch-only refs.wt step prune -y --foreground bulk-removes safe candidates — only after excluding worktrees that fail the active-cwd test or the Paseo agent cross-check below. If any prune candidate has live cwd users or an active Paseo agent, do not run blanket prune; delete branch-only refs with git branch -D and leave the busy worktree alone.wt list / wt list --branches shows _ (same commit) and ⊂ (content integrated).wt remove [-f] [-D] -y --foreground <branch-or-path> for targeted worktree+branch removal (after cwd test and Paseo cross-check are clean).Worktrunk's six checks (cheapest first): same commit → ancestor → empty 3-dot → trees match → merge-adds-nothing → patch-id match.
Integration alone is not enough to remove a worktree. Paseo / Claude / other agents often sit on a worktree whose branch already matches main (same commit). Removing it mid-session kills the agent.
For every worktree path that is a prune/wt remove candidate (everything except the primary checkout you are running from, if it is main/master):
# Quick scan (human-readable)
ls -la /proc/*/cwd 2>/dev/null | grep -F '<worktree-path>'
# Enumerate holders with PID + command
for p in /proc/[0-9]*; do
cwd=$(readlink "$p/cwd" 2>/dev/null) || continue
case "$cwd" in
<worktree-path>|<worktree-path>/*)
pid=${p#/proc/}
cmd=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null | head -c 200)
echo "pid=$pid cwd=$cwd cmd=$cmd"
;;
esac
done
claude, ssrag-mcp, node, a long-lived shell) → keep that worktree + its branch. Report PIDs/commands in the summary. Do not call wt remove / include it in wt step prune.Example from a real session: durable-anti-flap @ same commit as main, wt step prune wanted it gone, but /proc/*/cwd showed live claude + ssrag-mcp under ~/.paseo/worktrees/.../upbeat-elephant. Correct verdict: keep worktree; only delete other integrated branch-only refs.
paseo is on PATH)/proc/*/cwd alone is not enough for Paseo: the daemon tracks agents (running and idle) whose workspace must stay until the agent is archived/closed. If paseo is available, always inventory agents and exclude their workspaces from deletion — even when the scanner marks the worktree idle/integrated.
Skip this section only when command -v paseo fails (CLI not installed). Do not invent alternate Paseo APIs; use the CLI.
# Prefer JSON; -g so agents outside the current cwd still protect this repo's worktrees
paseo ls -g --json
# Optional: human-readable companion
paseo ls -g
Default paseo ls already excludes archived agents. Treat each entry as:
| Field | Use |
|---|---|
cwd | Workspace path (often ~/.paseo/worktrees/<slug>/<animal> or a repo worktree). Expand ~ → $HOME before matching. |
status | Protect when not closed (at least running and idle). closed may still have leftover dirs — still protect if /proc shows holders; otherwise integration rules may apply. |
shortId / name | Report in the keep list so the user can identify which agent owns the tree. |
Cross-reference before any worktree remove / blanket prune:
closed agent cwd (realpath if the path exists; otherwise expanded tilde form).cwd path basename matches a Paseo animal worktree basename under ~/.paseo/worktrees/ that maps to a candidate — prefer path equality over basename when possible.git branch -D with no worktree) are unaffected.blanket_wt_prune_safe=false: never run blanket wt step prune -y; only delete idle, non-Paseo targets explicitly.paseo ls -g --json immediately before execute — agents can start between inventory and confirmation.Example: scan says ugly-gopher is integrated and idle on disk, but paseo ls shows status: running, cwd: ~/.paseo/worktrees/.../ugly-gopher. Correct verdict: keep worktree; do not wt remove / prune it.
If paseo ls fails (daemon down), say so, fall back to the /proc active-cwd test, and do not bulk-remove paths under ~/.paseo/worktrees/ without user confirmation.
Against origin/<default> (call it D):
git rev-parse branch == git rev-parse Dgit merge-base --is-ancestor branch Dgit diff --numstat D...branch is emptybranch^{tree} == D^{tree}git merge-tree --write-tree D branch equals D^{tree} (non-zero exit ⇒ conflicts)If any of 1–5 succeed → integrated → delete.
Cheap checks false-negative on a common case: the feature was squash/cherry-picked onto D under a new commit SHA, then D kept evolving the same files. The local tip still shows a non-empty 3-dot diff and is not an ancestor — but the patch is already in history.
Example from a real session: local auto-worktree-init @ 5f87f822a9 vs master 0f18649633 — same subject, identical git patch-id --stable, five minutes apart. 3-dot still dirty because shell/env.sh moved on after the merge. Correct verdict: delete.
Run deep checks on every remaining non-worktree candidate before declaring "keep":
git cherry (per-commit patch-id equivalence)git cherry -v origin/<default> <branch>
- → that commit's patch is already on D+ → not found on DDelete if every listed commit is - (or the only + commits produce empty patches / are empty merges).
Note: squash-of-many → one commit on D often leaves all local commits as +. Then use B/C.
# local tip patch-id
git show <branch> --format= -- | git patch-id --stable
# candidates on default: same subject and/or same files
git log D --pretty=%H --grep='<subject without Refs…>' -i -40
git log D -200 --pretty=%H -- <files from the tip>
# for each candidate: git show <sha> --format= -- | git patch-id --stable
Delete if tip patch-id equals any commit on D.
Use binary-safe pipes (subprocess binary mode or shell pipes). Do not decode huge diffs as UTF-8 (binary blobs will crash a text-mode runner).
git diff D...<branch> | git patch-id --stable
Compare that id to single commits on D (subject/file candidates, same as B).
Delete if the combined range matches a squash commit on D.
git log D --oneline --grep='…' for the tip subjectglab mr list --source-branch <branch> --all -F json → state=mergedUse as evidence in the summary; only delete when A/B/C (or cheap checks / wt) confirm.
backup/* restack snapshots often contain large unique histories that later landed via different squash series — cherry may show dozens of + even when the product work is on master. Prefer user confirmation or comparing the feature tip that was actually merged, not the whole backup._SC-*) may look "ahead" with unique commits after intermediate squash merges; user may force-delete by name after confirming the stack shipped.| Result | Action |
|---|---|
| Cheap integrated | Auto-delete |
git cherry all - | Auto-delete |
Tip or range patch-id matches D | Auto-delete |
Unique + commits with no patch-id hit | Keep (or ask) |
| User names a stack as squash-merged | Force-delete those names |
git-cleanup-scan (required)Resolve the binary (first hit wins):
SCAN=$(command -v git-cleanup-scan || echo "${CLAUDE_SKILL_DIR}/scripts/git-cleanup-scan")
test -x "$SCAN"
Then from the repo root:
"$SCAN" # JSON (default); includes fetch --prune
"$SCAN" --text # human table for the user-facing summary
"$SCAN" --deep # also run git cherry on non-integrated leftovers
"$SCAN" --no-fetch # offline re-scan
Trust summary.* and per-branch category / reasons / delete_via / worktree_busy as the inventory source of truth. Do not re-derive cwd holders or cheap integration by hand unless the helper is missing.
If the helper is missing, fall back to the manual inventory + Active-cwd test below (and tell the user the skill scripts are not installed — ./install.sh --agents from colin-dotfiles).
| Field | Meaning |
|---|---|
summary.auto_delete_branch_only | Safe git branch -D candidates |
summary.auto_delete_worktree | Idle integrated worktrees → wt remove (still filter through Paseo cross-check) |
summary.keep | Includes live-cwd worktrees — never auto-remove |
summary.ask | Need deep checks / human judgment |
summary.protect | main/master/current/release/* |
summary.blanket_wt_prune_safe | If false, never run blanket wt step prune (also force false when Paseo owns a candidate) |
summary.recommended_actions | Suggested commands after confirm (still confirm first; drop Paseo-owned paths) |
summary.notes | Busy worktree warnings with PIDs |
Right after the scan (and before presenting the plan), if paseo is on PATH:
paseo ls -g --json
Cross-reference every non-closed agent cwd against scan auto-delete worktrees and any wt step prune candidates (see Paseo agent workspace cross-check above). Promote matching worktrees from auto-delete → keep, and force blanket_wt_prune_safe=false for the plan when any such match exists.
If paseo is missing, skip this step and rely on /proc + scan only.
Only when needed for ask leftovers or user questions:
glab mr list --source-branch <branch> --all -F json (merged vs open)--deep or cherry was inconclusivewt remove (agents can start after scan)paseo ls -g --json if the first inventory is stale| # | Category | Typical action |
|---|---|---|
| 1 | Gone (upstream deleted) | Auto-delete |
| 2 | Tracked, 0 ahead of live upstream | Auto-delete (re-checkout anytime) |
| 3 | Tracked, ahead of upstream | Ask (default keep) |
| 4 | Untracked — cheap or deep integrated | Auto-delete |
| 5 | Untracked — still unique after deep checks | Ask (default keep) |
| 6 | Worktree, idle (no live cwd, not a Paseo agent cwd) | Skip git branch -D; manage with wt remove / prune |
| 7 | Worktree, live agents (cwd holders and/or active Paseo) | Keep; never auto-remove |
| 8 | release/* | Keep unless user asks |
Show counts per category, planned auto-deletes, and keep-lists with why (from scan reasons, Paseo agent shortId/status when applicable, plus any deep-check notes). Tables beat walls of text. Include busy worktree PID/cmd from scan and Paseo-owned paths when present.
summary.recommended_actions after confirm — or equivalent git branch -D / wt remove commands. Squash merges will not show as --merged; use -D.blanket_wt_prune_safe is false (scan or Paseo cross-check), never run wt step prune -y; only branch-only deletes and explicit idle, non-Paseo wt remove targets."$SCAN" --no-fetch (or cwd test) and paseo ls -g --json (when available) right before removing a worktree.git branch -vv, worktree list, and counts removed.git-cleanup-scan # primary inventory (JSON)
"$SCAN" --text # human table
"$SCAN" --deep # + git cherry on leftovers
paseo ls -g --json # active (non-archived) agents + cwd — cross-ref before delete
paseo ls -g # human table
# optional: paseo worktree ls --json # Paseo-managed worktrees only
wt list # worktree status
wt step prune --dry-run # preview (scan already incorporates this)
wt step prune --dry-run --min-age=0s
wt step prune -y --foreground # ONLY if scan.summary.blanket_wt_prune_safe AND no Paseo-owned candidates
wt remove -y feature # remove one WT; delete branch if integrated
wt remove -y -f -D feature # dirty WT + force-delete unmerged branch
wt remove -y -f /path/to/detached # path for detached HEAD worktrees
# per-commit equivalence to default branch
git cherry -v origin/master BRANCH
# tip patch-id
git show BRANCH --format= -- | git patch-id --stable
# whole-branch (3-dot) patch-id — compares to a single squash on master
git diff origin/master...BRANCH | git patch-id --stable
# find same subject on master
git log origin/master --oneline --grep='first line of subject' -i
git branch -d often fails on squash-merged branches — use -D.wt remove may leave trash under .git/wt/trash/ (auto-swept ~24h); prefer --foreground when you want a definitive finish.wt step prune alone for worktrees — it does not know about live agents. git-cleanup-scan attaches cwd holders and sets blanket_wt_prune_safe=false when busy; honor that. If the helper is missing, run the /proc/*/cwd test by hand.paseo ls -g --json and cross-reference agent cwds before deleting worktrees.scripts/git-cleanup-scan beside this SKILL.md and is installed to ~/.local/bin/git-cleanup-scan by install.sh --agents.$ARGUMENTS
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
git-cleanup, branch-management, worktree-cleanup, squash-merge
Other plugins' skills for the same job
npx claudepluginhub colinmollenhour/dotfiles --plugin colin-shipping34 skills in this plugin
/cclsp-fix-diagnosticsScan a codebase with the CCLSP MCP and fix reported diagnostics. Language- and project-agnostic. Use for "fix all the LSP errors", "check the workspace for errors", "fix diagnostics in <path>", or auditing a branch/PR/commit range for new errors. Default scope is the whole codebase, chunked. User can narrow to files, folders, commits, ranges, branches, PRs, or MRs./clickup-task-authoringAuthor a ClickUp task from a conversation, plan, review, incident, or spec as CUFM via cup task-sync. Covers the source-fidelity ledger, the house voice for task copy (plain verbs, declarative mood, paragraphs over lists, 5% length budget), rich description structure (banners, toggles, mermaid, tldraw, tables), open-decision blocks (question, AI Recommendation, two alternatives), title conventions, workspace Value Stream / Requested By / Bug-type rules, and the post-write audit. Use when creating or updating ClickUp task content (file a bug, write a ticket, turn this into a task). Load the clickup skill from `cup skill` for CUFM syntax and task-sync flags. Workspace IDs come from `cup` or a project ClickUp skill. Formerly clickup-tasks./cli-designDesign, implement, or review CLI UX: args, flags, help, output, errors, config, interactivity, and distribution.