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
120 lines · 6.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:*)
3description: Code review a pull request
4---
5
6Provide a code review for the given pull request.
7
8**Arguments:**
9- `--comment`: Post the review as a PR comment on GitHub. By default, the review is output to the terminal only.
10
11To do this, follow these steps precisely:
12
131. Launch a haiku agent to check if any of the following are true:
14 - The pull request is closed
15 - The pull request is a draft
16 - The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct)
17 - You have already submitted a code review on this pull request
18
19 If any condition is true, stop and do not proceed.
20
21Note: Still review Claude generated PR's.
22
232. Launch a haiku agent to return a list of file paths (not their contents) for all relevant CLAUDE.md files including:
24 - The root CLAUDE.md file, if it exists
25 - Any CLAUDE.md files in directories containing files modified by the pull request
26
273. Launch a sonnet agent to view the pull request and return a summary of the changes
28
294. 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:
30
31 Agents 1 + 2: CLAUDE.md compliance sonnet agents
32 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.
33
34 Agent 3: Opus bug agent (parallel subagent with agent 4)
35 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.
36
37 Agent 4: Opus bug agent (parallel subagent with agent 3)
38 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.
39
40 **CRITICAL: We only want HIGH SIGNAL issues.** This means:
41 - Objective bugs that will cause incorrect behavior at runtime
42 - Clear, unambiguous CLAUDE.md violations where you can quote the exact rule being broken
43
44 We do NOT want:
45 - Subjective concerns or "suggestions"
46 - Style preferences not explicitly required by CLAUDE.md
47 - Potential issues that "might" be problems
48 - Anything requiring interpretation or judgment calls
49
50 If you are not certain an issue is real, do not flag it. False positives erode trust and waste reviewer time.
51
52 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.
53
545. 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.
55
566. 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.
57
587. Finally, output the review:
59 - If `--comment` was passed as an argument, post the review as a comment on the pull request using `gh pr comment`
60 - Otherwise, output the review directly to the terminal (do NOT post to GitHub)
61
62 When writing your review, follow these guidelines:
63 a. Keep your output brief
64 b. Avoid emojis
65 c. Link and cite relevant code, files, and URLs for each issue
66 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")
67
68Use this list when evaluating issues in Steps 4 and 5 (these are false positives, do NOT flag):
69
70- Pre-existing issues
71- Something that appears to be a bug but is actually correct
72- Pedantic nitpicks that a senior engineer would not flag
73- Issues that a linter will catch (do not run the linter to verify)
74- General code quality concerns (e.g., lack of test coverage, general security issues) unless explicitly required in CLAUDE.md
75- Issues mentioned in CLAUDE.md but explicitly silenced in the code (e.g., via a lint ignore comment)
76
77Notes:
78
79- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch.
80- Create a todo list before starting.
81- You must cite and link each issue (e.g., if referring to a CLAUDE.md, include a link to it).
82- For your final comment, follow the following format precisely (assuming for this example that you found 3 issues):
83
84---
85
86## Code review
87
88Found 3 issues:
89
901. <brief description of bug> (CLAUDE.md says: "<exact quote from CLAUDE.md>")
91
92<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>
93
942. <brief description of bug> (some/other/CLAUDE.md says: "<exact quote from CLAUDE.md>")
95
96<link to file and line with full sha1 + line range for context>
97
983. <brief description of bug> (bug due to <file and code snippet>)
99
100<link to file and line with full sha1 + line range for context>
101
102---
103
104- Or, if you found no issues:
105
106---
107
108## Auto code review
109
110No issues found. Checked for bugs and CLAUDE.md compliance.
111
112---
113
114- 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
115 - Requires full git sha
116 - 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.
117 - Repo name must match the repo you're code reviewing
118 - # sign after the file name
119 - Line range format is L[start]-L[end]
120 - 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`)