agentleFS
mxrsvmxrsv/spacevibe-deck/.claude/skills/clean-worktrees/SKILL.md

clean-worktrees

Skill41 starsChanged 23 days agoMITView on GitHub

Report which git worktrees and local branches of this repo are safe to remove, then remove only the rows the owner confirms. Use when the owner asks to clean or prune worktrees or branches, or `git worktree list` shows more than the three-worktree limit. Not for creating worktrees, merging, or deleting `backup/*` branches.

  • Reads credentials

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. 7zrv/claude-code-monitor★ 1same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository7 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

6 rules. About 0 are common, 4 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Run git fetch --prune origin first so the origin/main and unpushed columns are not judged against stale remote-tracking refs.

    line 14
  2. Very specific:

    Never propose remove for: the primary checkout, a dirty worktree (ignored files included), one with unpushed or unreachable commits, a live …

    line 49
  3. Distinctive:

    Stop here until the owner replies.

    line 58
  4. Distinctive:

    Only rows the owner named.

    line 62
  5. Distinctive:

    If any command fails or times out, stop.

    line 71
  6. Distinctive:

    Run git worktree prune --dry-run and show its output.

    line 77

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Clean worktrees

AGENTS.md sets no cap on live worktrees; this skill clears the ones made by hand under ../spacevibe-deck-worktrees/. It reports first and removes only what the owner confirms, row by row. Run all git commands from the primary checkout and read plans there by absolute path.

Step 1: report only

Run git fetch --prune origin first so the origin/main and unpushed columns are not judged against stale remote-tracking refs. No other git write command in this step. For every worktree in git worktree list --porcelain, except the primary checkout, collect:

ColumnHow
Path, branch or detachedporcelain output
Last commit dategit log -1 --format=%cs <head>
Mergedgit merge-base --is-ancestor <head> origin/main exits 0, or the tip equals the head.sha of a merged PR (command below). Squash and rebase merges leave the branch off origin/main, so the ancestor test alone misses them. Note "local main only" separately
Dirtythe ignored-aware status below prints anything. Ignored files count: git worktree remove deletes them without --force, and .env* and docs/plans/ are ignored here
Unpushedgit rev-list <head> --not --remotes is non-empty. A tip that equals a merged PR's head.sha has nothing unpushed
Detached, orphanedgit branch -a --contains <head> is empty
Live processlsof -a -d cwd -Fn lines equal to n<path> or starting with n<path>/ (the slash keeps landing from matching landing-standout). Never lsof +D (slow)
Recently touchedfind <path> -mmin -1440 -not -path '*/node_modules/*' -not -path '*/.git/*' -print -quit prints a file. Agent sessions run from the primary checkout and edit worktrees by absolute path, so the process column cannot see them; this one can
Named by a plangrep -rl the path and the branch name in the primary checkout's docs/plans/
# Merged PR for a branch: prints "<number> <head.sha>"; compare with `git rev-parse <branch>`
gh api "repos/mxrsv/spacevibe-deck/pulls?state=closed&head=mxrsv:<branch>" \
  --jq '.[] | select(.merged_at) | "\(.number) \(.head.sha)"'
# Dirty, ignored files included; build output at any depth is dropped
git -C <path> status --porcelain --ignored \
  | grep -vE '^!! (.*/)?(node_modules|dist|dist-electron|dist-electron-app)/$'

Then list local branches that have no worktree, with the merged, unpushed and named-by-a-plan columns. backup/* branches are left out of the table; report only their count.

Print one table and propose a verdict per row:

  • remove: merged, clean, nothing unpushed, not orphaned, no live process, not recently touched, not named by a plan.
  • keep (reason): dirty, unpushed, orphaned or a live process — name which.
  • ask: every other case — named by a plan, recently touched, merged into local main only.

Never propose remove for: the primary checkout, a dirty worktree (ignored files included), one with unpushed or unreachable commits, a live process, a recent touch, a plan naming it, or a backup/* branch.

End the report with two lines:

  • Not checked: each column that could not be computed, and why.
  • Skill gaps: edits you would make to this skill. Suggest only; do not edit it.

Stop here until the owner replies.

Step 2: remove the confirmed rows

Only rows the owner named. Re-run the merged, dirty, unpushed, process and recently-touched checks on each one first; the state may have changed since the report.

  1. git worktree remove <path>. No --force.
  2. git branch -d <branch>. Never -D, with one exception: -d refuses a squash- or rebase-merged branch, so -D is allowed only when the re-check just showed its tip equals a merged PR's head.sha (those commits stay on GitHub as refs/pull/<n>/head); name the PR in the report. Any other refusal: report it and leave the branch.

If any command fails or times out, stop. Report git worktree list and whether the directory still exists. Do not retry, do not force, do not clean up the half-done state: a timed-out worktree command is not a rollback (see traps).

After removals

Run git worktree prune --dry-run and show its output. Run git worktree prune only if the owner agrees. Finish by showing git worktree list and the count against the limit.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.