agentleFS
jMertajMerta/codex-skills/branch-cleaner/SKILL.md

branch-cleaner

Skill130 starsChanged 11 months agoMITView on GitHub

Use when the user asks to list, audit, prune, or delete local or remote Git branches, especially stale, merged, gone-upstream, protected, worktree-bound, or open-PR branches. Identifies safe candidates and performs only explicitly authorized cleanup.

  • Commits and pushes

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 6 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

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

    When GitHub context is available, prefer the GitHub connector for open/merged PR metadata and branch protection context.

    line 16
  2. Distinctive:

    Delete only approved candidates:

    line 23
  3. Distinctive:

    use git branch -D only for an individually named unmerged branch explicitly approved by the user.

    line 28
  4. Distinctive:

    Treat age as a review signal, never proof that a branch is safe to delete.

    line 33
  5. Distinctive:

    Never delete through an unresolved glob or a generated command string.

    line 34
  6. Distinctive:

    Do not remove a branch used by another worktree.

    line 35
  7. Distinctive:

    Do not delete remote branches or force-delete unmerged branches without explicit approval.

    line 36

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 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

Branch cleaner

Workflow

  1. Resolve the repository, current branch, remote, and remote default branch from Git. Ask only when they remain ambiguous.
  2. Fetch and prune remote-tracking refs, then collect evidence:
    • git status -sb
    • git worktree list --porcelain
    • git branch --merged <remote>/<default> and git branch --no-merged <remote>/<default>
    • git for-each-ref refs/heads --sort=committerdate --format="%(committerdate:iso8601) %(refname:short) %(upstream:short) %(upstream:track)"
  3. When GitHub context is available, prefer the GitHub connector for open/merged PR metadata and branch protection context. Use gh only as a fallback.
  4. Exclude the current branch, the default branch, branches checked out in any worktree, protected branches or rulesets, and branches with open PRs. If open-PR or protection state cannot be verified, keep the branch report-only.
  5. Group candidates by evidence:
    • merged into the fetched default branch;
    • upstream gone;
    • old but unmerged, which is report-only unless the user explicitly approves force deletion.
  6. Present concrete branch names, last commit dates, merge state, and local/remote scope before deleting anything.
  7. Delete only approved candidates:
    • immediately before each deletion, fetch current evidence and recheck the branch tip SHA, worktree use, open PRs, and protection or ruleset state against the reviewed candidate;
    • skip the branch if its tip or state changed, or if any safety check is unavailable;
    • local merged branch: git branch -d <branch>;
    • remote branch: git push <remote> --delete <branch> only when remote deletion was explicitly requested;
    • use git branch -D only for an individually named unmerged branch explicitly approved by the user.
  8. Re-run the candidate commands and git status -sb to verify the result.

Safety

  • Treat age as a review signal, never proof that a branch is safe to delete.
  • Never delete through an unresolved glob or a generated command string.
  • Do not remove a branch used by another worktree.
  • Do not delete remote branches or force-delete unmerged branches without explicit approval.
  • Preserve unrelated working-tree changes.

Deliverable

Report deleted branches, skipped branches with reasons, commands run, and any candidates still needing a decision.

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.

Reviews can't be read right now.

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.