From manage-pr
Create a PR and monitor it until CI passes and all comments are addressed
How this command is triggered — by the user, by Claude, or both
Slash command
/manage-pr:manage-pr [base-branch] [--ci-interval SECONDS] [--comment-interval SECONDS] [--rebase]This command is limited to the following tools:
The summary Claude sees in its command listing — used to decide when to auto-load this command
## Preflight Check
Verify that `gh` is installed and authenticated:
If the preflight check failed, inform the user and stop. Do not proceed with any other phases.
## Context
- Current git status: !`git status`
- Current git diff (staged and unstaged): !`git diff HEAD`
- Current branch: !`git branch --show-current`
- Recent commits on this branch: !`git log --oneline -10`
- Remote tracking: !`git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "No upstream set"`
## Parse Arguments
Parse `$ARGUMENTS` for the following options. All are optional:
- **Base branch**:...Verify that gh is installed and authenticated:
gh auth status 2>&1 || echo "PREFLIGHT_FAILED: gh CLI is not installed or not authenticated. Install it from https://cli.github.com/ and run 'gh auth login'."
If the preflight check failed, inform the user and stop. Do not proceed with any other phases.
git statusgit diff HEADgit branch --show-currentgit log --oneline -10git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null || echo "No upstream set"Parse $ARGUMENTS for the following options. All are optional:
--). Defaults to main, or master if main doesn't exist on the remote.--ci-interval SECONDS: How often to poll CI status, in seconds. Default: 15.--comment-interval SECONDS: How often to poll for new review comments, in seconds. Default: 60.--rebase: Before pushing, rebase the branch onto the latest HEAD of the base branch. Resolves conflicts if possible; if conflicts cannot be resolved automatically, stop and ask the user for help.Before starting the workflow, run the following commands so the user can approve all necessary permissions up front rather than being prompted mid-workflow. Run all of these in a single message:
git status — git read accessgit add --dry-run . — git staginggh pr list --limit 1 — gh PR read accessgh pr checks --help 2>/dev/null || true — gh CI status accessgh api rate_limit — gh API accessgh run list --limit 1 — gh run log accessThese are no-ops that establish the permission patterns (git:*, gh pr:*, gh api:*, gh run:*) so the user won't be interrupted during the actual workflow.
Execute each phase in order.
main or master, create a new descriptive branch first.--rebase was specified, rebase onto the latest base branch:
git fetch origin <base-branch>git rebase origin/<base-branch>-u to set upstream). If the rebase rewrote history, use --force-with-lease (never --force).gh pr create against the base branch. Write a clear title and body summarizing the changes. Include a ## Test plan section.If a PR already exists for this branch, skip creation and use the existing PR.
After creating (or finding) the PR, monitor both CI status and review comments simultaneously. Do not wait for CI to pass before checking comments — address both as they come in.
Monitoring loop:
On each iteration of the loop:
Check CI status: Run gh pr view <number> --json statusCheckRollup to get current check status.
Check for review comments: Run gh pr view <number> --json reviews,comments and gh api repos/<owner>/<repo>/pulls/<number>/comments to find unaddressed review comments. Only consider comments whose body starts with Claude: or @Claude (case-insensitive). Ignore all other comments — they are meant for human reviewers, not for this tool.
Take action on whatever needs attention:
If there are unaddressed review comments (starting with Claude: or @Claude):
gh pr comment or gh api to reply to the specific review comment.If CI has failed:
gh pr checks <number>.gh run view <run-id> --log-failed (get the run ID from checks output).Transient / infrastructure failures — rerun without code changes:
These are failures unrelated to the code in this PR. Rerun them with gh run rerun <run-id> --failed and continue monitoring. Examples:
Flaky tests — rerun if unrelated to current changes: If a test failure does not have a clear connection to the changes in this PR, it is likely flaky. To decide:
gh run rerun <run-id> --failed.Do not rerun the same failed job more than 2 times. If it fails a third time, treat it as a real failure.
Real failures — fix the code: If the failure is clearly caused by changes in this PR (compilation error, test assertion directly related to modified code, linting error on changed files):
If both comments and CI failures exist, address the review comments first (since the push to fix comments will trigger a new CI run anyway, and the CI failure may be related to the requested changes).
After pushing any changes or rerunning a job, sleep for the CI interval and loop back to step 1 to monitor the new run.
If nothing needs attention (CI is still pending, no new comments), sleep for the CI interval and check again. Time out after 30 minutes of no progress.
If CI fails more than 5 times consecutively on the same check (not counting transient/flaky reruns), stop and ask the user for help.
Exit condition: CI is green AND there are no unaddressed Claude:/@Claude review comments. Proceed to Phase 3.
CI is green and all comments are addressed. Display a summary:
The workflow is now complete. If new comments arrive later, the user can run /manage-pr again.
--rebase was specified, in which case use --force-with-lease (never --force) only after a rebase.gh api for operations not directly supported by gh pr subcommands (e.g., replying to specific inline comments).npx claudepluginhub shawnburke/claude-plugins --plugin manage-pr