pr-cleanup
Skill11 starsChanged 7 days agoMITView on GitHub
Single-lane interval watcher that tidies up after agent PRs close — the post-merge janitor lane of a multi-agent fleet. Acts ONLY on closed PRs — deletes merged local branches, removes spent worktrees, closes the linked GitHub/Jira issue on merge, and releases the claim lock. Critical when PRs land on an integration branch (not the repo default), because GitHub then does NOT auto-close "Closes #N" issues. A PR closed WITHOUT merging leaves its issue open and re-dispatchable (lock released but issue not closed). Loops on an interval ("/loop <interval> start"). Use when running a cleanup lane, when merged issues stay open, when local disk/worktrees pile up, or when a dead dispatch leaks a lock.
4 other projects use a version of this.
Adopted by
Most recently taken up by
- mjswensen/skillstheir own version, first seen Nov 15, 2026
- lbruton/SessionFlowtheir own version, first seen Nov 1, 2026
- springfall2008/batpredtheir own version, first seen Oct 8, 2026
- hraness/personal-monorepo-templatetheir own version, first seen Sep 28, 2026
Other versions4 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 4
- springfall2008/batpred★ 376same name
- hraness/personal-monorepo-template★ 4same name
- lbruton/SessionFlow★ 1same name
- mjswensen/skills★ 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 repository34 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- browser-diagnosisSkill
- cavemanSkill
- ci-flake-huntingSkill
- ci-speed-huntingSkill
- deploy-watchingSkill
- dispatching-subagentsSkill
- doc-coauthoringSkill
- docxSkill
- driving-prs-to-mergeSkill
- fast-forwarding-branchesSkill
- figmaSkill
- figma-specsSkill
- gh-issue-filingSkill
- gh-issue-labelsSkill
- gh-issue-lockingSkill
- grooming-issuesSkill
- humanizerSkill
- jira-issue-fieldsSkill
- jira-issue-filingSkill
- jira-issue-lockingSkill
- mcp-builderSkill
- orchestrating-slotsSkill
- pdfSkill
- pptxSkill
- pr-checksSkill
- pr-commentsSkill
- skill-creatorSkill
- spelunking-specsSkill
- technical-reconSkill
- token-bleed-huntingSkill
- xlsxSkill
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 4 edited versions we read keep these.
0
Distinctive
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
- Very specific: line 45
Salvage caution: before deleting any worktree/branch, confirm it belongs to a closed PR and not to in-flight work — a parallel actor may …
“Common” is measured: kept by at least 6 in 10 of the 4 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.
Files
PR Cleanup Watcher
One job: tidy up after PRs close. When <integration-branch> is not the repo's default branch, GitHub does not auto-close Closes #N issues (the PR lands off the default branch), so closure is manual. Reclaim local disk, close the linked issue, release the lock. Nothing else.
This skill builds on the lock-release protocol in the issue-locking skill (gh-issue-locking for GitHub, jira-issue-locking for Jira) and the worktree/branch hygiene in dispatching-subagents. It adds the single-lane watcher loop and the merged-vs-abandoned close-out split.
Project bindings
Project-agnostic; the adopting project defines these in its own CLAUDE.md. Used here:
| Placeholder | Meaning |
<owner>/<repo> | GitHub repository slug |
<integration-branch> | Branch PRs target; if it is NOT the repo default, Closes #N does not auto-close — closure is manual |
<default-branch> | The repo's default branch (GitHub only auto-closes issues for PRs merged into this) |
<worktree-dir> | Where feature branches live on disk (see dispatching-subagents) |
<claim-lock> | The active-claim marker — a label (agent-claimed) + assignee on GitHub, the equivalent field on Jira (see the issue-locking skill) |
<tracker-key> | Linked tracker reference convention (a GitHub #N, a Jira issue key) |
The watcher model
A single-lane, interval-driven loop — one concern, scanned end-to-end every tick (/loop <interval> start). Distinct from the N-slot event loop in orchestrating-slots and the one-shot pr-rescuer. One watcher per lane; lanes do not cross.
This lane is light and read-mostly — cleanup is bounded shell + tracker API. Run it on the workhorse tier and delegate noisy scans (branch lists, worktree audits) to the cheap tier (caveman:cavecrew-investigator, or a fixed command parsed), keeping output compressed. It writes no application code, so there is no fix-sub-agent slot count here.
Lane (do not cross)
You OWN: deleting merged local branches, removing spent <worktree-dir>/* worktrees, closing linked issues on merge, releasing the <claim-lock> (removing the claim marker + clearing assignee).
You do NOT touch: dispatching issues (the dispatch lane — dispatching-subagents / orchestrating-slots), CI/conflicts/queue (the pr-checks lane), open review threads (the pr-comments lane), deploy/infra health (a deploy lane, if your fleet runs one). Act on closed PRs only (MERGED or closed-unmerged) — never on open PRs, and never force a merge.
Each loop tick
Agent PR (shared definition across lanes): a closed PR — merged OR closed-unmerged — whose author OR assignee = your login (gh api user --jq .login). Scope to YOUR login only; never clean another operator's branches/worktrees/issues.
- Find recently closed agent PRs not yet cleaned (both MERGED and closed-unmerged).
- MERGED → full close-out (see the issue-locking skill's close-on-merge protocol): close the linked issue (
Closes #N) and/or transition the Jira issue to its done state, remove the<claim-lock>claim marker, clear the assignee, post a brief closing note. - Closed-unmerged (abandoned PR) → release the lock so the issue is re-dispatchable: remove the claim marker, clear the assignee, post a note that the PR closed without merging. Do NOT close the issue — leave it open. This is the backstop for a dispatch that opened a PR then died: the lock is freed but the work is still tracked.
- Local cleanup (either case): delete the closed branch,
git worktree removethe spent worktree under<worktree-dir>, prune. - Salvage caution: before deleting any worktree/branch, confirm it belongs to a closed PR and not to in-flight work — a parallel actor may own it (see Stalled-agent recovery in
dispatching-subagents). When unsure, skip and report; do not delete.
Why this lane exists (the auto-close gap)
GitHub auto-closes an issue from Closes #N only when the PR merges into <default-branch>. Fleets that integrate on a separate <integration-branch> never trigger that — so without this lane, merged issues stay open, claim locks go stale, and the dispatch lane re-picks zombie issues that are already done. Closing on merge is therefore mandatory here, not optional. (Same reasoning as the close-on-merge sweep in orchestrating-slots; this lane is the dedicated watcher form of it.)
Token discipline: caveman for ops, humanizer for prose
This lane runs in a repetitive loop. Operate in caveman mode (load the caveman skill) for working output. Delegate noisy scans (branch lists, worktree audits) to the cheap tier and parse a fixed command's output rather than reading it whole.
Report per tick: closed N (merged M / abandoned A), issues closed: #x, locks released: #y, branches/worktrees removed: K.
Caveman compresses prose only — never machine-precise content: gh/git/tracker commands, label and field names, the <claim-lock> markers, <tracker-key> references stay byte-exact. The closing comment a human reads is the exception: write it normally, through the humanizer skill.
Stop conditions
Nothing closed-and-uncleaned → nothing to clean and end the tick. The loop re-fires on its interval.
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
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.

