/git-clean-gone:git-clean-gone [--dry-run] [--no-worktrees]from git-clean-gone
Cleans up local branches with deleted remote tracking and their worktrees. Detects squash-merged and rebased branches after PR merges, with dry-run and worktree options.
Ships in git-clean-gone. 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.
Delete local branches whose remote tracking is gone or merged, and remove their associated worktrees.
Paths in this file are relative to the skill directory (the one holding this SKILL.md). The workflow is written for Claude Code; on other agents, or when a Claude feature is missing, use these fallbacks:
| Claude Code feature | Fallback |
|---|---|
| Argument substitution | If the "Parse from" line under Arguments shows no value or an unreplaced placeholder, take the flags from the user's request |
| Skill directory substitution | If the script path under Constraints is not an absolute path, run bash <absolute skill directory>/scripts/clean-gone.sh without changing directory. The script acts on the repository in the current working directory, so that must stay the user's repository, never the skill directory |
| Preprocessed context | If the values under Preprocessed context are unexpanded commands, ignore them: the script detects the remote, default branch and gh itself |
disable-model-invocation | This skill deletes branches and worktrees and is meant to run only when the user invokes it by name. Codex enforces this through agents/openai.yaml (allow_implicit_invocation: false); where nothing enforces it (for example opencode), apply the confirmation gate below |
AskUserQuestion, subagents, context: fork | Not used |
Confirmation gate on agents other than Claude Code: run the real cleanup directly only when the user invoked this skill by name (/git-clean-gone or $git-clean-gone) without --dry-run and without exclusions or conditions (such as "but keep feat/x"). In every other case, including plain requests such as "clean up stale branches", run with --dry-run first, show the preview, then end your turn and wait for the user's reply. Never run the real cleanup in the same turn as the preview; only an explicit yes in a later user message allows it. Approval is all-or-nothing: the script cannot skip individual branches, so if the user wants to keep any listed branch or worktree, stop and do not run the real cleanup. The real run fetches again, so after it, compare its DELETED/REMOVED_WT lines with the preview and call out every branch or worktree that was not in the preview. In Claude Code, invoking /git-clean-gone without --dry-run is that explicit request.
In Codex, git fetch --prune and gh need network access and the deletions write to .git, so run the script with escalation and a short reason from the start, for the --dry-run preview as well as the real run. A preview without network silently misses gone and squash-merged branches. If the output has a fatal: or error: line from git fetch, the fetch failed: report it and do not run the real cleanup.
Parse from $ARGUMENTS:
| Flag | Default | Purpose |
|---|---|---|
| (none) | — | Full cleanup: gone + merged branches + worktrees |
--dry-run | off | Preview only, no changes |
--no-worktrees | off | Branches only, skip worktree removal |
git for-each-ref --format="%(upstream:remotename)" refs/heads/main 2>/dev/null || git remote | head -1 2>/dev/null || echo "origin"basename "$(git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null || echo refs/remotes/origin/main)"command -v gh >/dev/null 2>&1 && echo "available" || echo "unavailable""${CLAUDE_SKILL_DIR}/scripts/clean-gone.sh" as a single Bash invocation--dry-run preview always ends the turnExecute "${CLAUDE_SKILL_DIR}/scripts/clean-gone.sh" immediately, passing through any flags from $ARGUMENTS. On agents other than Claude Code, apply the confirmation gate from Agent compatibility first.
--dry-run → preview only, no changes--no-worktrees → gone branches only, no worktree removal or merge detection--dry-run, --no-worktrees), stopParse script output line prefixes and render formatted summary directly as text.
Line prefixes (from script output):
| Prefix | Meaning |
|---|---|
DELETED:branch:reason | Deleted branch |
REMOVED_WT:worktree:branch | Removed worktree |
SKIPPED:branch:reason | Skipped branch |
KEPT:branch:reason | Kept branch |
KEPT_WT:worktree:branch:reason | Kept worktree |
Dry-run uses WOULD_DELETE, WOULD_REMOVE_WT, WOULD_SKIP, WOULD_KEEP, WOULD_KEEP_WT.
Summary format:
**Cleanup Summary**
Deleted:
🗑️ fix/old-feature (gone)
🗂️ fix-old-feature-wt (worktree)
Skipped:
⚠️ feat/current-work (current branch)
Kept:
🗂️ wt-name (worktree) - branch (N unmerged)
ℹ️ feat/in-progress (14 unmerged)
Only include sections with items. Empty state: ✅ Repository already clean — no branches to process
Dry-run header: **Dry Run Preview** with "Would delete/remove" phrasing.
[gone] (remote tracking deleted)git cherry)gh pr list --state merged) when gh CLI is available--force flaggh CLI (see preprocessed context): squash merges won't be detected, only git cherry used/git-clean-gone
Preview what would be deleted:
/git-clean-gone --dry-run
Branches only, no worktree removal:
/git-clean-gone --no-worktrees
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
npx claudepluginhub smykla-skalski/sai --plugin git-clean-gone