/ci-watch:ci-watchfrom ci-watch
Use when asked to "merge when green", "merge this once CI passes", "watch CI" or "babysit this PR", when a PR was just opened, and when the ci-watch hook says a PR was opened. Waits for CI as an event, fixes red CI, merges a green PR that was asked for, and follows a merged feat or fix to its release. Skip for merging release PRs, which is always the operator's call.
Ships in ci-watch. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Let CI results drive the work. Three stages: Wait, Merge, Release. The hook starts Wait when a PR is opened. It never merges; a merge happens only when the operator asked for it for this PR, or for the run's own item PR in an unattended run.
In an unattended run ci-watch never parks anything and never sets an item status. It returns an outcome (merged, red after three fix rounds, circling, timed out, no checks, rules not met, release PR, rules unreadable) and a reason to the unattended skill, whose queue step 8 decides what happens to the item.
Credit: the merge flow is adapted from merge-when-green in Devleaps/tempa-config-template (MIT), without its Tempa MCP calls. See NOTICE.md.
Pick the mechanism once per PR. Probe gh with gh auth status and gh pr view <n>: a cloud session can have a gh binary that only searches.
| Session | Mechanism |
|---|---|
SUPERPOWERS_UNATTENDED=1 with gh | Foreground gh pr checks <n> --watch --interval 30 with the Bash timeout at its maximum of 10 minutes, repeated until every check has finished. |
Unattended without gh | No wait. The item ends at an open PR, with "CI not watched: no gh" in the run file. |
Interactive with gh | The same command with run_in_background, then end the turn; you are re-invoked when it exits. Without run_in_background, use the foreground loop. |
No gh for PRs, as in cloud sessions | subscribe_pr_activity for the PR, then end the turn; the CI event wakes the session. |
In a repo that CodeRabbit reviews, an attended run uses the coderabbit-merge skill before the Merge stage. An unattended run does not merge there and returns "rules not met: CodeRabbit".
Never use a sleep loop. In a cloud session follow the rules in the subscription.created event for handling PR events; do not restate or override them here.
Limit: wait at most 60 minutes in total for one PR, counted from its first watch. The limit covers every later wait on the same PR and never restarts: a fix push, a branch update or a resolved conflict does not give the PR a new 60 minutes. A repo can set its own in docs/planning/CONVENTIONS.md as **CI timeout:** <minutes>. The value is a positive integer: a bare number such as 120 means that many minutes, and 60 (defaulted), as init-conventions records it, means 60. A configured value is a total for the PR too. Give each watch a timeout of 10 minutes or the time left of the PR's limit, whichever is shorter, so no watch runs past the limit. When the limit passes, stop waiting, check the Circle guard once more and return "circling" when it fires. Otherwise report which checks are still pending. When unattended, return "timed out" with those checks as the reason. For the subscription mechanism, also schedule one fallback wakeup at the limit, with ScheduleWakeup or send_later, whichever the session has, so a check that never reports cannot hang the session. It fires once.
Outcomes:
pull_request event checks count. Never trigger checks another way.gh run view <run-id> --log-failed, or the check-run output through MCP.superpowers:systematic-debugging. Show the same command passing, then commit and push.Three failed fix rounds on the same PR end the loop, and the Circle guard can end it sooner: report with the failure attached. When unattended, return "red after three fix rounds" with the failure; the unattended skill parks the item. A failure clearly not caused by the branch, such as an outage or a flaky external service, is reported. Never re-run a check until it turns green.
Every way back to Wait costs the PR a round: a fix pushed for red CI, a branch brought up to date with the base, a resolved conflict, and a coderabbit-merge fix round. A PR gets four rounds in total, whatever their cause. The three fix rounds of Red CI and of coderabbit-merge count toward the four; they are not on top of them.
Stop instead of starting a fifth round. Stop at once, with rounds left, when a round made no progress:
When it stops, report each round with its cause and what is still failing or open. Unattended: return "circling", with the rounds and anything still red as the reason. Never start another round to try once more.
Runs only on an explicit request for this PR, or for the run's own item PR in an unattended run. Never for any other PR.
Stop and say why when the PR is closed, merged, a draft or conflicting. Resolve conflicts on the branch, then Wait again; that costs a round of the Circle guard. A PR that is only behind the base with no conflicts (mergeStateStatus BEHIND) is brought up to date with gh pr update-branch <n>, or update_pull_request_branch through MCP, then Wait again; that costs a round too.
Never merge a release PR. It is one when its head branch starts with release-please-- or the tool named in Released by in docs/planning/CONVENTIONS.md opened it. Ask when attended; return "release PR" when unattended.
Read the reviews and rules. Every merge runs this whole step first, including when reviewDecision is APPROVED. Never merge on a rule set that was not read.
gh pr view <n> --json reviewDecision,mergeable,mergeStateStatus,statusCheckRollup,headRefName. In cloud sessions pull_request_read returns the PR, its reviews, its mergeable state and its check runs or statuses.gh api repos/<owner>/<repo>/rules/branches/<base> lists the active rules for the base branch, including the review rule and the required status checks. gh api repos/<owner>/<repo>/rulesets/<id> returns one ruleset, with its bypass actors and whether the current user can bypass it. pull_request_read returns neither rulesets nor bypass actors. When no gh can read them, the rule set is unreadable.APPROVED, or empty because no review is required: plain merge, once every other rule is met.REVIEW_REQUIRED with the review rule as the only unmet rule: merge with --admin. First verify from the rules and the PR that every required status check passed on the current head, the branch is up to date with the base when the rule is strict, there are no conflicts, and the current user can bypass the ruleset. --admin also skips the checks, so this verification is the gate. It is never used to get past anything else.CHANGES_REQUESTED, or any other unmet rule: stop and say what is missing. Unattended: return "rules not met" with what is missing.Squash-merge with an explicit message. The subject is the PR title, unchanged. The body is the branch's commit bodies passed through the sanitizer, which removes every Co-Authored-By: Claude trailer and claude.ai/code/session_ link and turns a parenthesis nested in a parenthesised group into square brackets:
git log --format=%b origin/<base>..HEAD | node <skill dir>/scripts/ci-watch.mjs sanitize > body.txt
gh pr merge <n> --squash --delete-branch --subject "<PR title>" --body-file body.txt
Run git fetch origin <base> first so origin/<base> is fresh. In cloud sessions there is no local clone to diff: build the body from the commit messages that pull_request_read returns for the PR, pipe it through the same sanitize command, and pass it as commit_message.
Add --admin only in the case of step 3 that allows it. Cloud sessions can merge only after step 3 read the rules. Pass the same subject and body as commit_title and commit_message to merge_pull_request. Use the repo's allowed method when squash is disabled. Delete the branch.
Confirm the PR shows as merged and note the merge commit.
Report the PR, the checks that passed, the merge commit and what the merge sets in motion.
After a merged commit that release-please counts, meaning feat, fix or a breaking change, in a repo whose Released by is release-please:
gh pr list --state open --search "head:release-please--". Through MCP: search_pull_requests with the query head:release-please-- is:open for the repo.In an unattended run, steps 1 and 2 run once, after the last item: wait for the release PR and confirm every commit the run merged is in its changelog. Put the result in the run summary.
--auto.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub marcelroozekrans/superpowers-extensions --plugin ci-watch