Clean leftover local branches and agent worktrees with no prompt: deletes the branches git-sweep proves are already in the base, removes the clean agent worktrees (.claude/worktrees/agent-*) standing on them, and archives under refs/archive/ the agent branches abandoned past a threshold. Never touches a remote ref, a protected or current branch, or a worktree with changes. Use when a session ends, after landing a branch, or when leftover agent worktrees and branches pile up.
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Auto Sweep?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/bengous-auto-sweep)
---
# Model-invocable without breaching .claude/rules/skill-commands.md: every
# deletion has an undo or loses nothing (a proven branch's content is in the
# base, an archive restores, a worktree loses only regenerated ignored paths
# and ignored symbolic links, never their targets).
name: auto-sweep
description: >
Clean leftover local branches and agent worktrees with no prompt: deletes the
branches git-sweep proves are already in the base, removes the clean agent
worktrees (.claude/worktrees/agent-*) standing on them, and archives under
refs/archive/ the agent branches abandoned past a threshold. Never touches a
remote ref, a protected or current branch, or a worktree with changes.
Use when a session ends, after landing a branch, or when leftover agent
worktrees and branches pile up.
argument-hint: "[--dry-run] [--base <branch>]"
allowed-tools:
- Bash(${CLAUDE_PLUGIN_ROOT}/scripts/auto-sweep.ts *)
---
# Auto Sweep
The script decides everything: which base to judge against, which branch is
proven, which agent branch is abandoned. Run it, then relay its summary.
## Run
```
"${CLAUDE_PLUGIN_ROOT}/scripts/auto-sweep.ts" $ARGUMENTS
```
One plain command, nothing appended. It works from any checkout of the
repository; the checkout it runs in is current, so its branch and worktree stay.
- `--dry-run` prints the same summary and changes nothing. Use it when the
user asks what a sweep would do.
- `--base <branch>` names the base. Without it the script takes `sweep.base`,
then `dev` or `develop`, then origin/HEAD, then main, master or trunk.
Exit 0 means every operation went through; 1 means the audit failed (reason
on stderr) or an operation failed (listed under `Failed`); 2 means a bad
argument.
## Report
Relay the summary in a few lines: how many branches were deleted, which agent
worktrees were removed, and every archived branch with its restore command,
`git branch <name> refs/archive/<name>`. Name the kept branches only when the
user asks, or when one looks like work the user is waiting on.
The sweep tidies more than it frees: most disk space sits in named worktrees,
which it leaves. When the summary ends with a count of clean worktrees on work
the base already holds, say so and name `/git-sweep` as the way to remove them.
It runs on the current repository only; for several, run it once in each.
Leave what the script kept as it is: do not delete, unlock or prune by hand.
An unproven branch that is not an agent's, a worktree outside
`.claude/worktrees/agent-*`, a backup branch and every remote branch are the
interactive `/git-sweep`'s to judge, with the user.
## What it decides
| Case | Outcome |
|------|---------|
| Branch proven in the base (ancestry, no merge delta, merged PR) | deleted |
| Clean agent worktree on a proven branch, its ignored paths all regenerated (`node_modules/`, a plugin's `tsconfig.json`…) or symbolic links | removed, branch deleted, link targets left |
| Detached worktree, an agent's included | kept, listed under its path with its state (`clean, HEAD in <base>`, its changes, or a HEAD the base lacks) |
| Agent worktree whose directory is gone | registration dropped |
| Unproven agent branch, PR closed unmerged and last commit both 14+ days old | archived, then deleted with its clean worktree |
| Unproven agent branch, no PR, last commit 30+ days old | archived, then deleted with its clean worktree |
| Base, protected, current, locked, dirty, or holding any other ignored path that is not a symbolic link (a `plans/` directory) | kept, the path named |
| Named worktree `.claude/worktrees/<name>`, or any outside `.claude/worktrees/agent-*` | not swept |
| Agent branch whose agent still runs (its worktree is locked) | kept |
| Remote branches and tracking refs | never deleted |
An agent branch is one named with `sweep.agentPrefix` (default
`worktree-agent-`) or checked out only in an agent worktree.