Clean out stale branches, worktrees, checkouts, scratch directories, and ignore rules; the pond stays clean. Use before deleting branches or worktrees, even on a blanket order to delete them all, and when the user asks for repository cleanup across one or more repos, or when stale worktrees and temporary artifacts have accumulated after merged work.
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 Duck Sweep?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/askrubberduck-duck-sweep)
---
name: duck-sweep
description: Clean out stale branches, worktrees, checkouts, scratch directories, and ignore rules; the pond stays clean. Use before deleting branches or worktrees, even on a blanket order to delete them all, and when the user asks for repository cleanup across one or more repos, or when stale worktrees and temporary artifacts have accumulated after merged work.
---
# Duck Sweep
Clean one or more repos under a hard rule: **verify merged before delete, and keep nothing "just in
case"**. Unmerged work gets an explicit merge-or-delete decision. One preservation invariant covers
every deletion path: an entry marked **keep** moves to
its durable home and is verified there before its container is removed.
Follow the user's language unless they ask otherwise. Keep commands, paths, identifiers,
quoted errors and machine-readable verdicts unchanged; the duck asks for evidence in any language.
Before a step that requires the procedure of a skill, load that skill. Follow its named section
within existing authority. A conditional or routing mention needs no load until it applies.
## Sweep per repo
1. Inventory: run `git fetch --prune`, then `git worktree list` and `git branch -vv`, with absolute
paths and no cd between repos. Record an unreachable remote or unreadable worktree and continue.
A multi-repo setup means every sibling repo the request names.
2. Classify: **delete only what is provably preserved elsewhere**.
- **Preserved**: commits reachable from `origin/<default>`.
`git branch --merged origin/<default>` is the proof. Delete with `-D`; `-d` re-checks against
HEAD or the upstream and refuses when either is behind.
- **Preserved by record**: squash-merged, rebased or cherry-picked, *and* the project's outcome
record ([`duck-land`](../duck-land/SKILL.md)'s) names this branch's landed and candidate SHAs.
Confirm the landed SHA is on `origin/<default>` **and the branch tip is still that
candidate**, then delete. A branch that gained commits after landing is Unverified.
- **Not preserved**: squash-merged, rebased or cherry-picked with **no such record**. PR
records, `git cherry`, tree diffs and revert greps each produce false positives; here, one
destroys work. Do not build a cleverer classifier. Treat it as Unverified.
- **Unverified**: open the work item and decide. To merge, land it, reclassify by the paths
above and delete under that path. To delete, record the decision, then use `-D`. A blanket
order ("delete every branch", "don't ask") names no branch and is not that decision. Keep and
report each Unverified branch until the owner names it.
3. Delete, after `git status --short --untracked-files=all --ignored` on the worktree. Plain
`git status` hides ignored files, and `git worktree remove` takes every untracked and ignored
file with it. Drop entries reproducible from tracked content (build output, caches,
installed dependencies) that the repo's ignore rules name as artifacts. Every other `??` or
`!!` entry first gets an explicit keep-or-delete decision: **unknown means keep, and only the
owner may decide to delete one**. Queue it through [`duck-decide`](../duck-decide/SKILL.md), and
keep the file until the owner decides.
When nothing in the worktree remains marked keep, run `git worktree remove <path>`,
`git branch -D <branch>` per the classification, and `git worktree prune`.
4. Scratch dirs: find ad-hoc temp dirs outside the sanctioned scratchpad (`<repo>-tmp*` in the home
directory, `<repo>*` in the system temp directory, stray review-tmp dirs). The scratchpad
is disposable; never sweep it per file. A non-git dir has no merge evidence. Inventory every
entry, hidden ones included (`ls -laR`), and give each step 3's keep-or-delete decision. Run
`rm -rf` on the dir only when nothing in it remains marked keep.
5. `.gitignore` audit: confirm that worktree dirs (`.worktrees/`), build output and local-config
paths are listed and ignored. Sanity-check with `git status --ignored`.
## Report shape
Per repo, report deleted items (with merge evidence), kept items (with the justifying work item)
and decisions. A deletion without stated merge evidence is not done.