一键导入
pr-cleanup
// Find and close stale GitHub PRs. Surveys all open PRs for the authenticated user, identifies those with no activity beyond a configurable threshold (default 30 days), and bulk-closes them after confirmation.
// Find and close stale GitHub PRs. Surveys all open PRs for the authenticated user, identifies those with no activity beyond a configurable threshold (default 30 days), and bulk-closes them after confirmation.
| name | pr-cleanup |
| description | Find and close stale GitHub PRs. Surveys all open PRs for the authenticated user, identifies those with no activity beyond a configurable threshold (default 30 days), and bulk-closes them after confirmation. |
Find all open PRs authored by the authenticated GitHub user, identify stale ones, and close them after user confirmation.
The user may pass a number of days as the staleness threshold. Default is 30 days. Examples:
/pr-cleanup — PRs with no activity in 30+ days/pr-cleanup 14 — PRs with no activity in 14+ days/pr-cleanup 90 — PRs with no activity in 90+ daysgh api user --jq '.login'
If this fails, stop and tell the user to authenticate with gh auth login.
gh search prs --author=<login> --state=open \
--json repository,title,url,createdAt,updatedAt,state,number,isDraft \
--limit 100
Compare each PR's updatedAt against today's date minus the
staleness threshold. A PR is stale if it has had no activity
(no commits, comments, reviews, or label changes) within the
threshold period.
Show the user a summary with two sections:
Active PRs (within threshold) — brief count and list so the user knows what's being kept.
Stale PRs (beyond threshold) — full table:
| # | Repo | Title | Last Activity |
|---|
Sort stale PRs by last activity date, oldest first.
If there are no stale PRs, say so and stop.
Ask the user what to do using AskUserQuestion:
Do NOT close any PRs without explicit user confirmation.
For each PR to close, run:
gh pr close <number> --repo <owner/repo> \
--comment "Closing — this PR has gone stale and is no longer being actively pursued. (Automated cleanup by agent)"
Run close commands in parallel (up to 10 at a time) for speed.
If a close fails with a transient error (HTTP 504, timeout), retry once after a brief pause. If the retry also fails, report the failure and continue with the remaining PRs.
After all closures complete, show a summary: