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 / commands / code-review.md
139 lines · 7.6 KBPreviewCodeRaw
1---
2allowed-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
3description: Code review a pull request
4---
5
6Provide a code review for the given pull request.
7
8To do this, follow these steps precisely:
9
101. Launch a haiku agent to check if any of the following are true:
11 - The pull request is closed
12 - The pull request is a draft
13 - The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct)
14 - Claude has already commented on this PR (check `gh pr view <PR> --comments` for comments left by claude)
15
16 If any condition is true, stop and do not proceed.
17
18Note: Still review Claude generated PR's.
19
202. Launch a haiku agent to return a list of file paths (not their contents) for all relevant CLAUDE.md files including:
21 - The root CLAUDE.md file, if it exists
22 - Any CLAUDE.md files in directories containing files modified by the pull request
23
243. Launch a sonnet agent to view the pull request and return a summary of the changes
25
264. 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:
27
28 Agents 1 + 2: CLAUDE.md compliance sonnet agents
29 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.
30
31 Agent 3: Opus bug agent (parallel subagent with agent 4)
32 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.
33
34 Agent 4: Opus bug agent (parallel subagent with agent 3)
35 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.
36
37 **CRITICAL: We only want HIGH SIGNAL issues.** This means:
38 - Objective bugs that will cause incorrect behavior at runtime
39 - Clear, unambiguous CLAUDE.md violations where you can quote the exact rule being broken
40
41 We do NOT want:
42 - Subjective concerns or "suggestions"
43 - Style preferences not explicitly required by CLAUDE.md
44 - Potential issues that "might" be problems
45 - Anything requiring interpretation or judgment calls
46
47 If you are not certain an issue is real, do not flag it. False positives erode trust and waste reviewer time.
48
49 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.
50
515. 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.
52
536. 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.
54
557. Post summary comment FIRST using `gh pr comment` (if `--comment` argument is provided):
56 - Total number of issues found
57 - Brief one-line summary of each issue (no "Bug:" prefix)
58 - Or if no issues: "No issues found. Checked for bugs and CLAUDE.md compliance."
59
60 When writing your comment, follow these guidelines:
61 a. Keep your output brief
62 b. Avoid emojis
63 c. Link and cite relevant code, files, and URLs for each issue
64 d. When citing CLAUDE.md violations, you MUST quote the exact text from CLAUDE.md that is being violated (e.g., CLAUDE.md says: "Use snake_case for variable names")
65
668. THEN post inline comments for each issue using `mcp__github_inline_comment__create_inline_comment`:
67 - `path`: the file path
68 - `line` (and `startLine` for ranges): select the buggy lines so the user sees them
69 - `body`: Brief description of the issue (no "Bug:" prefix). For small fixes (up to 5 lines changed), include a committable suggestion:
70 ```suggestion
71 corrected code here
72 ```
73 For larger fixes (6+ lines or structural changes), do NOT use suggestion blocks. Instead:
74 1. Describe what the issue is
75 2. Explain the suggested fix at a high level
76 3. Include a copyable prompt for Claude Code that the user can use to fix the issue, formatted as:
77 ```
78 Fix [file:line]: [brief description of issue and suggested fix]
79 ```
80
81 **IMPORTANT: Only post ONE comment per unique issue. Do not post duplicate comments.**
82
83Use this list when evaluating issues in Steps 4 and 5 (these are false positives, do NOT flag):
84
85- Pre-existing issues
86- Something that appears to be a bug but is actually correct
87- Pedantic nitpicks that a senior engineer would not flag
88- Issues that a linter will catch (do not run the linter to verify)
89- General code quality concerns (e.g., lack of test coverage, general security issues) unless explicitly required in CLAUDE.md
90- Issues mentioned in CLAUDE.md but explicitly silenced in the code (e.g., via a lint ignore comment)
91
92Notes:
93
94- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch.
95- Create a todo list before starting.
96- You must cite and link each issue (e.g., if referring to a CLAUDE.md, include a link to it).
97- For your final comment, follow the following format precisely (assuming for this example that you found 3 issues):
98
99---
100
101## Code review
102
103Found 3 issues:
104
1051. <brief description of bug> (CLAUDE.md says: "<exact quote from CLAUDE.md>")
106
107<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>
108
1092. <brief description of bug> (some/other/CLAUDE.md says: "<exact quote from CLAUDE.md>")
110
111<link to file and line with full sha1 + line range for context>
112
1133. <brief description of bug> (bug due to <file and code snippet>)
114
115<link to file and line with full sha1 + line range for context>
116
117<sub>If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>
118
119---
120
121- Or, if you found no issues:
122
123---
124
125## Auto code review
126
127No issues found. Checked for bugs and CLAUDE.md compliance.
128
129<sub>If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub>
130
131---
132
133- When linking to code, 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
134 - Requires full git sha
135 - 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.
136 - Repo name must match the repo you're code reviewing
137 - # sign after the file name
138 - Line range format is L[start]-L[end]
139 - 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`)