/dev-kit:pr-shepherd [PR …] [iteration]from dev-kit
Automates fixing CI failures and review comments on a pull request (or stack of PRs) in a self-paced loop, committing and pushing fixes and replying to review threads.
Ships in dev-kit. 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.
None: SKILL.md is the whole skill.
Arguments: $ARGUMENTS
Invoking this skill authorizes every commit and push it describes, on the branches of the PRs it shepherds only. It does not cover merging or rebasing the base into the branch (the stack merge under Entry is the one exception), resolving conflicts, force-pushing, or changing the PR itself (close, reopen, base, title, body unless this skill's step says so); a later user message grants one of these only when it names it explicitly. This invocation is the explicit, per-branch consent that repository rules reserving git push for humans ask for; say so once in the first status line. The user running it is the PR's owner. It runs unattended with one exception: a review decision (step 3) is the owner's call, so it asks them. Wherever else it needs a human, it stops (below) with a report instead of asking.
This skill body is one iteration of a self-paced /loop. When the arguments carry iteration, or this turn is already a /loop fire, run the iteration. Otherwise invoke the loop skill with the arguments /dev-kit:pr-shepherd <PR numbers, if any> iteration and end the turn: the loop runs the first iteration at once and paces the rest. When the loop skill is unavailable, run one iteration and tell the user the loop could not start.
Every iteration re-reads the whole state from git and GitHub; the transcript of earlier iterations counts only toward the caps and for the decisions the owner deferred.
Stacks. With no PR number in the arguments, the PR is the current branch's; with one, it is that PR, and when the current branch is not its headRefName, steps 1–3 run in a worktree on that branch, as for a stack: never pull, commit or push from another branch. With several, they form a stack: run steps 1–3 for each PR in its own worktree on its head branch (git worktree add <dir> <headRefName> outside the repository, or the worktree git worktree list already shows on that branch), lowest PR first. A fix lands on the lowest branch in the stack that owns the code and reaches the PRs above it by a plain merge of base into child: after pushing the base, run git fetch and git merge --no-edit origin/<baseRefName> in the child's worktree, then push the child, one level at a time. Never rebase. This is the one exception to the base-merge ban, and only between branches of the set; merging the default branch into any of them stays forbidden. When such a merge conflicts, git merge --abort and stop, naming the files. Mergeability is judged per PR, as GitHub reports it. Step 4 decides over the whole set: done needs every PR done, and a stop that fires for one PR stops the loop once every PR has finished this iteration's steps 1–3.
To stop: call ScheduleWakeup with stop: true (on a fixed-interval loop, delete its job with CronDelete instead), then write the final report.
gh pr view [<N>] --json number,url,state,headRefName,baseRefName,headRefOid,mergeable, with <N> the PR number when the arguments name one. No PR for the current branch, or state is not OPEN: stop.git status --porcelain and git fetch, then git rev-list --left-right --count HEAD...origin/<headRefName> (@{u} may be unset). A dirty tree, local commits ahead of the remote, or a diverged branch: stop, naming which; those changes are the user's. Untracked files (??) do not block, but are the user's: never stage them. Behind only: git pull --ff-only origin <headRefName>.mergeable == "CONFLICTING": trust GitHub. Never argue it away with a local merge check, and never close, reopen, retarget or edit the PR to make GitHub recompute; a stacked PR conflicts through its whole base chain down to the default branch. Skip step 2 (GitHub runs no pull_request CI on a conflicting PR), finish step 3 and push, then stop, naming the conflicting files (git merge-tree --write-tree --name-only HEAD origin/<baseRefName>, or the lower branch of the chain where the conflict sits) and saying that re-running before the conflict is resolved repeats this stop. Resolving it is the user's call: the stop report suggests /dev-kit:merge-in-head (in that PR's worktree for a stack), which merges the base in and resolves the conflicts, and never invokes it. UNKNOWN is still computing and blocks nothing.gh pr checks --json name,bucket,state,link,workflow for every check, and the same with --required for the required ones; when none is required, every check counts as required. gh pr checks exits non-zero while any check is pending or failing, and with --required when no check is required, even though its JSON is complete: read the JSON, never its exit code, and never chain the call with &&. pass and skipping (skipped, neutral) are green; fail and cancel are red; pending, or no checks reported yet for the head commit, is pending. A red non-required check is sent to ci-fix once; when it stays red after that, it goes under left-to-the-user in the report instead of blocking done.OWNER/REPO filled by gh and N the PR number:gh api graphql --paginate -F owner='{owner}' -F repo='{repo}' -F number=N -f query='
query($owner: String!, $repo: String!, $number: Int!, $endCursor: String) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $number) {
reviewThreads(first: 50, after: $endCursor) {
pageInfo { hasNextPage endCursor }
nodes {
id isResolved isOutdated path line viewerCanReply viewerCanResolve
comments(first: 100) {
nodes { author { login __typename } viewerDidAuthor createdAt url body }
}
}
}
}
}
}' --jq '.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved | not)'
Classify each unresolved thread by its last comment:
viewerDidAuthor false). It needs handling this iteration.Every red check goes through ci-fix; never fix or rerun CI directly in this skill. When a required check is red, or a red non-required one has not had its ci-fix run yet, invoke dev-kit:ci-fix with the arguments <PR url> push-authorized, plus checkout=<dir> when this PR's steps run in a worktree, and read its result block:
fixed or rerun: CI restarts; continue.nothing-to-fix: the red check went green or pending meanwhile; continue.not-fixable or blocked: finish step 3, then stop with ci-fix's cause and next.Fix cap: count every fix or rerun cycle on a check, whichever step made it (a ci-fix run reporting fixed or rerun, or a review fix aimed at that check). When the same check is red again after two such cycles, stop instead of invoking ci-fix a third time; the cycle needs a human.
Take every open thread, reading the whole thread, the code at path/line on HEAD, and the PR's intent. Also read the reviews bodies and the PR conversation comments, trimmed to what judging needs:
gh pr view <N> --json comments,reviews --jq '{comments: [.comments[] | {author: .author.login, url, createdAt, body: .body[0:500]}], reviews: [.reviews[] | select(.body != "") | {author: .author.login, state, submittedAt, body: .body[0:500]}]}'
They have no resolution state, so they sit outside the exit condition, but a concrete change request in one that no later comment of ours links to is handled like a thread, answered once with gh pr comment <N> --body that links its URL (a review has none: name its author and submittedAt). Read a truncated body in full only when it holds such a request.
Judge each comment on its merits, whoever wrote it, into one verdict:
git log). Stage by explicit file path (git add <file>…), never a directory, -A or -a.An outdated thread (isOutdated) whose point a later commit already addresses, or a thread whose point another PR in the stack already fixes, is justified with that commit as its fix. Two comments demanding incompatible changes: a human's outranks a bot's (the bot's gets a rebuttal naming the human's thread); between two humans, it is a decision whose options include each human's change. A thread already holding two rebuttals of ours is left to the user: list it in the report and post nothing more.
Asking for decisions. Once every thread is judged, and before committing, collect this PR's decisions and ask about them together, so the chosen changes land in this PR's push; in a stack, each PR asks in its own step 3. AskUserQuestion has room only for short labels, so first write the decisions out in prose. For each one, give the thread URL, what the reviewer asks for and why, then every option with what it changes and what it costs, and which one you recommend and why. Only then call AskUserQuestion: one question per decision, naming the thread, with each option's label matching the prose. Put the recommended option first, marked (Recommended). Offer a "leave as is" option whenever keeping the code unchanged is a real option. The tool takes at most four questions per call, so with more decisions, make further calls. Act on each answer:
After the fixes are committed, git push once per branch, then post and resolve through GraphQL (THREAD_ID is the thread's id):
gh api graphql -F threadId=THREAD_ID -f body="$BODY" -f query='
mutation($threadId: ID!, $body: String!) {
addPullRequestReviewThreadReply(input: {pullRequestReviewThreadId: $threadId, body: $body}) { comment { url } }
}'
gh api graphql -F threadId=THREAD_ID -f query='
mutation($threadId: ID!) { resolveReviewThread(input: {threadId: $threadId}) { thread { isResolved } } }'
Fixed in <short SHA>. (Fixed in <short SHA> (#<PR>). when another PR in the stack carries it) with one line on what changed, then resolve.author.__typename == "Bot"): post the reply, then resolve.A deferred decision gets no reply and stays unresolved; it is handed over. A thread with viewerCanReply or viewerCanResolve false goes into the report unhandled.
Done when every required check is green, every red non-required check has had its one ci-fix run, and no unresolved thread remains: stop, reporting success.
Otherwise stop when one of these holds:
viewerCanReply/viewerCanResolve false) or awaiting a human whose newest reply of ours is older than 24 hours: nothing left is ours to move.Else call ScheduleWakeup for the next iteration, choosing the delay by what is still moving:
End every iteration with one status line (one per PR in a stack): checks green/red/pending counts, threads open/awaiting, and what this iteration did.
On every stop: why it stopped; commits pushed during the loop (short SHA and subject); threads fixed, rebutted and answered, with URLs; decisions the owner made, with the option chosen; every thread or check left to the user, each deferred decision with its options, and what it needs from them.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub grixu/cc-toolkit --plugin dev-kit5 skills in this plugin
/ci-fixFix a failed CI pipeline at its root cause, verify locally, and commit. Use when the user pastes a GitHub Actions run, job, PR or commit-checks URL, says CI, a pipeline or a build is red, or another skill hands over a failing check./dep-upgrade-checkDependency upgrade compatibility and security check. Gates the target version on known vulnerabilities, malware, and release age, finds everything that changes between the version a codebase resolves today and the target, maps each change to where the code uses it, and returns a safe / safe with changes / breaking verdict with file:line evidence. Use when the user names a package and a target version, links a Renovate or Dependabot pull request, or asks whether bumping a dependency will break the build./Other plugins' skills for the same job