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
246 lines · 7.1 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
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
57Found 3 issues:
58
591. Missing error handling for OAuth callback (CLAUDE.md says "Always handle OAuth errors")
60
61https://github.com/owner/repo/blob/abc123.../src/auth.ts#L67-L72
62
632. Memory leak: OAuth state not cleaned up (bug due to missing cleanup in finally block)
64
65https://github.com/owner/repo/blob/abc123.../src/auth.ts#L88-L95
66
673. Inconsistent naming pattern (src/conventions/CLAUDE.md says "Use camelCase for functions")
68
69https://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
89This 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**:
162Check 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**:
174Links must follow this exact format:
175```
176https://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
204The default threshold is 80. To adjust, modify the command file at `commands/code-review.md`:
205```markdown
206Filter out any issues with a score less than 80.
207```
208
209Change `80` to your preferred threshold (0-100).
210
211### Customizing review focus
212
213Edit `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
234Uses `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
242Boris Cherny (boris@anthropic.com)
243
244## Version
245
2461.0.0