Skip to content

Commit 546f0b4

Browse files
whyuan-ccclaude
andcommitted
Add code-review plugin with automated PR review workflow
Add new code-review plugin that provides automated pull request reviews using multiple specialized agents with confidence-based scoring to filter false positives. Key features: - Multiple parallel agents for independent auditing (CLAUDE.md compliance, bug detection, historical context) - Confidence-based scoring (0-100) with 80+ threshold to filter false positives - Automatic skipping of closed, draft, or already-reviewed PRs - Links directly to code with full SHA and line ranges Updates: - Add code-review plugin directory with command and README - Update plugins/README.md to document the new plugin 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3be7215 commit 546f0b4

3 files changed

Lines changed: 342 additions & 0 deletions

File tree

‎plugins/README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,16 @@ Simplifies common git operations with streamlined commands for committing, pushi
3232
- `/clean_gone` - Clean up stale local branches marked as [gone]
3333
- **Use case**: Faster git workflows with less context switching
3434

35+
### [code-review](./code-review/)
36+
37+
**Automated Pull Request Code Review Plugin**
38+
39+
Provides automated code review for pull requests using multiple specialized agents with confidence-based scoring to filter false positives.
40+
41+
- **Command**:
42+
- `/code-review` - Automated PR review workflow
43+
- **Use case**: Automated code review on pull requests with high-confidence issue detection (threshold ≥80)
44+
3545
### [feature-dev](./feature-dev/)
3646

3747
**Comprehensive Feature Development Workflow Plugin**

‎plugins/code-review/README.md‎

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
# Code Review Plugin
2+
3+
Automated code review for pull requests using multiple specialized agents with confidence-based scoring to filter false positives.
4+
5+
## Overview
6+
7+
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.
8+
9+
## Commands
10+
11+
### `/code-review`
12+
13+
Performs automated code review on a pull request using multiple specialized agents.
14+
15+
**What it does:**
16+
1. Checks if review is needed (skips closed, draft, trivial, or already-reviewed PRs)
17+
2. Gathers relevant CLAUDE.md guideline files from the repository
18+
3. Summarizes the pull request changes
19+
4. Launches 4 parallel agents to independently review:
20+
- **Agents #1 & #2**: Audit for CLAUDE.md compliance
21+
- **Agent #3**: Scan for obvious bugs in changes
22+
- **Agent #4**: Analyze git blame/history for context-based issues
23+
5. Scores each issue 0-100 for confidence level
24+
6. Filters out issues below 80 confidence threshold
25+
7. Posts review comment with high-confidence issues only
26+
27+
**Usage:**
28+
```bash
29+
/code-review
30+
```
31+
32+
**Example workflow:**
33+
```bash
34+
# On a PR branch, run:
35+
/code-review
36+
37+
# Claude will:
38+
# - Launch 4 review agents in parallel
39+
# - Score each issue for confidence
40+
# - Post comment with issues ≥80 confidence
41+
# - Skip posting if no high-confidence issues found
42+
```
43+
44+
**Features:**
45+
- Multiple independent agents for comprehensive review
46+
- Confidence-based scoring reduces false positives (threshold: 80)
47+
- CLAUDE.md compliance checking with explicit guideline verification
48+
- Bug detection focused on changes (not pre-existing issues)
49+
- Historical context analysis via git blame
50+
- Automatic skipping of closed, draft, or already-reviewed PRs
51+
- Links directly to code with full SHA and line ranges
52+
53+
**Review comment format:**
54+
```markdown
55+
## Code review
56+
57+
Found 3 issues:
58+
59+
1. Missing error handling for OAuth callback (CLAUDE.md says "Always handle OAuth errors")
60+
61+
https://github.com/owner/repo/blob/abc123.../src/auth.ts#L67-L72
62+
63+
2. Memory leak: OAuth state not cleaned up (bug due to missing cleanup in finally block)
64+
65+
https://github.com/owner/repo/blob/abc123.../src/auth.ts#L88-L95
66+
67+
3. Inconsistent naming pattern (src/conventions/CLAUDE.md says "Use camelCase for functions")
68+
69+
https://github.com/owner/repo/blob/abc123.../src/utils.ts#L23-L28
70+
```
71+
72+
**Confidence scoring:**
73+
- **0**: Not confident, false positive
74+
- **25**: Somewhat confident, might be real
75+
- **50**: Moderately confident, real but minor
76+
- **75**: Highly confident, real and important
77+
- **100**: Absolutely certain, definitely real
78+
79+
**False positives filtered:**
80+
- Pre-existing issues not introduced in PR
81+
- Code that looks like a bug but isn't
82+
- Pedantic nitpicks
83+
- Issues linters will catch
84+
- General quality issues (unless in CLAUDE.md)
85+
- Issues with lint ignore comments
86+
87+
## Installation
88+
89+
This plugin is included in the Claude Code repository. The command is automatically available when using Claude Code.
90+
91+
## Best Practices
92+
93+
### Using `/code-review`
94+
- Maintain clear CLAUDE.md files for better compliance checking
95+
- Trust the 80+ confidence threshold - false positives are filtered
96+
- Run on all non-trivial pull requests
97+
- Review agent findings as a starting point for human review
98+
- Update CLAUDE.md based on recurring review patterns
99+
100+
### When to use
101+
- All pull requests with meaningful changes
102+
- PRs touching critical code paths
103+
- PRs from multiple contributors
104+
- PRs where guideline compliance matters
105+
106+
### When not to use
107+
- Closed or draft PRs (automatically skipped anyway)
108+
- Trivial automated PRs (automatically skipped)
109+
- Urgent hotfixes requiring immediate merge
110+
- PRs already reviewed (automatically skipped)
111+
112+
## Workflow Integration
113+
114+
### Standard PR review workflow:
115+
```bash
116+
# Create PR with changes
117+
/code-review
118+
119+
# Review the automated feedback
120+
# Make any necessary fixes
121+
# Merge when ready
122+
```
123+
124+
### As part of CI/CD:
125+
```bash
126+
# Trigger on PR creation or update
127+
# Automatically posts review comments
128+
# Skip if review already exists
129+
```
130+
131+
## Requirements
132+
133+
- Git repository with GitHub integration
134+
- GitHub CLI (`gh`) installed and authenticated
135+
- CLAUDE.md files (optional but recommended for guideline checking)
136+
137+
## Troubleshooting
138+
139+
### Review takes too long
140+
141+
**Issue**: Agents are slow on large PRs
142+
143+
**Solution**:
144+
- Normal for large changes - agents run in parallel
145+
- 4 independent agents ensure thoroughness
146+
- Consider splitting large PRs into smaller ones
147+
148+
### Too many false positives
149+
150+
**Issue**: Review flags issues that aren't real
151+
152+
**Solution**:
153+
- Default threshold is 80 (already filters most false positives)
154+
- Make CLAUDE.md more specific about what matters
155+
- Consider if the flagged issue is actually valid
156+
157+
### No review comment posted
158+
159+
**Issue**: `/code-review` runs but no comment appears
160+
161+
**Solution**:
162+
Check if:
163+
- PR is closed (reviews skipped)
164+
- PR is draft (reviews skipped)
165+
- PR is trivial/automated (reviews skipped)
166+
- PR already has review (reviews skipped)
167+
- No issues scored ≥80 (no comment needed)
168+
169+
### Link formatting broken
170+
171+
**Issue**: Code links don't render correctly in GitHub
172+
173+
**Solution**:
174+
Links must follow this exact format:
175+
```
176+
https://github.com/owner/repo/blob/[full-sha]/path/file.ext#L[start]-L[end]
177+
```
178+
- Must use full SHA (not abbreviated)
179+
- Must use `#L` notation
180+
- Must include line range with at least 1 line of context
181+
182+
### GitHub CLI not working
183+
184+
**Issue**: `gh` commands fail
185+
186+
**Solution**:
187+
- Install GitHub CLI: `brew install gh` (macOS) or see [GitHub CLI installation](https://cli.github.com/)
188+
- Authenticate: `gh auth login`
189+
- Verify repository has GitHub remote
190+
191+
## Tips
192+
193+
- **Write specific CLAUDE.md files**: Clear guidelines = better reviews
194+
- **Include context in PRs**: Helps agents understand intent
195+
- **Use confidence scores**: Issues ≥80 are usually correct
196+
- **Iterate on guidelines**: Update CLAUDE.md based on patterns
197+
- **Review automatically**: Set up as part of PR workflow
198+
- **Trust the filtering**: Threshold prevents noise
199+
200+
## Configuration
201+
202+
### Adjusting confidence threshold
203+
204+
The default threshold is 80. To adjust, modify the command file at `commands/code-review.md`:
205+
```markdown
206+
Filter out any issues with a score less than 80.
207+
```
208+
209+
Change `80` to your preferred threshold (0-100).
210+
211+
### Customizing review focus
212+
213+
Edit `commands/code-review.md` to add or modify agent tasks:
214+
- Add security-focused agents
215+
- Add performance analysis agents
216+
- Add accessibility checking agents
217+
- Add documentation quality checks
218+
219+
## Technical Details
220+
221+
### Agent architecture
222+
- **2x CLAUDE.md compliance agents**: Redundancy for guideline checks
223+
- **1x bug detector**: Focused on obvious bugs in changes only
224+
- **1x history analyzer**: Context from git blame and history
225+
- **Nx confidence scorers**: One per issue for independent scoring
226+
227+
### Scoring system
228+
- Each issue independently scored 0-100
229+
- Scoring considers evidence strength and verification
230+
- Threshold (default 80) filters low-confidence issues
231+
- For CLAUDE.md issues: verifies guideline explicitly mentions it
232+
233+
### GitHub integration
234+
Uses `gh` CLI for:
235+
- Viewing PR details and diffs
236+
- Fetching repository data
237+
- Reading git blame and history
238+
- Posting review comments
239+
240+
## Author
241+
242+
Boris Cherny ([email protected])
243+
244+
## Version
245+
246+
1.0.0
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
---
2+
allowed-tools: Bash(gh issue view:*), Bash(gh search:*), Bash(gh issue list:*), Bash(gh api:*), Bash(gh pr comment:*), Bash(gh pr diff:*), Bash(gh pr view:*), Bash(gh pr review:*), Bash(gh pr list:*)
3+
description: Code review a pull request
4+
---
5+
6+
Provide a code review for the given pull request.
7+
8+
To do this, follow these steps precisely:
9+
10+
1. Use an agent to check if the pull request (a) is closed, (b) is a draft, (c) does not need a code review (eg. because it is an automated pull request, or is very simple and obviously ok), or (d) already has a code review from you from earlier. If so, do not proceed.
11+
2. Use another agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root CLAUDE.md file (if one exists), as well as any CLAUDE.md files in the directories whose files the pull request modified
12+
3. Use an agent to view the pull request, and ask the agent to return a summary of the change
13+
4. Then, launch 4 parallel agents to independently code review the change. The agents should do the following, then return a list of issues and the reason each issue was flagged (eg. CLAUDE.md adherence, bug, historical git context, etc.):
14+
a. Agents #1 and #2: Independently audit the changes to make sure they compily with the CLAUDE.md
15+
b. Agent #3: Read the file changes in the pull request, then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore likely false positives.
16+
c. Agent #5: Read the git blame and history of the code modified, to identify any bugs in light of that historical context
17+
5. For each issue found in #4, launch a parallel agent that takes the PR, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or false positive. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. For issues that were flagged due to CLAUDE.md instructions, the agent should double check that the CLAUDE.md actually calls out that issue specifically. The scale is (give this rubric to the agent verbatim):
18+
a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue.
19+
b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md.
20+
c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the PR, it's not very important.
21+
d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach in the PR is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md.
22+
e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this.
23+
6. Filter out any issues with a score less than 80. If there are no issues that meet this criteria, do not proceed.
24+
7. Finally, comment back on the pull request with a list of issues you found. When writing your comment, keep in mind to:
25+
a. Keep your output brief
26+
b. Avoid emojis
27+
c. Link and cite relevant code, files, and URLs
28+
29+
Examples of false positives, for steps 4 and 5:
30+
31+
- Pre-existing issues
32+
- Something that looks like a bug but is not actually a bug
33+
- Pedantic nitpicks that a senior engineer wouldn't call out
34+
- Issues that a linter will catch (no need to run the linter to verify)
35+
- General code quality issues (eg. lack of test coverage, general security issues), unless explicitly required in CLAUDE.md
36+
- Issues that are called out in CLAUDE.md, but explicitly silenced in the code (eg. due to a lint ignore comment)
37+
38+
Notes:
39+
40+
- Use `gh` to interact with Github (eg. to fetch a pull request, or to create inline comments), rather than web fetch
41+
- Make a todo list first
42+
- You must cite and link each bug (eg. if referring to a CLAUDE.md, you must link it)
43+
- For your comment, follow the following format precisely (assuming for this example that you found 3 issues):
44+
45+
---
46+
47+
## Code review
48+
49+
Found 3 issues:
50+
51+
1. <brief description of bug> (CLAUDE.md says "<...>")
52+
53+
<link to file and line with full sha1 + line range for context, eg. https://github.com/anthropics/claude-code/blob/1d54823877c4de72b2316a64032a54afc404e619/README.md#L13-L17>
54+
55+
2. <brief description of bug> (some/other/CLAUDE.md says "<...>")
56+
57+
<link to file and line with full sha1 + line range for context>
58+
59+
3. <brief description of bug> (bug due to <file and code snippet>)
60+
61+
<link to file and line with full sha1 + line range for context>
62+
63+
🤖 Generated with [Claude Code](https://claude.ai/code)
64+
65+
<sub>[ANT-ONLY]</sub>
66+
<sub>- If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>
67+
<sub>- To improve the quality of this code review, update the relevant CLAUDE.md with better guidance or post in #claude-code-feedback on Slack for advice.</sub>
68+
69+
---
70+
71+
- Or, if you found no issues:
72+
73+
---
74+
75+
## Auto code review
76+
77+
No issues found. Checked for bugs and CLAUDE.md compliance.
78+
79+
## 🤖 Generated with [Claude Code](https://claude.ai/code)
80+
81+
- When linking to code, follow the following format precisely, otherwise the Markdown preview won't render correctly: https://github.com/anthropics/claude-cli-internal/blob/c21d3c10bc8e898b7ac1a2d745bdc9bc4e423afe/package.json#L10-L15
82+
- Requires full git sha
83+
- Repo name must match the repo you're code reviewing
84+
- # sign after the file name
85+
- Line range format is L[start]-L[end]
86+
- 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)