Watch a PR's GitHub Actions CI, automatically fix failures, and push until green. Use this skill whenever the user says "babysit", "watch ci", "fix ci", "make ci green", "monitor the PR", "keep pushing until green", or after creating a PR when they want hands-off CI resolution. Also use proactively after /commit or /pr when CI is likely to run and the user seems done coding.
Watch a PR's CI pipeline. When checks fail, read the logs, fix the code, commit, push, and repeat until everything is green. The goal: the user invokes this once and walks away.
Parse $ARGUMENTS for a PR number or branch name. If empty, detect from the current branch:
# Get PR for current branch
gh pr list --head "$(git branch --show-current)" --json number,url,title --jq '.[0]'
If no PR exists for the branch, tell the user and stop.
Store the PR number and branch name — you'll need them throughout.
Run this cycle up to 5 times. If CI still fails after 5 fix attempts, stop and report what's left — the issue likely needs human judgment.
Poll the CI status. CI workflows typically take a few minutes.
gh pr checks <PR> --watch --fail-fast 2>&1
This blocks until all checks complete or one fails. If the command isn't available or hangs, fall back to polling:
gh run list --branch <branch> --limit 1 --json status,conclusion,databaseId,name
Poll every 30 seconds. A run is done when status is completed.
gh pr checks <PR> --json name,state,description
If all checks pass → done. Report success and stop.
If any check failed → continue to Step 3.
Find the failed run ID, then fetch only the failed output:
# Get the failed run ID
gh run list --branch <branch> --limit 1 --json databaseId,conclusion --jq '.[] | select(.conclusion == "failure") | .databaseId'
# Get failed job logs (this is the key command — only shows what broke)
gh run view <run-id> --log-failed 2>&1
--log-failed returns only the output from failed steps, which is exactly what you need to
diagnose the issue. Read it carefully.
Read the failure logs and categorize the issue:
Auto-fixable failures — many CI failures can be fixed by running a formatter or fixer tool
locally. Check the project for linting/formatting commands (e.g., prettier --write, eslint --fix,
black, cargo fmt, gofmt, php-cs-fixer fix). Run the appropriate fixer, verify locally, then
commit.
Code change failures — for type errors, test failures, build errors, or static analysis issues:
Stage only the fix files. Use a conventional commit message that references the CI failure:
git add <specific-files>
git commit -m "$(cat <<'EOF'
fix(<scope>): <what was fixed>
CI fix: <which check failed and why>
Co-Authored-By: Claude <[email protected]>
EOF
)"
git push
Important: Verify upstream before pushing:
git rev-parse --abbrev-ref @{upstream}
If it shows a main/default branch instead of the feature branch, fix with git push -u origin HEAD.
After pushing, go back to Step 1. The push triggers a new CI run automatically.
After each iteration, give a brief status update:
## Babysit — Iteration 2/5
Fixed: Type error in AuthService.ts (missing null check)
Pushed: abc1234
Waiting for CI run #12345...
When done (success or max iterations reached):
## Babysit — Complete
PR #42: Fix authentication flow
Status: All checks passing
Iterations: 2 (1 fix applied)
Fixes applied:
1. fix(auth): add null check for token expiry — TypeScript
Or if still failing after max iterations:
## Babysit — Stopped (5/5 iterations)
PR #42: Fix authentication flow
Status: 2 checks still failing
Remaining failures:
- test-unit: AuthServiceTest::testRefresh — assertion mismatch
- lint: 3 unresolved warnings in src/auth/
These likely need manual investigation. Run `gh run view <id> --log-failed` to see details.
gh run rerun <id> --failed.