agentleFS
gufrancogufranco/claude-engineering-rules/skills/cleanup/SKILL.md

cleanup

Skill3 starsChanged 30 days agoMITView on GitHub

List stale branches, long-open PRs, merged branches, and orphaned worktrees, then close or delete each one with confirmation.

  • Commits and pushes

71 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use chips, react-query-best-practices and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • udecodeSkill

    chips

    Run the project's suggested-task ledger, the chips. /chips alone brings this session's open tasks up to date: it applies what the ledger helper says, settles stale and split tasks, cards what can start and reports the board, and /chips all also takes the ship-list tasks and the ones no live session owns, and merges duplicate tasks across the board. Use for /chips, /chips offer, start or drop, \"what chips are open\", \"suggest a task for X\", \"update the chips\", \"clean up the chips\", \"which chips are stale\", \"is this chip still worth doing\", \"merge duplicate chips\", at the last hand-back of a run that offered a task, and whenever pstack would file a tracked issue, a follow-up, a reflect Backlog item or an out-of-band PR.

    Also in 3 projects that use this

  • bibektimilsina00Skill

    react-query-best-practices

    Audit and fix React Query usage in apps/web — enforce query key factories, signal forwarding, staleTime, and proper mutation patterns. Use when reviewing or fixing server-state code.

    Also in 3 projects that use this

  • bibektimilsina00Skill

    you-might-not-need-a-callback

    Analyze and fix useCallback anti-patterns in your code

    Also in 3 projects that use this

  • Scylla23Skill

    redo

    Re-run the last routed task one model tier up (haiku → sonnet → opus → fable). User-invoked escalation when the previous result missed. Pass --dry-run to preview without running.

    Also in 3 projects that use this

  • Aetheria-Labs1Skill

    plan-page

    Plan one storefront page from strategy through final copy, section order, proof, offers, template direction, responsive layout, and production asset requirements. Stops at an approved execution-ready specification.

    Also in 3 projects that use this

  • SocialKit-APISkill

    video-transcripts

    Extract transcripts from social videos through SocialKit across YouTube, TikTok, Instagram, Facebook, X/Twitter, LinkedIn, and direct video file URLs. Use when the user asks to transcribe, get captions or subtitles, pull the spoken text, or read what a video says, including one video or many at once. Returns full text plus timestamped segments. Not for posting, private accounts, or unrelated website scraping.

    Also in 3 projects that use this

  • +3 more from bibektimilsina00

The file

Show its rules and text

We split this skill into the rules it gives an agent

21 rules. 0 are common, 12 are distinctive, and 9 are very specific to this project.

  • 0

    Common

    Most of the 61 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 9

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    When the repository has accumulated many old branches.

    line 16
  2. Distinctive:

    When you want to prune merged branches that were never deleted after merge.

    line 17
  3. Distinctive:

    When open PRs have gone stale and need to be closed or re-evaluated.

    line 18
  4. Distinctive:

    When worktrees from previous tasks were left behind.

    line 19
  5. Distinctive:

    Before a release to reduce clutter.

    line 20
  6. Very specific:

    No arguments: full scan covering branches, PRs, and worktrees.

    line 32
  7. Distinctive:

    Detect the platform and account: Read git remote get-url origin to determine GitHub or GitLab.

    line 45
  8. Distinctive:

    Find orphaned worktrees: Run git worktree list --porcelain.

    line 57
  9. Very specific:

    If --apply was NOT passed, stop here: Default mode is dry-run. Print the report, remind the user to re-run with --apply to mutate, and …

    line 96
  10. Very specific:

    Confirm and act: Only when --apply was passed.

    line 98
  11. Distinctive:

    Prune remote tracking branches: Run git remote prune origin to clean up references to deleted remote branches.

    line 108
  12. Very specific:

    Never delete protected branches: main, master, develop, staging, production, or branches matching release/*.

    line 124
  13. Distinctive:

    Always confirm before force-deleting unmerged branches.

    line 125
  14. Distinctive:

    Never close PRs that have activity in the last 7 days, even if they are older than the stale threshold.

    line 126
  15. Very specific:

    Always prefix gh commands with GH_TOKEN per the github-accounts rule.

    line 127
  16. Very specific:

    Always prefix glab commands with GITLAB_TOKEN and GITLAB_HOST per the gitlab-accounts rule.

    line 128
  17. Very specific:

    When a branch exists both locally and on the remote, delete both if approved.

    line 131
  18. Very specific:

    Stop and drop the item when a candidate branch is main, master, develop, staging, production, or matches release/*.

    line 144
  19. Very specific:

    Stop after the report when the invocation lacks --apply.

    line 145
  20. Distinctive:

    Stop and ask again when the user's selection names an item absent from the report.

    line 146
  21. Distinctive:

    Stop and keep the worktree when git worktree list --porcelain shows uncommitted changes in it.

    line 147

“Common” is measured: kept by at least 6 in 10 of the 61 edited versions of this file we could read. “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

Overview

Repository hygiene tool that finds stale branches, lingering PRs, merged branches not yet deleted, and orphaned worktrees. Presents everything in a table, asks for confirmation per item, and cleans up what you approve.

When to use

  • When the repository has accumulated many old branches.
  • When you want to prune merged branches that were never deleted after merge.
  • When open PRs have gone stale and need to be closed or re-evaluated.
  • When worktrees from previous tasks were left behind.
  • Before a release to reduce clutter.

When NOT to use

  • For refactoring or cleaning up code. Use /review or a manual refactor instead.
  • For dependency updates or vulnerability scanning. Use /audit instead.
  • For git commit, push, or PR creation. Use /ship instead.

Arguments

This skill accepts optional arguments after /cleanup:

  • No arguments: full scan covering branches, PRs, and worktrees. Default mode is dry-run. No mutation happens without --apply.
  • branches: scan branches only.
  • prs: scan PRs only.
  • worktrees: scan worktrees only.
  • --dry-run: explicit dry-run flag. Same as the default. Kept for clarity.
  • --apply: perform the cleanup. Required for any mutation. Without this flag, the skill prints the report and exits.

Examples: /cleanup branches, dry-run, /cleanup prs --apply, /cleanup --apply.

The two-phase flow exists because cleanup is destructive: read the report, decide, then re-run with --apply.

Steps

  1. Detect the platform and account. Read git remote get-url origin to determine GitHub or GitLab. Identify the correct account token per the github-accounts or gitlab-accounts rules.
  2. Find merged branches. Run git branch --merged origin/HEAD 2>/dev/null to list local branches whose HEAD is reachable from the default branch. If origin/HEAD is not set, try origin/main, then origin/master. Exclude protected branches: main, master, develop, staging, production, and any branch matching release/*. These can be safely deleted with git branch -d.
  3. Find stale branches. For each local and remote branch not in the merged list and not protected, check the date of the last commit: git log -1 --format="%ci" <branch>. Flag branches with no commits in the last 30 days as stale. Record the branch name, last commit date, last commit message, and author.
  4. Find stale PRs. Query the platform for open PRs in the current repo.
    • GitHub: GH_TOKEN=$(gh auth token --user <account>) gh pr list --state open --json number,title,author,createdAt,updatedAt,isDraft,url
    • GitLab: GITLAB_TOKEN=<token> GITLAB_HOST=<host> glab mr list -F json, which lists open MRs by default
    • Flag PRs open for more than 14 days with no activity in the last 7 days as stale.
    • Flag draft PRs open for more than 7 days separately.
  5. Find orphaned worktrees. Run git worktree list --porcelain. For each worktree, check if its branch still exists and is not merged. A worktree whose branch was deleted or merged is orphaned.
  6. Present findings. Display a table grouped by category:

    ## Cleanup Report
    
    ### Merged branches (safe to delete)
    
    | Branch | Merged into | Last commit |
    |--------|------------|-------------|
    | feature/auth-v2 | main | 12 days ago |
    | bugfix/null-check | main | 3 weeks ago |
    
    ### Stale branches (no commits in 30+ days)
    
    | Branch | Last commit | Author | Last message |
    |--------|------------|--------|-------------|
    | feature/old-idea | 45 days ago | alice | WIP: initial attempt |
    
    ### Stale PRs (open 14+ days, no recent activity)
    
    | PR | Title | Author | Age | Last activity |
    |----|-------|--------|-----|--------------|
    | #42 | Add caching layer | bob | 21 days | 18 days ago |
    
    ### Draft PRs (open 7+ days)
    
    | PR | Title | Author | Age |
    |----|-------|--------|-----|
    | #55 | WIP: new layout | carol | 10 days |
    
    ### Orphaned worktrees
    
    | Path | Branch | Reason |
    |------|--------|--------|
    | /tmp/repo-auth | feature/auth | branch deleted |
  7. If --apply was NOT passed, stop here. Default mode is dry-run. Print the report, remind the user to re-run with --apply to mutate, and exit.
  8. Confirm and act. Only when --apply was passed. For each category, ask the user which items to clean up. Accept "all", a comma-separated list of names or numbers, or "skip".

    • Merged branches: git branch -d <branch>.
    • Stale branches: git branch -D <branch> with a warning that this force-deletes an unmerged branch.
    • Stale PRs: close without a comment, per ../../rules/pr-comment-discipline.md. The terminal report names each closed PR and its idle time, so the user can tell the author directly.
      • GitHub: GH_TOKEN=$(gh auth token --user <account>) gh pr close <number>
      • GitLab: GITLAB_TOKEN=<token> GITLAB_HOST=<host> glab mr close <number>
    • Draft PRs: same as stale PRs.
    • Orphaned worktrees: git worktree remove <path>.
  9. Prune remote tracking branches. Run git remote prune origin to clean up references to deleted remote branches.
  10. Print summary.

    ### Cleanup complete
    
    - N merged branches deleted
    - N stale branches deleted
    - N PRs closed
    - N worktrees removed
    - Remote tracking branches pruned

Rules

  • Never delete protected branches: main, master, develop, staging, production, or branches matching release/*.
  • Always confirm before force-deleting unmerged branches. Make the warning visible.
  • Never close PRs that have activity in the last 7 days, even if they are older than the stale threshold.
  • Always prefix gh commands with GH_TOKEN per the github-accounts rule.
  • Always prefix glab commands with GITLAB_TOKEN and GITLAB_HOST per the gitlab-accounts rule.
  • Close a PR with no comment. The reason goes in the terminal report, where the user decides how to tell the author.
  • In --dry-run mode, do not modify any state. Report only.
  • When a branch exists both locally and on the remote, delete both if approved. Delete local first with git branch -d <branch>, or -D after the force-delete warning, then remote with git push origin --delete <branch>.
  • Show age and last activity in relative format.

Common Rationalizations

  • "The user asked for cleanup, so --apply is implied": the default is a dry run. Print the report and wait for a re-run with --apply.
  • "The branch is stale, so -D is fine": a stale branch can hold the only copy of unmerged work. Show the force-delete warning and get a per-item answer.
  • "origin/HEAD is missing, so skip the merged scan": fall back to origin/main, then origin/master.
  • "The PR is 20 days old, close it": age alone is not staleness. Activity in the last 7 days keeps it open.
  • "The default token works for gh": the wrong account sees the wrong PRs or none. Prefix GH_TOKEN for the account read from the remote.

Red Flags

  • Stop and drop the item when a candidate branch is main, master, develop, staging, production, or matches release/*.
  • Stop after the report when the invocation lacks --apply.
  • Stop and ask again when the user's selection names an item absent from the report.
  • Stop and keep the worktree when git worktree list --porcelain shows uncommitted changes in it.

Verification

  • The report lists every category the invocation scanned, with relative ages.
  • In dry-run mode, git branch -a, git worktree list, and the open PR list are unchanged after the run.
  • With --apply, each approved branch is absent from git branch -a and each approved worktree from git worktree list.
  • Each closed PR shows the state CLOSED in GH_TOKEN=$(gh auth token --user <account>) gh pr view <number> --json state, or glab mr view on GitLab.
  • The summary counts match the items the user approved.

Related skills

  • /ship - Commit, push, and create PRs.
  • /morning - Cross-account sweep of open PRs, reviews, and issues. This skill covers one repository; that one covers every account.

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.