Native PR review loop, 2.x — drives the Codex and Copilot GitHub reviewers to a clean signoff, then gates the merge. No daemon: the 1.x file bus is retired.

A team-grade code-review rhythm for solo developers. You write the code; GitHub's own reviewers, Codex and Copilot, review every pull request, and Claude Code works the fix → reply → resolve → re-request loop until they sign off. Then it stops and asks you before opening the second reviewer's phase, and again before merging, or takes the answers you gave in advance and runs unattended.
One install serves every project on your machine. No daemon: nothing keeps running between sessions.
The plugin is a driver for the native GitHub reviewers. Your session:
| Reviewer | Identity | How it is asked |
|---|---|---|
| Codex | chatgpt-codex-connector[bot] | a PR comment containing @codex review |
| Copilot | copilot-pull-request-reviewer[bot] | a review request for @copilot |
The reviewers judge relevance against what the PR says it set out to do, so the description is the one input the whole loop is calibrated on. Write it first.
Use it when a change deserves a second pair of eyes and there is nobody to ask: behaviour changes, anything touching money, auth, data loss or concurrency, a refactor you want checked, work you will not remember the reasoning behind. Skip it for a one-line typo, generated files, formatting-only commits, or a spike you will throw away. If a loop runs long, that is information: rounds that keep finding defects in the fixes usually mean the change is too large.
git, gh, jq, perl. gh must be authenticated with the repo scope (gh auth status). perl is a hard requirement: the helpers hand values to each other in files, and the shell has no safe spelling of the exclusive create and exact rename that takes. macOS ships it; on Linux, install it if your distribution does not.@codex replies with a setup link instead of a review.Works on Linux and macOS. Running one of the privileged helpers by hand goes through its #!/usr/bin/env -S bash -p shebang and needs an env that supports -S (GNU coreutils 8.30 or later, or BSD env). The skill itself never depends on it, pr-selfcheck.sh does not use it, and pr-origin.sh cannot be run by hand at all.
/plugin marketplace add p5ych0/watch-pr-skill
/plugin install watch-pr-skill@p5ych0-tools
Install once at user scope. To update:
/plugin marketplace update p5ych0-tools
/plugin update watch-pr-skill
/reload-plugins
An automatic update needs the last step too. A running session reads the new SKILL.md at its next invocation but keeps the hooks module it loaded at start, so after an automatic update run /reload-plugins or restart the session before the skill is invoked again, and the module matches the SKILL.md it serves.
What an update takes is this repository as it stands, since the marketplace tracks it rather than a tag, so CHANGELOG.md is the record of what an update brings. The newest versions are also tagged and released at github.com/p5ych0/watch-pr-skill/releases, carrying the same entries.
2.0.0 replaced the plugin rather than extending it. The file bus, its two systemd --user daemons, the codex exec reviewer and the SessionStart hook are gone; both reviewers are GitHub apps, and the plugin runs under Claude Code only. Once, before updating:
--stop included. <plugin> below is that installed copy, $CLAUDE_PLUGIN_ROOT in a 1.x session and otherwise a directory under ~/.claude/plugins/cache/ or ~/.codex/plugins/cache/. <plugin>/skills/watch-prs/scripts/review-bus-codex-start.sh --stop
systemctl --user is-active review-bus-<owner>-<repo>-watcher review-bus-<owner>-<repo>-monitor
Only once is-active prints inactive, failed or unknown for both units — a unit that is gone reads the first, or the last on an older systemd — and after checking that the second directory below holds nothing you still want:
rm -rf /tmp/<owner>-<repo>-review-bus /tmp/<owner>-<repo>-claude-worktrees
git worktree prune
--stop stops both transient units and terminates the whole process group of a daemon an earlier 1.x launched under setsid, which killing the shell alone would leave running with its codex exec child. It needs a running systemd --user; without one, signal each daemon's process group yourself. It reports success even where a unit refused to stop, which is what the check between the two blocks is for. The second directory is where 1.x put implementer worktrees by default, and git worktree prune drops the registrations they leave in .git. Where you exported BUS_DIR, the bus lived there instead, so remove that directory. Remove the clone and the worktrees too where REVIEW_BUS_REPO_CLONE or CODEX_REVIEW_WORKTREE_ROOT put them outside that directory.
codex CLI, inotify-tools and systemd are no longer needed; perl is. Link the Codex connector as under Requirements, and enable Copilot code review on the repository only where you want the Copilot phase; a Codex-only merge needs none. Then follow Per-project setup, carrying anything stack-specific in .review-bus.md into AGENTS.md and .github/copilot-instructions.md on the way and deleting it after: nothing reads it, and the conventions live in the two files the reviewers read from the base branch.CODEX_REVIEW_ROUND_THRESHOLD is REVIEW_ROUND_THRESHOLD, counting reviewed heads per reviewer where 1.x counted enqueued heads per PR, so a carried-over value pauses at a different point. Unset every old CODEX_REVIEW_* and REVIEW_BUS_* export and BUS_DIR. Most are gone — model and effort are Codex account settings, and the round pause is a stop in the session — and REVIEW_BUS_REMOTE, REVIEW_BUS_OWNER and REVIEW_BUS_REPO are test seams here, which a stale export must not reach: they retarget the session's repository identity. The current list is under Configuration.Earlier releases could leave setup directories directly in your home: ~/watch-pr-setup.* and ~/watch-pr-setup-2.*, and before those ~/watch-pr.*, ~/watch-pr-2.*, ~/watch-pr-work.*, ~/watch-pr-pin.* and ~/watch-pr-pin-2.*. From 2.11.3 setup works under TMPDIR or ~/.watch-pr instead, and nothing removes what a session made. To tidy the old ones away, first make sure no session is running — each of those directories is a session's working files — then:
{ [ -d ~/.watch-pr ] || mkdir -m 700 ~/.watch-pr; } && find -H ~ -mindepth 1 -maxdepth 1 -type d \( -name 'watch-pr.*' -o -name 'watch-pr-2.*' -o -name 'watch-pr-setup.*' -o -name 'watch-pr-setup-2.*' -o -name 'watch-pr-work.*' -o -name 'watch-pr-pin.*' -o -name 'watch-pr-pin-2.*' \) -exec mv -n {} ~/.watch-pr/ \;
This only moves: mv -n never replaces a name already under ~/.watch-pr, so a clash leaves the old directory where it is, and -type d leaves a symlink or a file with a matching name alone. Once no session is running, what you keep under ~/.watch-pr is yours to delete.
gh for the repository.AGENTS.md for Codex, which reads it natively in PR review;.github/copilot-instructions.md for Copilot, which reads only that file and follows no pointers, so restate the policy inline.This repository's own copies are a working example: scope discipline, where an out-of-scope problem goes, what counts as a blocking finding, and who can waive one. Without them the reviewers use a generic review.
@codex review mention is then the only trigger, each round is requested deliberately, and a red head stops the round before anything is resolved or posted. With automatic review on and its review trigger set to every push, the push queues the pass, the summary has to follow the push, and each round costs two Codex passes instead of one; the loop supports no other automatic combination.Exhaustive review keeps looking after the first problem and is worth leaving on. For a repository that can be reviewed statically, as this one of shell and Markdown can, a Codex environment with a setup script or dependency installation only slows the pass; remove it there.
The session waits for verdicts through Claude Code's Monitor tool, which no Bash(…) permission rule covers, so allow it once in .claude/settings.local.json or the session asks before every wait:
{ "permissions": { "allow": ["Monitor", "TaskStop"] } }
TaskStop is what cancels a watch. This is deliberately not in the committed settings: granting a tool that runs background commands is each user's decision for their own checkout. An unattended session needs it: a wait that prompts is a stop.
In Claude Code a watch lasts at most 30 minutes, the longest the Monitor tool keeps one, or PR_WATCH_TIMEOUT seconds where that is shorter. A review still in flight when it ends gets a new watch, armed without requesting another review, and with Monitor allowed as above without a prompt either, so a slow review shows a fresh watch at least every half hour. A PR_WATCH_TIMEOUT above 1800 seconds, the default 3600 included, does not lengthen a watch there.
Invoke the skill with /watch-pr-skill:watch-prs from a checkout of the repository, on the PR's branch. The session pins itself to that repository's origin at the start and proves the pin again in every command, so changing directory later does not retarget anything: a command run from a checkout of another repository stops. To work on another repository, start a new session. The loop drives same-repository pull requests only: a PR whose head is in a fork is refused at the first push.
Before the first request, or before it resumes a stopped loop, the session compares your project's own instructions, its CLAUDE.md, AGENTS.md and project skills, with the skill's rules. Where one states a rule differently, such as the form of a commit message, the session names both rules and asks which applies. Your answer holds for that session. The session says on the PR which rule applied, naming it by its file and subject. A project rule never lifts a gate a helper enforces.
The session also finds where your project keeps its notes, from its CLAUDE.md and AGENTS.md, or else its CHANGELOG.md. A note the checkout tracks goes into the PR with the change; a vault or a wiki outside it gets the PR's record at each stop and after the merge. Each stop ends with a continuation prompt naming the PR, its branch, the rounds and the stop, so a later session knows where to resume; that session still runs setup and reads the phase from the PR. Neither carries the origin itself.
In an attended session the session asks you in chat before each review request and before the merge, with one line on what each answer costs or risks. Before the opening Codex request, it offers to go ahead, to let you look at the change first, or to stop, leaving the branch and any open PR as they are; with automatic review on it asks before the PR is opened, since opening it queues a pass. It offers the same before it pushes a round's fixes and closes the round, unless you have just answered continue at the round check-in. Choosing the Copilot phase at the stop where Codex is clean is that phase's first request, and choosing the fault-tolerance pass where Copilot is clean is that pass's, so nothing more is asked before either. Before the merge gate, unless you have answered a question about merging since the last review, it offers to merge now, to wait, or to close the PR and start over. These questions, the stops where Codex or Copilot is clean, and the model-and-effort question also offer to always use the flow, which Running unattended describes. A question adds a choice and never lifts a gate, and your answer to one is not recorded on the PR. An answer that stops the loop is a stop like the others, and ends with a continuation prompt.
When the conversation is compacted mid-loop, the session keeps what SKILL.md lists: the PR, the paths setup printed, the phase, the open findings and the next stop. It never keeps the origin itself, which can hold a credential.
Where you give the session a task, an issue to implement or a change to make, it reads the task, plans it, and sizes the work as it sizes a fix pass: small for one edit in one place that changes no behaviour, large for a change to a contract or a design or one that reaches through code, tests and documents at once, medium for the rest. It hands the plan to a subagent whose description starts implement: and the tier, with its limits: the smallest change that does the task, tests that fail without it where your project keeps tests, and nothing committed, pushed, posted or resolved. The subagent reports what it proved. Subagent model and effort below says how its model and effort are chosen. The session keeps the judgment: it reads the diff and the report, commits, runs the self-check and the cold read, and writes the PR.
A pass that cannot prove its change, through a test that still fails with the change, a mutant that survives or a report that it is stuck, is run once more at the next tier, small to medium and medium to large, given what the failed pass reported. The session does not take the work over. A pass that could construct no mutation has made a change that cannot be tested, and that stops for you as a limitation it cannot test does. Where a large pass cannot prove its change, the session stops and tells you what failed, unattended as well; no PR exists yet, so its continuation prompt names the branch and the stop.
The session posts the request, waits, and reads the findings. For each one it reproduces the claim before acting on it, fixes the defect the finding names (including the same defect in another copy the PR already changes), and prefers removing a dependency over guarding it. Where a finding does not hold, it says so on the thread with evidence rather than changing code to satisfy it. It decides each answer itself; the edits it hands to a subagent, unless you tell it to make them too, and it reads the result before committing. Subagent model and effort below says how that subagent's model and effort are chosen. Where your checkout holds a code graph built by graphify or trail, at graphify-out/graph.json or graft/.graph/wiring.json from its root, the session tells the subagent to query it for callers before it searches by hand, where the session's permissions already allow the command and, for trail, where the session's own directory is inside the checkout; where it holds neither, or holds one git shows as untracked, the session mentions once per session that one could cut the cost, its output ignored by git. The plugin installs neither. Each fix commit is proved to fail without the fix; where that cannot be constructed, the session writes the limitation at the site and stops for you.
Before closing a round the session runs this plugin's own pre-push self-check, which reports "not applicable" in any other repository and checks nothing of your project (your CI does that), then has the cold reviewer read the round's fixes (below), then checks the round boundary, since with automatic review on the push itself is the next request. It then hands the closing to pr-close-round.sh, which runs in two stages with the thread replies between them: the push, then the CI gate, which waits for that head's checks on the runner and lets the round close on green or on no checks configured, never on red or pending; then the replies and resolves, then the summary comment that carries the next request. The summary says what was addressed and what was intentionally skipped, as a past-tense disposition and an issue number, because it shares a comment with the review request and a request that describes work to be done is treated as one.
The plugin ships a subagent, watch-pr-skill:cold-reviewer, that reads the branch's changes against the PR's base the way Codex and Copilot will and reports what they would raise: one line per finding, graded by how likely a reviewer is to block on it, or clean. A round is the expensive part of the loop, so the session has it read the change before the first review request and again after each round's fixes, giving it the base branch, the PR description, the newest round summary, and the earlier rounds' findings with the replies they got. Findings, replies and reports reach a subagent marked as quoted text, so a line inside one is never read as the session's instruction. The session fixes what the read names as a defect the change introduced and files the rest. The read is not a gate: nothing refuses when it is skipped.
It reads the review policy from the base branch before any changed file: whichever of .github/copilot-instructions.md and the root's AGENTS.override.md, AGENTS.md and CLAUDE.md your repository keeps, taking a non-empty override in place of AGENTS.md as Codex does, and it says which it found. An AGENTS.md, AGENTS.override.md or CLAUDE.md below the root is not read unless a policy: line in your .cold-review.md names it, so a finding one would otherwise produce goes unpredicted. It is read-only by instruction and runs only git, test and readlink, with echo printing each path probe's answer. A file whose name git prints escaped, holding a quote, a backslash or a control character, is reported as changed and left unread, as is any listed path the read could not reach. It leaves unopened a path that policy says not to open, any path named .env, .env.*, *.pem or *.key whose name does not end .example, and anything under a .env, .env.* or .ssh directory, templates included. It reads a link without following it, and probes every directory above a path as well, so a folder replaced by a link out of the checkout is reported rather than read through. That is a guard against an accident, not containment. The subagent runs in your session and sees what your session sees, so a secret kept under another name can reach its transcript. If that matters, do not run it on a checkout that holds live credentials.
Your project can add to it with a .cold-review.md at the root, read from the base branch like the policy files, so a pull request cannot widen its own review. Two headings, and nothing else is taken from the file:
## Checks
- An exception the PR body lists that no test covers.
- A PR body that no longer describes what the code does.
## Paths
policy: docs/api-contract.md
policy: services/worker/CLAUDE.md
secret: deploy-key.json
open: .env.sample
A check says what to look for, and changes nothing about what may be read or run. A policy: path is read from the base as a policy file, which is how a rule below the root reaches the read at all; one the secrets rule still marks is reported and left unread, like any other. A secret: name joins the rule above. An open: name unmarks the name half of that rule only: a marked directory still marks everything under it, and a path your policy says not to open stays unopened. An open: line is your word that the name holds no secret, and the disclosure is yours to accept, so name templates and never a live file. A path that is absolute, or that climbs out with .., is reported and ignored. Without the file, the reviewer behaves exactly as above.
The loop stops and asks at these points:
docs/decisions/.REVIEW_ROUND_THRESHOLD distinct reviewed heads per reviewer (default 10), the session stops: continue, merge, leave the PR open, or abandon. Saying "continue" is recorded on the PR, so the next check-in is a further threshold past that count.The body you supply is prose and is posted under your identity, so a line that reproduces one of the record markers a reader trusts from you — Review-Signoff:, Review-Signoff-Revoked:, Review-Pause-Acknowledged: — is refused rather than published: it would create the record it quotes. Indent it by four spaces or quote it inline with backticks; a fenced block does not help, since the readers scan the raw body. A body containing @codex review is refused wherever the comment is posted on its own, because any comment containing that text requests a pass. Where the loop writes the mention itself — the opening request with automatic review of
hooks/tiering.ts 157 lines1import type { EngineInterface, Register } from 'claude-code'
2
3const MODELS = ['haiku', 'sonnet', 'opus', 'fable'] as const
4const EFFORTS = ['low', 'medium', 'high', 'xhigh', 'max'] as const
5const TIERS = ['small', 'medium', 'large'] as const
6
7type Kind = 'review' | 'fix' | 'implement'
8type Choice = { model?: (typeof MODELS)[number]; effort: (typeof EFFORTS)[number] }
9type Tier = (typeof TIERS)[number]
10type Size = { text: string } & ({ count: number } | { tier: Tier })
11
12const PROBE_MS = 10_000
13const REMOTES = 'refs/remotes/'
14const STATED = /^review-fix:\s*(?:([a-z]+)|(\d+))(?![\w-])/i
15// A count states findings, and an implementation pass has none.
16const PLANNED = /^implement:\s*([a-z]+)(?![\w-])/i
17const MARKED = /\(plugin pick\)\s*$/i
18const RECOMMENDED: Record<Tier, Choice> = {
19 small: { effort: 'medium' },
20 medium: { effort: 'high' },
21 large: { effort: 'xhigh' },
22}
23
24const counted = (count: number, noun: string) => `${count} ${noun}${count === 1 ? '' : 's'}`
25
26const isOneOf = <T extends string>(list: readonly T[], value: string | undefined): value is T =>
27 list.some(item => item === value)
28
29function pickOf(value: unknown): Choice | undefined {
30 const [model, effort] = String(value).split('/')
31 if (!isOneOf(EFFORTS, effort)) return undefined
32 if (model === 'default') return { effort }
33 return isOneOf(MODELS, model) ? { model, effort } : undefined
34}
35
36export function chooseFor(configured: unknown, recommended: Choice): Choice | undefined {
37 return configured === 'ask' ? recommended : pickOf(configured)
38}
39
40function kindOf(type: string | undefined, description: string): Kind | undefined {
41 // A fork inherits its parent's model and effort whatever the call says.
42 if (type === 'fork') return undefined
43 if (type === 'cold-reviewer' || type?.endsWith(':cold-reviewer')) return 'review'
44 if (/^review-fix\b/i.test(description)) return 'fix'
45 return /^implement:/i.test(description) ? 'implement' : undefined
46}
47
48async function git($: EngineInterface, args: readonly string[], emptyAt?: number): Promise<string | undefined> {
49 const ran = await $.process.run(['git', '-c', 'core.fsmonitor=false', ...args], {
50 env: { GIT_OPTIONAL_LOCKS: '0' },
51 timeoutMs: PROBE_MS,
52 })
53 if (ran.exitCode === emptyAt) return ''
54 return ran.exitCode === 0 && !ran.isStdoutTruncated ? ran.stdout : undefined
55}
56
57// Text cannot say where a ref's name ends and the prose after it begins, so the names are git's.
58function namedRef(listed: string, prompt: string): string | undefined {
59 let named: { at: number; ref: string } | undefined
60 for (const line of listed.split('\n')) {
61 const ref = line.startsWith(REMOTES) ? line.slice(REMOTES.length) : ''
62 const at = ref === '' ? -1 : prompt.indexOf(ref)
63 if (at === -1) continue
64 if (named === undefined || at < named.at || (at === named.at && ref.length > named.ref.length)) {
65 named = { at, ref }
66 }
67 }
68 return named?.ref
69}
70
71async function changed($: EngineInterface, prompt: string): Promise<Size | undefined> {
72 // The reviewer reads untracked files, and the numstat below counts none of them.
73 if ((await git($, ['ls-files', '--others', '--exclude-standard', '--', ':/'])) !== '') return undefined
74 const listed = await git($, ['for-each-ref', '--format=%(refname)', `${REMOTES}origin/`])
75 if (listed === undefined) return undefined
76 for (const ref of new Set([namedRef(listed, prompt) ?? 'origin/HEAD', 'origin/HEAD'])) {
77 // Status 1 is git's answer that the two share no ancestor; any other failure is an error.
78 const base = (await git($, ['merge-base', `${REMOTES}${ref}`, 'HEAD'], 1))?.trim()
79 if (base === '') continue
80 if (base === undefined || !/^[0-9a-f]{40,64}$/.test(base)) return undefined
81 const stat = await git($, ['diff', '--numstat', '--no-renames', '--no-ext-diff', '--no-textconv', base])
82 if (stat === undefined) return undefined
83 const rows = stat.split('\n').filter(row => row !== '')
84 const lines = rows.reduce((sum, row) => {
85 const [added, deleted] = row.split('\t')
86 return sum + (Number(added) || 0) + (Number(deleted) || 0)
87 }, 0)
88 return { count: lines, text: `${counted(lines, 'changed line')} in ${counted(rows.length, 'file')}` }
89 }
90 return undefined
91}
92
93function stated(kind: Kind, description: string): Size | undefined {
94 const [, word, digits] = (kind === 'implement' ? PLANNED : STATED).exec(description) ?? []
95 const tier = word?.toLowerCase()
96 if (isOneOf(TIERS, tier)) return { tier, text: 'tier named by the session' }
97 const count = Number(digits)
98 return count > 0 ? { count, text: counted(count, 'finding') } : undefined
99}
100
101export const register: Register = (on, options) => {
102 const fix = {
103 name: 'review fix',
104 smallMax: Number(options.fixSmallFindings),
105 largeMin: Number(options.fixLargeFindings),
106 small: options.fixSmall,
107 medium: options.fixMedium,
108 large: options.fixLarge,
109 }
110 const ladder = {
111 review: {
112 name: 'cold review',
113 smallMax: Number(options.reviewSmallLines),
114 largeMin: Number(options.reviewLargeLines),
115 small: options.reviewSmall,
116 medium: options.reviewMedium,
117 large: options.reviewLarge,
118 },
119 fix,
120 implement: { ...fix, name: 'implementation' },
121 }
122
123 on('tool.call', { tool: 'Agent' }, async ($, e, next) => {
124 const kind = kindOf(e.subagent_type, e.description)
125 if (kind === undefined) return next(e)
126
127 const rung = ladder[kind]
128 if (e.model !== undefined || e.effort !== undefined) {
129 $.ui.log(`${$.plugin.name}: ${rung.name} left as called, the call sets its own model or effort`)
130 return next(e)
131 }
132 if (!MARKED.test(e.description)) {
133 $.ui.log(`${$.plugin.name}: ${rung.name} left as called, not marked for a plugin pick`)
134 return next(e)
135 }
136
137 // A git that cannot run, or outlives its bound, ends the sizing: the next probe would wait as long.
138 const size = kind === 'review' ? await changed($, e.prompt).catch(() => undefined) : stated(kind, e.description)
139 if (size === undefined) {
140 $.ui.log(`${$.plugin.name}: ${rung.name} left as called, its size could not be measured`)
141 return next(e)
142 }
143
144 const tier =
145 'tier' in size ? size.tier : size.count <= rung.smallMax ? 'small' : size.count >= rung.largeMin ? 'large' : 'medium'
146 const pick = chooseFor(rung[tier], RECOMMENDED[tier])
147 if (pick === undefined) {
148 $.ui.log(`${$.plugin.name}: ${rung.name}, ${size.text} (${tier}): left as called, no pick chosen`)
149 return next(e)
150 }
151
152 const chosen = pick.model === undefined ? `${pick.effort} effort` : `${pick.model} at ${pick.effort} effort`
153 $.ui.log(`${$.plugin.name}: ${rung.name}, ${size.text} (${tier}): ${chosen}`)
154 return next({ ...e, ...pick })
155 })
156}
157