Agent skill
reviewing-prs
System skill loaded before dispatching any PR review subagent. Ensures correct file version selection based on branch and worktree state. Not invoked directly by users. Required by: code-review, advanced-code-review, distilling-prs when reviewing PRs.
Install this agent skill to your Project
npx add-skill https://github.com/axiomantic/spellbook/tree/main/skills/reviewing-prs
SKILL.md
Reviewing PRs Safely
Invariant Principles
- Determine review_source First: Never dispatch a PR review subagent without computing
review_source. No exceptions. - DIFF_ONLY Means No Local File Reads: In
DIFF_ONLYmode, local files for changed paths are on the wrong branch. Reading them produces wrong verdicts. - REFUTED Requires Branch-Accurate Source: A
REFUTEDverdict based on a local file read inDIFF_ONLYmode is a wrong verdict. Mark itINCONCLUSIVEor[NEEDS VERIFICATION]. - Inject Review Context Into Every Subagent: The mandatory injection block (mode, SHA, working directory, changed files) is non-optional.
The Wrong-Branch Failure
When reviewing a PR via diff, local files are on a different branch. Reading them produces silently wrong results:
- PR-introduced changes appear absent (local has old code)
- Real bugs get declared "not present" → false REFUTED verdicts
- Findings carry high confidence in factually wrong conclusions
This is a structural failure: the agent reads the wrong version of the file.
Review Source Decision
Before dispatching any code review subagent, determine review_source:
PR_HEAD_SHA=$(gh pr view <PR_NUMBER> --json headRefOid --jq '.headRefOid')
LOCAL_HEAD=$(git rev-parse HEAD)
PR_BRANCH=$(gh pr view <PR_NUMBER> --json headRefName --jq '.headRefName')
WORKTREE_PATH=$(git worktree list --porcelain | grep -B1 "branch refs/heads/$PR_BRANCH" | grep "^worktree" | awk '{print $2}')
| Condition | review_source |
Working Directory |
|---|---|---|
$WORKTREE_PATH is set |
LOCAL_FILES |
$WORKTREE_PATH |
$LOCAL_HEAD == $PR_HEAD_SHA |
LOCAL_FILES |
Current repo root |
| Neither | DIFF_ONLY |
N/A |
What Each Mode Means
LOCAL_FILES mode
The agent works in a directory that is the PR branch. File reads are authoritative.
- Safe to read changed files
- Safe to verify/refute findings by reading line content
- MUST specify the working directory — the agent must not stray outside it
DIFF_ONLY mode
No local checkout matches the PR. The diff is the only source of truth.
- NEVER read local files from the changed file set
- All verification functions return
INCONCLUSIVE(notREFUTED) - Findings that cannot be verified from the diff are marked
[NEEDS VERIFICATION] - A finding marked
REFUTEDbased on a local file read is a wrong verdict
Mandatory Injection
Every subagent dispatched to review a PR must receive this context block:
## PR Review Context
- PR: #<NUMBER>
- PR HEAD SHA: <SHA>
- Review mode: <LOCAL_FILES | DIFF_ONLY>
- Working directory: <path if LOCAL_FILES, "N/A — use diff only" if DIFF_ONLY>
- Changed files: <list>
If review mode is DIFF_ONLY:
- Do NOT read any files listed under "Changed files" from the local filesystem
- The diff is the only authoritative source for those files
- Mark any finding you cannot verify from the diff as [NEEDS VERIFICATION]
- Do NOT mark a finding REFUTED based on local file content
Why Worktrees Are the Clean Solution
Checking out a PR branch in a worktree converts a DIFF_ONLY review into a LOCAL_FILES review. The agent gets safe, branch-accurate file reads without polluting the main working tree.
# Check out PR branch in a worktree
git worktree add ~/.local/worktrees/pr-<NUMBER> <PR_BRANCH>
Once the worktree exists, dispatch the review agent with working_directory: ~/.local/worktrees/pr-<NUMBER>.
Self-Check
Before dispatching any PR review subagent:
-
PR_HEAD_SHAfetched from GitHub (not guessed) -
review_sourcedetermined:LOCAL_FILESorDIFF_ONLY - If
LOCAL_FILES: exact working directory specified in prompt - If
DIFF_ONLY: prompt explicitly forbids local file reads on changed files - Changed file list included so agent knows what is "in scope"
<FINAL_EMPHASIS> The wrong-branch problem produces confident wrong answers, not obvious errors. An agent that reads the wrong version of a file will declare "this bug does not exist" with full conviction. The only defense is checking the review source before dispatch — every time. </FINAL_EMPHASIS>
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
spellbook-auditing
Meta-audit skill for spellbook development. Spawns parallel subagents to factcheck docs, optimize instructions, find token savings, and identify MCP candidates. Produces actionable report.
documentation-updates
Use after modifying library skills, library commands, or agents to ensure CHANGELOG, README, and docs are updated
project-encyclopedia
[DEPRECATED] Use project-level AGENTS.md files instead. Previously used for first-session codebase onboarding and persistent glossary creation.
reviewing-impl-plans
Use when reviewing implementation plans before execution. Triggers: 'is this plan solid', 'review the plan', 'check before I start building', 'anything missing from this plan', 'will this plan work', 'audit the implementation plan'. NOT for: reviewing design documents (use reviewing-design-docs) or creating plans (use writing-plans).
session-resume
Session resume protocol and session repairs handling. Loaded when spellbook_session_init returns resume_available: true, or when session_init returns a repairs array. Triggers: 'resume', 'continue', 'where were we', session resume, session repairs.
brainstorming
Use when exploring design approaches, generating ideas, or making architectural decisions. Triggers: 'explore options', 'what are the tradeoffs', 'how should I approach', 'let's think through', 'sketch out an approach', 'I need ideas for', 'how would you structure', 'what are my options'. Also invoked by develop when design decisions are needed.
Didn't find tool you were looking for?