PR Shepherd Skill
This skill manages the post-creation phase of a Pull Request autonomously. After a PR is raised it enters a watch-and-fix loop: wait for initial feedback, address any review comments, monitor CI, and fix any failures — repeating until CI passes green.
When to Use This Skill
Use this skill immediately after a PR has been created and pushed, when you want to:
- Automatically pick up and address reviewer comments without manual prompting.
- Monitor CI continuously and fix build or test failures as they appear.
- Drive a PR to a green state with minimal user intervention.
How to Use This Skill
The preferred approach is the pr-watch background script, which polls GitHub
cheaply using only the gh CLI and invokes Claude only when there is something
actionable. This avoids wasting Claude resources on idle polling.
Using pr-watch (recommended)
Start the watcher immediately after the PR is created. The script
self-backgrounds, writes a log under tmp/, and exits once CI is green and all
review threads are resolved.
./build/scripts/pr-watch.sh <PR_NUMBER> # e.g. ./build/scripts/pr-watch.sh 574 ./build/scripts/pr-watch.sh 574 --interval 10 # poll every 10 minutes
Monitor progress:
tail -f tmp/pr-watch-<PR_NUMBER>.log
The script invokes claude -p with structured context whenever:
- A CI check-run fails (logs included in the prompt).
- A new unresolved review thread appears from an external reviewer.
It exits cleanly and logs PR #NNN is ready when all checks pass and all
threads are resolved.
Manual loop (fallback)
If pr-watch is not suitable, run this skill directly and follow the
Detailed Instructions below.
See Detailed Instructions for the full loop behaviour.
Detailed Instructions
Overview
Before starting the loop, ask the user for the polling interval:
How long should I wait between checks? (default: 10 minutes)
Accept any value in minutes. Use 10 minutes if the user does not specify.
Convert to seconds for sleep (e.g. 5 minutes → sleep 300).
The skill then runs a loop at that interval:
- Check CI status immediately — if the build is already red, fix it before waiting.
- Wait the chosen interval for CI and reviewers to produce additional feedback.
- Fetch and address all open review comments.
- Check CI status again.
- Green: loop exits — PR is ready.
- Still running: wait another interval and repeat from step 3.
- Red: investigate failures, apply fixes, push, then wait and repeat.
Step 1: Check CI Before Sleeping
Before the first sleep, check whether CI is already red. A push can immediately trigger a pre-existing failure (e.g. a broken dependency or a lint check that fires on the new code). Do not silently wait through a known-broken build.
gh pr checks
- If any check has already failed, go directly to Step 5 and fix it before sleeping.
- If checks are pending or all green, proceed to Step 2.
Step 2: Wait for Additional Feedback
After confirming CI is not already red, pause for the chosen interval to allow CI to complete and reviewers to post comments.
sleep <interval_in_seconds>
Step 3: Fetch and Address Review Comments
Retrieve all unresolved review comments on the PR:
gh pr view --comments
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments
For each open comment:
- Read the comment carefully and understand the requested change.
- Apply the fix in the relevant source file(s).
- Stage and commit the change:
git add <modified-files>
git commit -m "[component] Address review comment: <brief description>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>"
- Push all accumulated commits once all comments in the current batch are addressed:
git push
- Required: reply to each review comment on GitHub, referencing the fix commit. Do not skip this step — the reviewer must be able to see what changed and in which commit.
gh api repos/{owner}/{repo}/pulls/{pr_number}/comments/{comment_id}/replies \
-X POST -f body="Fixed in commit <sha> — <brief description of what was changed>."
- Required: resolve each review thread on GitHub using the GraphQL API. Threads must be marked resolved so the PR dashboard shows no outstanding comments. First, get the thread IDs:
gh api graphql -f query=' { repository(owner: "{owner}", name: "{repo}") { pullRequest(number: {pr_number}) { reviewThreads(first: 50) { nodes { id isResolved comments(first: 1) { nodes { databaseId body } } } } } } }'
Then resolve each unresolved thread:
gh api graphql -f query="mutation { resolveReviewThread(input: {threadId: \"<thread_id>\"}) { thread { isResolved } } }"
Important: never amend existing commits — always create new commits for fixes. This preserves the review history.
Step 4: Check CI Status
Query the current state of all CI checks on the PR:
gh pr checks
Interpret the result:
| Outcome | Action |
|---|---|
| All green (pass) | Loop exits. PR is ready to merge. |
| Pending/queued | Wait the chosen interval, then return to Step 3. |
| Any failure | Investigate and fix (see Step 5), then repeat. |
Step 5: Fix CI Failures
When one or more checks are red:
- Identify the failing check:
gh run list --branch <branch-name> gh run view <run-id> --log-failed
- Read the failure output carefully. Common categories:
- Compilation errors: fix the offending source files.
- Test failures: fix or update the failing tests.
- Linting / formatting: apply the required formatting fixes.
- Schema validation: re-run
validate_schemas.shlocally and fix warnings.
- Apply the fixes, commit, and push:
git add <modified-files>
git commit -m "[component] Fix CI failure: <brief description>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>"
git push
- Return to Step 2 (wait the chosen interval) and repeat the loop.
Loop Termination
The loop terminates when gh pr checks reports all checks as passed. At that
point inform the user:
All CI checks are green. The PR is ready to review and merge.