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
258 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. Outputs review (to terminal by default, or as PR comment with `--comment` flag)
26
27**Usage:**
28```bash
29/code-review [--comment]
30```
31
32**Options:**
33- `--comment`: Post the review as a comment on the pull request (default: outputs to terminal only)
34
35**Example workflow:**
36```bash
37# On a PR branch, run locally (outputs to terminal):
38/code-review
39
40# Post review as PR comment:
41/code-review --comment
42
43# Claude will:
44# - Launch 4 review agents in parallel
45# - Score each issue for confidence
46# - Output issues ≥80 confidence (to terminal or PR depending on flag)
47# - Skip if no high-confidence issues found
48```
49
50**Features:**
51- Multiple independent agents for comprehensive review
52- Confidence-based scoring reduces false positives (threshold: 80)
53- CLAUDE.md compliance checking with explicit guideline verification
54- Bug detection focused on changes (not pre-existing issues)
55- Historical context analysis via git blame
56- Automatic skipping of closed, draft, or already-reviewed PRs
57- Links directly to code with full SHA and line ranges
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# Run local review (outputs to terminal)
124/code-review
125
126# Review the automated feedback
127# Make any necessary fixes
128
129# Optionally post as PR comment
130/code-review --comment
131
132# Merge when ready
133```
134
135### As part of CI/CD:
136```bash
137# Trigger on PR creation or update
138# Use --comment flag to post review comments
139/code-review --comment
140# Skip if review already exists
141```
142
143## Requirements
144
145- Git repository with GitHub integration
146- GitHub CLI (`gh`) installed and authenticated
147- CLAUDE.md files (optional but recommended for guideline checking)
148
149## Troubleshooting
150
151### Review takes too long
152
153**Issue**: Agents are slow on large PRs
154
155**Solution**:
156- Normal for large changes - agents run in parallel
157- 4 independent agents ensure thoroughness
158- Consider splitting large PRs into smaller ones
159
160### Too many false positives
161
162**Issue**: Review flags issues that aren't real
163
164**Solution**:
165- Default threshold is 80 (already filters most false positives)
166- Make CLAUDE.md more specific about what matters
167- Consider if the flagged issue is actually valid
168
169### No review comment posted
170
171**Issue**: `/code-review` runs but no comment appears
172
173**Solution**:
174Check if:
175- PR is closed (reviews skipped)
176- PR is draft (reviews skipped)
177- PR is trivial/automated (reviews skipped)
178- PR already has review (reviews skipped)
179- No issues scored ≥80 (no comment needed)
180
181### Link formatting broken
182
183**Issue**: Code links don't render correctly in GitHub
184
185**Solution**:
186Links must follow this exact format:
187```
188https://github.com/owner/repo/blob/[full-sha]/path/file.ext#L[start]-L[end]
189```
190- Must use full SHA (not abbreviated)
191- Must use `#L` notation
192- Must include line range with at least 1 line of context
193
194### GitHub CLI not working
195
196**Issue**: `gh` commands fail
197
198**Solution**:
199- Install GitHub CLI: `brew install gh` (macOS) or see [GitHub CLI installation](https://cli.github.com/)
200- Authenticate: `gh auth login`
201- Verify repository has GitHub remote
202
203## Tips
204
205- **Write specific CLAUDE.md files**: Clear guidelines = better reviews
206- **Include context in PRs**: Helps agents understand intent
207- **Use confidence scores**: Issues ≥80 are usually correct
208- **Iterate on guidelines**: Update CLAUDE.md based on patterns
209- **Review automatically**: Set up as part of PR workflow
210- **Trust the filtering**: Threshold prevents noise
211
212## Configuration
213
214### Adjusting confidence threshold
215
216The default threshold is 80. To adjust, modify the command file at `commands/code-review.md`:
217```markdown
218Filter out any issues with a score less than 80.
219```
220
221Change `80` to your preferred threshold (0-100).
222
223### Customizing review focus
224
225Edit `commands/code-review.md` to add or modify agent tasks:
226- Add security-focused agents
227- Add performance analysis agents
228- Add accessibility checking agents
229- Add documentation quality checks
230
231## Technical Details
232
233### Agent architecture
234- **2x CLAUDE.md compliance agents**: Redundancy for guideline checks
235- **1x bug detector**: Focused on obvious bugs in changes only
236- **1x history analyzer**: Context from git blame and history
237- **Nx confidence scorers**: One per issue for independent scoring
238
239### Scoring system
240- Each issue independently scored 0-100
241- Scoring considers evidence strength and verification
242- Threshold (default 80) filters low-confidence issues
243- For CLAUDE.md issues: verifies guideline explicitly mentions it
244
245### GitHub integration
246Uses `gh` CLI for:
247- Viewing PR details and diffs
248- Fetching repository data
249- Reading git blame and history
250- Posting review comments
251
252## Author
253
254Boris Cherny (boris@anthropic.com)
255
256## Version
257
2581.0.0