Skip to content

Commit d6eb4cb

Browse files
committed
Add custom code-review Claude plugin
1 parent 9ba7bcb commit d6eb4cb

File tree

3 files changed

+379
-0
lines changed

3 files changed

+379
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"name": "code-review",
3+
"description": "Automated code review for pull requests using multiple specialized agents with confidence-based scoring",
4+
"version": "1.0.0",
5+
"author": {
6+
"name": "Boris Cherny",
7+
"email": "boris@anthropic.com"
8+
}
9+
}
10+
Lines changed: 260 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,260 @@
1+
# Code Review Plugin
2+
3+
**Stolen from https://github.com/anthropics/claude-code/tree/db8834ba1d72e9a26fba30ac85f3bc4316bb0689/plugins/code-review**
4+
5+
Automated code review for pull requests using multiple specialized agents with confidence-based scoring to filter false positives.
6+
7+
## Overview
8+
9+
The Code Review Plugin automates pull request review by launching multiple agents in parallel to independently audit changes from different perspectives. It uses confidence scoring to filter out false positives, ensuring only high-quality, actionable feedback is posted.
10+
11+
## Commands
12+
13+
### `/code-review`
14+
15+
Performs automated code review on a pull request using multiple specialized agents.
16+
17+
**What it does:**
18+
1. Checks if review is needed (skips closed, draft, trivial, or already-reviewed PRs)
19+
2. Gathers relevant CLAUDE.md guideline files from the repository
20+
3. Summarizes the pull request changes
21+
4. Launches 4 parallel agents to independently review:
22+
- **Agents #1 & #2**: Audit for CLAUDE.md compliance
23+
- **Agent #3**: Scan for obvious bugs in changes
24+
- **Agent #4**: Analyze git blame/history for context-based issues
25+
5. Scores each issue 0-100 for confidence level
26+
6. Filters out issues below 80 confidence threshold
27+
7. Outputs review (to terminal by default, or as PR comment with `--comment` flag)
28+
29+
**Usage:**
30+
```bash
31+
/code-review [--comment]
32+
```
33+
34+
**Options:**
35+
- `--comment`: Post the review as a comment on the pull request (default: outputs to terminal only)
36+
37+
**Example workflow:**
38+
```bash
39+
# On a PR branch, run locally (outputs to terminal):
40+
/code-review
41+
42+
# Post review as PR comment:
43+
/code-review --comment
44+
45+
# Claude will:
46+
# - Launch 4 review agents in parallel
47+
# - Score each issue for confidence
48+
# - Output issues ≥80 confidence (to terminal or PR depending on flag)
49+
# - Skip if no high-confidence issues found
50+
```
51+
52+
**Features:**
53+
- Multiple independent agents for comprehensive review
54+
- Confidence-based scoring reduces false positives (threshold: 80)
55+
- CLAUDE.md compliance checking with explicit guideline verification
56+
- Bug detection focused on changes (not pre-existing issues)
57+
- Historical context analysis via git blame
58+
- Automatic skipping of closed, draft, or already-reviewed PRs
59+
- Links directly to code with full SHA and line ranges
60+
61+
**Review comment format:**
62+
```markdown
63+
## Code review
64+
65+
Found 3 issues:
66+
67+
1. Missing error handling for OAuth callback (CLAUDE.md says "Always handle OAuth errors")
68+
69+
https://github.com/owner/repo/blob/abc123.../src/auth.ts#L67-L72
70+
71+
2. Memory leak: OAuth state not cleaned up (bug due to missing cleanup in finally block)
72+
73+
https://github.com/owner/repo/blob/abc123.../src/auth.ts#L88-L95
74+
75+
3. Inconsistent naming pattern (src/conventions/CLAUDE.md says "Use camelCase for functions")
76+
77+
https://github.com/owner/repo/blob/abc123.../src/utils.ts#L23-L28
78+
```
79+
80+
**Confidence scoring:**
81+
- **0**: Not confident, false positive
82+
- **25**: Somewhat confident, might be real
83+
- **50**: Moderately confident, real but minor
84+
- **75**: Highly confident, real and important
85+
- **100**: Absolutely certain, definitely real
86+
87+
**False positives filtered:**
88+
- Pre-existing issues not introduced in PR
89+
- Code that looks like a bug but isn't
90+
- Pedantic nitpicks
91+
- Issues linters will catch
92+
- General quality issues (unless in CLAUDE.md)
93+
- Issues with lint ignore comments
94+
95+
## Installation
96+
97+
This plugin is included in the Claude Code repository. The command is automatically available when using Claude Code.
98+
99+
## Best Practices
100+
101+
### Using `/code-review`
102+
- Maintain clear CLAUDE.md files for better compliance checking
103+
- Trust the 80+ confidence threshold - false positives are filtered
104+
- Run on all non-trivial pull requests
105+
- Review agent findings as a starting point for human review
106+
- Update CLAUDE.md based on recurring review patterns
107+
108+
### When to use
109+
- All pull requests with meaningful changes
110+
- PRs touching critical code paths
111+
- PRs from multiple contributors
112+
- PRs where guideline compliance matters
113+
114+
### When not to use
115+
- Closed or draft PRs (automatically skipped anyway)
116+
- Trivial automated PRs (automatically skipped)
117+
- Urgent hotfixes requiring immediate merge
118+
- PRs already reviewed (automatically skipped)
119+
120+
## Workflow Integration
121+
122+
### Standard PR review workflow:
123+
```bash
124+
# Create PR with changes
125+
# Run local review (outputs to terminal)
126+
/code-review
127+
128+
# Review the automated feedback
129+
# Make any necessary fixes
130+
131+
# Optionally post as PR comment
132+
/code-review --comment
133+
134+
# Merge when ready
135+
```
136+
137+
### As part of CI/CD:
138+
```bash
139+
# Trigger on PR creation or update
140+
# Use --comment flag to post review comments
141+
/code-review --comment
142+
# Skip if review already exists
143+
```
144+
145+
## Requirements
146+
147+
- Git repository with GitHub integration
148+
- GitHub CLI (`gh`) installed and authenticated
149+
- CLAUDE.md files (optional but recommended for guideline checking)
150+
151+
## Troubleshooting
152+
153+
### Review takes too long
154+
155+
**Issue**: Agents are slow on large PRs
156+
157+
**Solution**:
158+
- Normal for large changes - agents run in parallel
159+
- 4 independent agents ensure thoroughness
160+
- Consider splitting large PRs into smaller ones
161+
162+
### Too many false positives
163+
164+
**Issue**: Review flags issues that aren't real
165+
166+
**Solution**:
167+
- Default threshold is 80 (already filters most false positives)
168+
- Make CLAUDE.md more specific about what matters
169+
- Consider if the flagged issue is actually valid
170+
171+
### No review comment posted
172+
173+
**Issue**: `/code-review` runs but no comment appears
174+
175+
**Solution**:
176+
Check if:
177+
- PR is closed (reviews skipped)
178+
- PR is draft (reviews skipped)
179+
- PR is trivial/automated (reviews skipped)
180+
- PR already has review (reviews skipped)
181+
- No issues scored ≥80 (no comment needed)
182+
183+
### Link formatting broken
184+
185+
**Issue**: Code links don't render correctly in GitHub
186+
187+
**Solution**:
188+
Links must follow this exact format:
189+
```
190+
https://github.com/owner/repo/blob/[full-sha]/path/file.ext#L[start]-L[end]
191+
```
192+
- Must use full SHA (not abbreviated)
193+
- Must use `#L` notation
194+
- Must include line range with at least 1 line of context
195+
196+
### GitHub CLI not working
197+
198+
**Issue**: `gh` commands fail
199+
200+
**Solution**:
201+
- Install GitHub CLI: `brew install gh` (macOS) or see [GitHub CLI installation](https://cli.github.com/)
202+
- Authenticate: `gh auth login`
203+
- Verify repository has GitHub remote
204+
205+
## Tips
206+
207+
- **Write specific CLAUDE.md files**: Clear guidelines = better reviews
208+
- **Include context in PRs**: Helps agents understand intent
209+
- **Use confidence scores**: Issues ≥80 are usually correct
210+
- **Iterate on guidelines**: Update CLAUDE.md based on patterns
211+
- **Review automatically**: Set up as part of PR workflow
212+
- **Trust the filtering**: Threshold prevents noise
213+
214+
## Configuration
215+
216+
### Adjusting confidence threshold
217+
218+
The default threshold is 80. To adjust, modify the command file at `commands/code-review.md`:
219+
```markdown
220+
Filter out any issues with a score less than 80.
221+
```
222+
223+
Change `80` to your preferred threshold (0-100).
224+
225+
### Customizing review focus
226+
227+
Edit `commands/code-review.md` to add or modify agent tasks:
228+
- Add security-focused agents
229+
- Add performance analysis agents
230+
- Add accessibility checking agents
231+
- Add documentation quality checks
232+
233+
## Technical Details
234+
235+
### Agent architecture
236+
- **2x CLAUDE.md compliance agents**: Redundancy for guideline checks
237+
- **1x bug detector**: Focused on obvious bugs in changes only
238+
- **1x history analyzer**: Context from git blame and history
239+
- **Nx confidence scorers**: One per issue for independent scoring
240+
241+
### Scoring system
242+
- Each issue independently scored 0-100
243+
- Scoring considers evidence strength and verification
244+
- Threshold (default 80) filters low-confidence issues
245+
- For CLAUDE.md issues: verifies guideline explicitly mentions it
246+
247+
### GitHub integration
248+
Uses `gh` CLI for:
249+
- Viewing PR details and diffs
250+
- Fetching repository data
251+
- Reading git blame and history
252+
- Posting review comments
253+
254+
## Author
255+
256+
Boris Cherny (boris@anthropic.com)
257+
258+
## Version
259+
260+
1.0.0
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Bash(gh pr list:*), mcp__github_inline_comment__create_inline_comment
3+
description: Code review a pull request
4+
---
5+
6+
Provide a code review for the given pull request.
7+
8+
**Agent assumptions (applies to all agents and subagents):**
9+
- All tools are functional and will work without error. Do not test tools or make exploratory calls. Make sure this is clear to every subagent that is launched.
10+
- Only call a tool if it is required to complete the task. Every tool call should have a clear purpose.
11+
12+
To do this, follow these steps precisely:
13+
14+
1. Launch a haiku agent to check if any of the following are true:
15+
- The pull request is closed
16+
- The pull request is a draft
17+
- The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct)
18+
- Claude has already commented on this PR (check `gh pr view <PR> --comments` for comments left by claude)
19+
20+
If any condition is true, stop and do not proceed.
21+
22+
Note: Still review Claude generated PR's.
23+
24+
2. Launch a haiku agent to return a list of file paths (not their contents) for all relevant CLAUDE.md files including:
25+
- The root CLAUDE.md file, if it exists
26+
- Any CLAUDE.md files in directories containing files modified by the pull request
27+
28+
3. Launch a sonnet agent to view the pull request and return a summary of the changes
29+
30+
4. Launch 4 agents in parallel to independently review the changes. Each agent should return the list of issues, where each issue includes a description and the reason it was flagged (e.g. "CLAUDE.md adherence", "bug"). The agents should do the following:
31+
32+
Agents 1 + 2: CLAUDE.md compliance sonnet agents
33+
Audit changes for CLAUDE.md compliance in parallel. Note: When evaluating CLAUDE.md compliance for a file, you should only consider CLAUDE.md files that share a file path with the file or parents.
34+
35+
Agent 3: Opus bug agent (parallel subagent with agent 4)
36+
Scan for obvious bugs. Focus only on the diff itself without reading extra context. Flag only significant bugs; ignore nitpicks and likely false positives. Do not flag issues that you cannot validate without looking at context outside of the git diff.
37+
38+
Agent 4: Opus bug agent (parallel subagent with agent 3)
39+
Look for problems that exist in the introduced code. This could be security issues, incorrect logic, etc. Only look for issues that fall within the changed code.
40+
41+
**CRITICAL: We only want HIGH SIGNAL issues.** Flag issues where:
42+
- The code will fail to compile or parse (syntax errors, type errors, missing imports, unresolved references)
43+
- The code will definitely produce wrong results regardless of inputs (clear logic errors)
44+
- Clear, unambiguous CLAUDE.md violations where you can quote the exact rule being broken
45+
46+
Do NOT flag:
47+
- Code style or quality concerns
48+
- Potential issues that depend on specific inputs or state
49+
- Subjective suggestions or improvements
50+
51+
If you are not certain an issue is real, do not flag it. False positives erode trust and waste reviewer time.
52+
53+
In addition to the above, each subagent should be told the PR title and description. This will help provide context regarding the author's intent.
54+
55+
5. For each issue found in the previous step by agents 3 and 4, launch parallel subagents to validate the issue. These subagents should get the PR title and description along with a description of the issue. The agent's job is to review the issue to validate that the stated issue is truly an issue with high confidence. For example, if an issue such as "variable is not defined" was flagged, the subagent's job would be to validate that is actually true in the code. Another example would be CLAUDE.md issues. The agent should validate that the CLAUDE.md rule that was violated is scoped for this file and is actually violated. Use Opus subagents for bugs and logic issues, and sonnet agents for CLAUDE.md violations.
56+
57+
6. Filter out any issues that were not validated in step 5. This step will give us our list of high signal issues for our review.
58+
59+
7. Output a summary of the review findings to the terminal:
60+
- If issues were found, list each issue with a brief description.
61+
- If no issues were found, state: "No issues found. Checked for bugs and CLAUDE.md compliance."
62+
63+
If `--comment` argument was NOT provided, stop here. Do not post any GitHub comments.
64+
65+
If `--comment` argument IS provided and NO issues were found, post a summary comment using `gh pr comment` and stop.
66+
67+
If `--comment` argument IS provided and issues were found, continue to step 8.
68+
69+
8. Create a list of all comments that you plan on leaving. This is only for you to make sure you are comfortable with the comments. Do not post this list anywhere.
70+
71+
9. Post inline comments for each issue using `mcp__github_inline_comment__create_inline_comment` with `confirmed: true`. For each comment:
72+
- Provide a brief description of the issue
73+
- For small, self-contained fixes, include a committable suggestion block
74+
- For larger fixes (6+ lines, structural changes, or changes spanning multiple locations), describe the issue and suggested fix without a suggestion block
75+
- Never post a committable suggestion UNLESS committing the suggestion fixes the issue entirely. If follow up steps are required, do not leave a committable suggestion.
76+
77+
**IMPORTANT: Only post ONE comment per unique issue. Do not post duplicate comments.**
78+
79+
Use this list when evaluating issues in Steps 4 and 5 (these are false positives, do NOT flag):
80+
81+
- Pre-existing issues
82+
- Something that appears to be a bug but is actually correct
83+
- Pedantic nitpicks that a senior engineer would not flag
84+
- Issues that a linter will catch (do not run the linter to verify)
85+
- General code quality concerns (e.g., lack of test coverage, general security issues) unless explicitly required in CLAUDE.md
86+
- Issues mentioned in CLAUDE.md but explicitly silenced in the code (e.g., via a lint ignore comment)
87+
88+
Notes:
89+
90+
- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch.
91+
- Create a todo list before starting.
92+
- You must cite and link each issue in inline comments (e.g., if referring to a CLAUDE.md, include a link to it).
93+
- If no issues are found and `--comment` argument is provided, post a comment with the following format:
94+
95+
---
96+
97+
## Code review
98+
99+
No issues found. Checked for bugs and CLAUDE.md compliance.
100+
101+
---
102+
103+
- When linking to code in inline comments, follow the following format precisely, otherwise the Markdown preview won't render correctly: https://github.com/anthropics/claude-code/blob/c21d3c10bc8e898b7ac1a2d745bdc9bc4e423afe/package.json#L10-L15
104+
- Requires full git sha
105+
- You must provide the full sha. Commands like `https://github.com/owner/repo/blob/$(git rev-parse HEAD)/foo/bar` will not work, since your comment will be directly rendered in Markdown.
106+
- Repo name must match the repo you're code reviewing
107+
- # sign after the file name
108+
- Line range format is L[start]-L[end]
109+
- Provide at least 1 line of context before and after, centered on the line you are commenting about (eg. if you are commenting about lines 5-6, you should link to `L4-7`)

0 commit comments

Comments
 (0)