Coderabbitloop
Fix every actionable CodeRabbit finding on a PR, answer each thread, resolve it, and keep going until CodeRabbit has nothing left to say (or a finding needs a human call).
Inputs
- PR number (optional): detect from the current branch if not given.
How CodeRabbit actually posts (verified against docs.coderabbit.ai and a live install: don't assume otherwise)
CodeRabbit runs as coderabbitai[bot] and posts two independent things, not one:
- An auto-generated walkthrough/summary issue comment: body starts with the HTML marker
<!-- This is an auto-generated comment: summarize by coderabbit.ai -->. This is a description, not a review: use it for context only, never as a source of fixable findings. - A formal PR review carrying one inline review comment per finding, each a real, resolvable GitHub review thread at the finding's file/line. Each one contains a
<details><summary>🤖 Prompt for AI Agents</summary>block: a ready-made fix spec, CodeRabbit's own words, meant to be handed straight to an agent.
Use the inline threads as the source of truth, exactly like Greptile/Qodo: fetch via GraphQL reviewThreads, which carries native isResolved state (see references/graphql-queries.md, shared with qodoloop; only the bot login and the prompt-heading text differ).
CodeRabbit has slash commands (official, docs.coderabbit.ai/reference/review-commands), the ones this loop actually uses:
@coderabbitai review: incremental review of new changes (use this to re-trigger after a push, if automatic review-on-push is off for this repo).@coderabbitai resolve: marks all CodeRabbit threads resolved in one shot. This is a bulk escape hatch, not the default path: this loop resolves threads one at a time, right after replying to each, so the reply-then-resolve record stays intact per finding.- CodeRabbit also has its own built-in
@coderabbitai autofix, which commits fixes directly without a model in the loop. Mention it to the user as an alternative if they'd rather skip the loop entirely, but this skill's whole point is the Claude-orchestrated version: don't default to autofix instead of doing the work.
Rate limit is a real terminal state, not a bug. A comment reading "you've reached your PR review limit" (confirmed live wording) means CodeRabbit will not review again this cycle: stop and report it, don't loop waiting for something that isn't coming.
Instructions
1. Identify the PR
gh pr view --json number,headRefName,headRefOid -q '{number, branch: .headRefName, sha: .headRefOid}'
Check out the branch if not already on it.
2. Loop (max 5 iterations)
A. Push and wait
git push
If this repo doesn't auto-review on push, nudge it:
gh pr comment <PR_NUMBER> --body "@coderabbitai review"
Poll (every ~10s, timeout ~5min) for CodeRabbit's next formal review to land: a new entry in gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/reviews from coderabbitai[bot] created after this push. If you instead see a rate-limit comment ("review limit"), stop the loop now and go to Report with blocked: rate-limited.
B. Fetch unresolved findings
Run the unresolvedQodoThreads-shaped query in references/graphql-queries.md (filter author.login == "coderabbitai[bot]" instead of Qodo's login). For each unresolved thread, parse the finding text and the Prompt for AI Agents block (heading text is 🤖 Prompt for AI Agents, not Agent Prompt: match case/emoji-insensitively).
C. Check exit conditions
Stop if there are zero unresolved CodeRabbit threads, or max iterations reached.
D. Fix each finding
For each thread, in order: read the Prompt for AI Agents block in full: it names the issue and the fix. Apply it, staying inside its stated scope. If the suggestion is wrong, unsafe, or needs a product decision, don't force it: note that in step E instead.
E. Answer and resolve
Reply to the thread first, then resolve it, the "answer to the comments" half of the job:
gh api graphql -f query='mutation { addPullRequestReviewThreadReply(input: {pullRequestReviewThreadId: "<THREAD_ID>", body: "<REPLY>"}) { comment { id } } }'
Reply body: one or two sentences, what you changed and why, or exactly why you didn't fix it. Then resolve (resolveReviewThread). A finding you deliberately skip still gets a reply and gets resolved.
F. Commit and push
git add -A
git commit -m "address CodeRabbit review feedback (coderabbitloop iteration N)"
git push
Go back to step A.
3. Report
| Field | Value |
|---|---|
| Iterations | N |
| Findings resolved | N |
| Findings skipped | N (with reasons) |
| Remaining | N (if any) |
| Blocked | rate-limited / max-iterations / none |
Coderabbitloop complete.
Iterations: 2
Resolved: 4 (3 fixed, 1 false-positive, replied + resolved)
Remaining: 0
References
references/graphql-queries.md: shared withqodoloop: the exactreviewThreadsquery and theresolveReviewThread/addPullRequestReviewThreadReplymutations. Swap the author-login filter tocoderabbitai[bot]and the prompt-heading match toPrompt for AI Agents.