spacehub

surshar / claude-code

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

Built by Anthropic · github.com/anthropics

claude-code / plugins / code-review / README.md
253 lines · 7.5 KBPreviewCodeRaw
1# Code Review Plugin
2
3Automated code review for pull requests using multiple specialized agents with confidence-based scoring to filter false positives.
4
5## Overview
6
7The 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
13Performs automated code review on a pull request using multiple specialized agents.
14
15**What it does:**
161. Checks if review is needed (skips closed, draft, trivial, or already-reviewed PRs)
172. Gathers relevant CLAUDE.md guideline files from the repository
183. Summarizes the pull request changes
194. 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
235. Scores each issue 0-100 for confidence level
246. Filters out issues below 80 confidence threshold
257. Posts review comment with high-confidence issues only
26
27**Usage:**
28```bash
29/code-review [--comment]
30```
31
32**Options:**
33- `--comment`: Post the review as a PR comment on GitHub. By default, the review is output to the terminal only.
34
35**Example workflow:**
36```bash
37# On a PR branch, run (outputs to terminal only):
38/code-review
39
40# Claude will:
41# - Launch 4 review agents in parallel
42# - Score each issue for confidence
43# - Output review with issues ≥80 confidence to terminal
44
45# To post review as a GitHub PR comment:
46/code-review --comment
47```
48
49**Features:**
50- Multiple independent agents for comprehensive review
51- Confidence-based scoring reduces false positives (threshold: 80)
52- CLAUDE.md compliance checking with explicit guideline verification
53- Bug detection focused on changes (not pre-existing issues)
54- Historical context analysis via git blame
55- Automatic skipping of closed, draft, or already-reviewed PRs
56- Links directly to code with full SHA and line ranges
57- Local-only output by default; use `--comment` flag to post to GitHub PR
58
59**Review comment format:**
60```markdown
61## Code review
62
63Found 3 issues:
64
651. Missing error handling for OAuth callback (CLAUDE.md says "Always handle OAuth errors")
66
67https://github.com/owner/repo/blob/abc123.../src/auth.ts#L67-L72
68
692. Memory leak: OAuth state not cleaned up (bug due to missing cleanup in finally block)
70
71https://github.com/owner/repo/blob/abc123.../src/auth.ts#L88-L95
72
733. Inconsistent naming pattern (src/conventions/CLAUDE.md says "Use camelCase for functions")
74
75https://github.com/owner/repo/blob/abc123.../src/utils.ts#L23-L28
76```
77
78**Confidence scoring:**
79- **0**: Not confident, false positive
80- **25**: Somewhat confident, might be real
81- **50**: Moderately confident, real but minor
82- **75**: Highly confident, real and important
83- **100**: Absolutely certain, definitely real
84
85**False positives filtered:**
86- Pre-existing issues not introduced in PR
87- Code that looks like a bug but isn't
88- Pedantic nitpicks
89- Issues linters will catch
90- General quality issues (unless in CLAUDE.md)
91- Issues with lint ignore comments
92
93## Installation
94
95This plugin is included in the Claude Code repository. The command is automatically available when using Claude Code.
96
97## Best Practices
98
99### Using `/code-review`
100- Maintain clear CLAUDE.md files for better compliance checking
101- Trust the 80+ confidence threshold - false positives are filtered
102- Run on all non-trivial pull requests
103- Review agent findings as a starting point for human review
104- Update CLAUDE.md based on recurring review patterns
105
106### When to use
107- All pull requests with meaningful changes
108- PRs touching critical code paths
109- PRs from multiple contributors
110- PRs where guideline compliance matters
111
112### When not to use
113- Closed or draft PRs (automatically skipped anyway)
114- Trivial automated PRs (automatically skipped)
115- Urgent hotfixes requiring immediate merge
116- PRs already reviewed (automatically skipped)
117
118## Workflow Integration
119
120### Standard PR review workflow:
121```bash
122# Create PR with changes
123/code-review
124
125# Review the automated feedback
126# Make any necessary fixes
127# Merge when ready
128```
129
130### As part of CI/CD:
131```bash
132# Trigger on PR creation or update
133# Automatically posts review comments
134# Skip if review already exists
135```
136
137## Requirements
138
139- Git repository with GitHub integration
140- GitHub CLI (`gh`) installed and authenticated
141- CLAUDE.md files (optional but recommended for guideline checking)
142
143## Troubleshooting
144
145### Review takes too long
146
147**Issue**: Agents are slow on large PRs
148
149**Solution**:
150- Normal for large changes - agents run in parallel
151- 4 independent agents ensure thoroughness
152- Consider splitting large PRs into smaller ones
153
154### Too many false positives
155
156**Issue**: Review flags issues that aren't real
157
158**Solution**:
159- Default threshold is 80 (already filters most false positives)
160- Make CLAUDE.md more specific about what matters
161- Consider if the flagged issue is actually valid
162
163### No review comment posted
164
165**Issue**: `/code-review` runs but no comment appears
166
167**Solution**:
168Check if:
169- PR is closed (reviews skipped)
170- PR is draft (reviews skipped)
171- PR is trivial/automated (reviews skipped)
172- PR already has review (reviews skipped)
173- No issues scored ≥80 (no comment needed)
174
175### Link formatting broken
176
177**Issue**: Code links don't render correctly in GitHub
178
179**Solution**:
180Links must follow this exact format:
181```
182https://github.com/owner/repo/blob/[full-sha]/path/file.ext#L[start]-L[end]
183```
184- Must use full SHA (not abbreviated)
185- Must use `#L` notation
186- Must include line range with at least 1 line of context
187
188### GitHub CLI not working
189
190**Issue**: `gh` commands fail
191
192**Solution**:
193- Install GitHub CLI: `brew install gh` (macOS) or see [GitHub CLI installation](https://cli.github.com/)
194- Authenticate: `gh auth login`
195- Verify repository has GitHub remote
196
197## Tips
198
199- **Write specific CLAUDE.md files**: Clear guidelines = better reviews
200- **Include context in PRs**: Helps agents understand intent
201- **Use confidence scores**: Issues ≥80 are usually correct
202- **Iterate on guidelines**: Update CLAUDE.md based on patterns
203- **Review automatically**: Set up as part of PR workflow
204- **Trust the filtering**: Threshold prevents noise
205- **Use `--comment` for CI/CD**: Post review to PR when running in automated workflows
206
207## Configuration
208
209### Adjusting confidence threshold
210
211The default threshold is 80. To adjust, modify the command file at `commands/code-review.md`:
212```markdown
213Filter out any issues with a score less than 80.
214```
215
216Change `80` to your preferred threshold (0-100).
217
218### Customizing review focus
219
220Edit `commands/code-review.md` to add or modify agent tasks:
221- Add security-focused agents
222- Add performance analysis agents
223- Add accessibility checking agents
224- Add documentation quality checks
225
226## Technical Details
227
228### Agent architecture
229- **2x CLAUDE.md compliance agents**: Redundancy for guideline checks
230- **1x bug detector**: Focused on obvious bugs in changes only
231- **1x history analyzer**: Context from git blame and history
232- **Nx confidence scorers**: One per issue for independent scoring
233
234### Scoring system
235- Each issue independently scored 0-100
236- Scoring considers evidence strength and verification
237- Threshold (default 80) filters low-confidence issues
238- For CLAUDE.md issues: verifies guideline explicitly mentions it
239
240### GitHub integration
241Uses `gh` CLI for:
242- Viewing PR details and diffs
243- Fetching repository data
244- Reading git blame and history
245- Posting review comments
246
247## Author
248
249Boris Cherny (boris@anthropic.com)
250
251## Version
252
2531.0.0