Skip to content
Back to skills

Git Sweep

ASecurity

Clean stale git branches and worktrees interactively. Audits local/remote branches, proves which ones the base already contains (including after a squash or rebase), frees finished worktrees, and confirms before deleting. Use when: "git sweep", "sweep branches", "branch cleanup", "prune stale branches", "clean up agent worktrees".

  • 6 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 24, 2026
toolsbashgitbackend

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned November 29, 2026

npx -y skills add bengous/claude-code-plugins --skill git-sweep --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Sweep?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Sweep
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/bengous-git-sweep/badge)](https://www.skillsdirectory.com/skills/bengous-git-sweep)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-sweep
description: >
  Clean stale git branches and worktrees interactively. Audits local/remote
  branches, proves which ones the base already contains (including after a
  squash or rebase), frees finished worktrees, and confirms before deleting.
  Use when: "git sweep", "sweep branches", "branch cleanup",
  "prune stale branches", "clean up agent worktrees".
disable-model-invocation: true
argument-hint: "[base-branch]"
allowed-tools:
  - Bash(${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-audit.ts *)
  - Bash(${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-apply.ts *)
  - Bash(printf:*)
  - Bash(test:*)
  - Bash(echo:*)
  - Bash(git log:*)
  - Bash(git diff:*)
  - Bash(git symbolic-ref:*)
  - Bash(git rev-parse:*)
  - Bash(git branch:*)
  - Bash(git for-each-ref:*)
  - Bash(git status:*)
  - Bash(git worktree list:*)
  - Read
  - Write
  - Grep
  - Glob
---

# Git Sweep

Route to the correct cleanup phase based on repo state. The phase files
`audit.md` and `apply.md` live in this skill's base directory.

## Inputs

- base: $ARGUMENTS
  (optional: the base branch to audit against, e.g. `/git-sweep dev`;
  empty lets the backend resolve the trunk: git config sweep.base,
  then origin/HEAD, then main/master/trunk/dev/develop)
- branch: !`git branch --show-current`
- repo: !`git rev-parse --show-toplevel`
- worktrees: !`git worktree list`
- pending: !`test -f "$(git rev-parse --absolute-git-dir)/git-sweep-manifest.json" && echo "yes" || echo "no"`
- tools: !`test -x "${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-audit.ts" && test -x "${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-apply.ts" && echo "ok" || echo "missing"`

## Routing

```
if tools == "missing":
  STOP — tell user: git-clean-audit and/or git-clean-apply not executable.
  Run: chmod +x "${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-audit.ts" "${CLAUDE_PLUGIN_ROOT}/scripts/git-clean-apply.ts"

if pending == "yes":
  # A previous run left operations unexecuted (partial failure, or an
  # interrupted hand-off). The file holds an already-confirmed selection.
  AskUserQuestion:
    header:   "Manifest"
    question: "A pending cleanup manifest exists. Apply it, or re-audit?"
    options:  "Apply pending manifest (Recommended)"
              | "Re-audit (overwrites it)"
  if "Apply pending manifest":
    Read apply.md and follow it
    (do not continue below)

Read audit.md and follow it
```

The audit phase handles all "nothing to clean" detection itself
(local branches, remote branches, worktrees). Do not short-circuit here.

## Configuration (git config, all optional)

- `sweep.base` — trunk to audit against when no argument is given
- `sweep.protect` (multi-valued) — extra branches never proposed for deletion
- `sweep.unprotect` (multi-valued) — lift names from the default protected
  set (main, master, trunk, dev, develop); the audited base stays protected
- `sweep.agentPrefix` / `sweep.backupPrefix` — classification prefixes
  (defaults `worktree-agent-`, `backup/`; they must not overlap)
- `sweep.maxAgeDays` — age bound for the containment test (default 180)

Suggest the right key when a repo needs it (custom trunk name, other branch
conventions); never set one without the user asking.

Files in this skill

  • SKILL.md3.1 KB
  • apply.md7.8 KB
  • audit.md15.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.