Cleanup
Skill honerlaw/agent-marketplace/plugins/minerva/skills/cleanup
Removes `.minerva/worktrees/NNN-slug/` directories whose branches have been merged into the default branch, and prunes the corresponding local branches. Idempotent; never touches the default branch or unmerged work. Use after a PR merges, when the user asks to remove merged worktrees, prune stale minerva branches, or generally tidy up after shipped work, or when they invoke `minerva:cleanup`.From its SKILL.md
npx -y skills add honerlaw/agent-marketplace --skill cleanupAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
One thing to look at
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
SKILL.md
6.8 KB, ~1.7k tokens by cl100k_base, as published. Nobody here has run it
Tidy up after shipped work — remove .minerva/worktrees/NNN-slug/ directories whose branches have been merged into the default branch, and prune the corresponding local branches. Idempotent: safe to run on a clean tree (reports zero items removed).
Usage
minerva:cleanup— sweep all merged worktrees + branches in the current repominerva:cleanup 005-add-payments— clean up only the named work unit (slug or path)minerva:cleanup --dry-run— list what would be removed without removing anything
Target resolution
Same pattern used by minerva:work, minerva:replan, minerva:promote, minerva:review, minerva:ship. Keep all six blocks in sync if you edit one. For minerva:cleanup specifically, the default mode (no argument) is "all merged worktrees" rather than a single target — but resolution rules apply when an argument is passed.
- Explicit argument (slug or path) → operate on just that work unit. Check both
.minerva/work/<NNN-slug>/and.minerva/worktrees/<NNN-slug>/. Required: the corresponding branch must be merged into default (see Merge detection). - No argument → scan all
.minerva/worktrees/NNN-*/directories and check each branch's merge state. - Non-git repo → report "not a git repo, nothing to clean up" and stop.
Pre-flight checks
Bail with a clear message on any failure:
- Git repo.
git rev-parse --is-inside-work-treereturns true. ghCLI available (optional but preferred). Falls back to local-only merge detection ifghis missing or unauthenticated.- Not currently inside a worktree being cleaned. If invoked from inside
.minerva/worktrees/NNN-slug/, that worktree cannot be removed while it's the current working tree. Report and ask the user tocdout (back to the main repo root) and re-run. Cleanup always operates from the parent repo — its job is to remove worktrees, so it must never be running inside one. (No lifecycle skill makes a worktree its working directory: the others address worktrees by.minerva/worktrees/NNN-slug/-prefixed paths, while cleanup removes them outright.)
Default-branch detection
Resolve once at the start:
git symbolic-ref refs/remotes/origin/HEAD→ parserefs/remotes/origin/<name>.- Fall back to
main, thenmaster.
Use the resolved value for all merge checks.
Merge detection per worktree
For each .minerva/worktrees/NNN-slug/ candidate, determine if its branch (NNN-slug by convention) has been merged into the default branch:
- Branch exists?
git rev-parse --verify NNN-slug— if the branch is already gone (was deleted upstream and locally), the worktree is orphaned and can be removed. - Merged via PR (preferred) —
gh pr list --head NNN-slug --state merged --json number,mergedAt --limit 1. If a merged PR exists, the work is shipped. - Merged locally —
git branch --merged <default> | grep -q "^[* ] NNN-slug$". Catches the case where the branch was merged locally or whereghisn't available. - Neither — branch is not merged. Skip. Do not remove an unmerged worktree (the user's in-progress work would be lost).
Report each candidate's state. For --dry-run, stop here.
Confirmation gate
Before removing anything, present the list:
Will remove:
.minerva/worktrees/005-add-payments/ (branch 005-add-payments, merged via PR #42 on 2026-05-12)
.minerva/worktrees/006-add-ship-skill/ (branch 006-add-ship-skill, merged via PR #45 on 2026-05-15)
Will skip:
.minerva/worktrees/007-add-cleanup/ (branch 007-add-cleanup, NOT merged — unmerged work, leaving alone)
Ask:
"Remove these worktrees and prune the matching local branches? [y/N]"
Default is no — destructive operations require explicit yes. The user can also batch ("yes, all" / "just the first two" / "skip 006").
Skip this gate when --dry-run is set (nothing destructive happens) or when the user invokes with an explicit single-unit argument and says --yes (e.g. minerva:cleanup 005-add-payments --yes).
Removal
For each confirmed worktree:
git worktree remove .minerva/worktrees/<NNN-slug>— if this fails because the worktree has uncommitted changes, surface the error and skip (do not force-remove without explicit user direction; uncommitted changes in a "merged" worktree are a red flag worth surfacing).git branch -d <NNN-slug>— uses-d(safe delete), not-D(force). If-drefuses because git thinks the branch isn't merged (rare after PR merge — usually a squash-merge artifact), fall back togit branch -D <NNN-slug>only if the merged-PR check in step 2 of Merge detection passed. Squash-merges leave a different commit hash on default, so localgit branch -dis conservative and needs an override.git worktree prune— cleans up any stale worktree metadata.
After all removals: git worktree list to show the final state.
Final report
Worktrees removed: N (<list>)
Branches pruned: N (<list>)
Skipped (unmerged): N (<list with branch names>)
Skipped (uncommitted): N (<list — needs manual review>)
Remaining worktrees: N (<list>)
If any worktrees were skipped due to uncommitted changes, recommend the user inspect each (cd .minerva/worktrees/<slug>; git status) and decide whether the changes are valuable.
Idempotency
Cleanup is stateless. Re-running on a fresh tree finds zero candidates and reports zero removed. Running mid-CI for a branch with an auto-merge pending will correctly skip that worktree (PR is OPEN, not MERGED).
If a user manually removed a worktree directory without running git worktree remove, the next minerva:cleanup call will see stale worktree metadata; git worktree prune at the end of the run handles this.
Out of scope
- Removing the work-unit's
.minerva/work/NNN-slug/directory frommain. The docs already moved into the worktree atminerva:worktime and were merged intomainvia the PR; the canonical record lives at.minerva/work/NNN-slug/post-merge.cleanuponly removes the worktree, not the merged docs. - Removing knowledge files.
.minerva/knowledge/entries are permanent by design. - Force-removing unmerged work. Always requires explicit user override; cleanup is conservative by default.
- Pruning remote branches. GitHub usually auto-deletes the source branch after merge if the repo is configured for it. Local prune handles the local side; remote prune is
git fetch --pruneand not part of this skill.
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.