Watch CI
Monitor the current branch's PR for CI failures and review comments. Fix issues automatically and loop until clean.
Flow
┌─► gh pr checks --watch (blocks, zero tokens) │ │ │ pass ▼ fail │ ┌────┴────┐ │ │ │ │ │ Read logs, diagnose, fix, push │ │ │ │ └────┬────┘ │ │ │ Check for unaddressed review comments │ │ │ none ▼ found │ ┌────┴────┐ │ │ │ │ │ Address comments, push │ │ │ │ └────┬────┘ │ │ │ ▼ │ CI still running? ──yes──► loop back │ │ │ no, all green │ ▼ │ Done ✓ └─────────────────────────────────
Steps
- Find the PR
gh pr view --json number,title,headRefName,url --jq '{number, title, headRefName, url}'
If no PR exists for the current branch, tell the user and exit.
- Wait for CI
Run this and let it block — it costs zero tokens while waiting:
gh pr checks --watch --fail-fast 2>&1
This blocks until all checks complete. Capture the exit code and output.
- Handle CI result
If CI passes (exit 0): proceed to step 4.
If CI fails (exit non-zero):
-
Get the failed check names from the output
-
Fetch the logs for each failed run: gh run view <run-id> --log-failed 2>&1 | tail -200
-
Diagnose the root cause from the logs
-
Fix the issue — edit files, run tests locally to verify
-
Commit and push: git add -A && git commit -m "fix: address CI failure - <brief description>" git push origin HEAD
-
Go back to step 2 (wait for CI again)
Max 3 fix attempts. If CI still fails after 3 pushes, report the situation to the user and stop.
- Check for review comments
gh pr view --json reviewDecision,reviews,comments --jq '{ reviewDecision, reviews: [.reviews[] | select(.state != "APPROVED" and .state != "DISMISSED") | {author: .author.login, state: .state, body: .body}], comments: [.comments[] | {author: .author.login, body: .body}] }'
Also check inline review comments:
gh api repos/{owner}/{repo}/pulls/{number}/comments --jq '[.[] | select(.position != null) | {path: .path, line: .line, body: .body, author: .user.login}]'
If there are unaddressed review comments or changes requested:
-
Read and understand each comment
-
Make the requested changes
-
Commit and push
-
Go back to step 2
If review is clean or approved: proceed to step 5.
- Report
Print a summary:
-
PR URL
-
CI status (green)
-
Review status
-
What was fixed (if anything)
If $ARGUMENTS contains --once , stop here. Otherwise, ask the user if they want to keep watching.