diff options
| author | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
|---|---|---|
| committer | Claude <noreply@anthropic.com> | 2026-11-06 00:54:48 +0000 |
| commit | 7aba3deae3ff17d032c37e07d2929d1426b34278 (patch) | |
| tree | 9c482f9acda1599bd2f9bed95a6a46b75e634e80 /plugins/code-review | |
| parent | 5472f5f56e0070feeeb464318b316714fe3e9105 (diff) | |
| parent | b8331dd69ab3e132bbf8cd6e89b5d8c1747e21b1 (diff) | |
Merge remote-tracking branch 'origin/main' into add-plugin/xcodeadd-plugin/xcode
Diffstat (limited to 'plugins/code-review')
| -rw-r--r-- | plugins/code-review/.claude-plugin/plugin.json | 1 | ||||
| -rw-r--r-- | plugins/code-review/README.md | 24 | ||||
| -rw-r--r-- | plugins/code-review/commands/code-review.md | 126 |
3 files changed, 91 insertions, 60 deletions
diff --git a/plugins/code-review/.claude-plugin/plugin.json b/plugins/code-review/.claude-plugin/plugin.json index c48abfeb..85fbd7c6 100644 --- a/plugins/code-review/.claude-plugin/plugin.json +++ b/plugins/code-review/.claude-plugin/plugin.json @@ -1,6 +1,7 @@ { "name": "code-review", "description": "Automated code review for pull requests using multiple specialized agents with confidence-based scoring", + "version": "1.0.1", "author": { "name": "Anthropic", "email": "support@anthropic.com" diff --git a/plugins/code-review/README.md b/plugins/code-review/README.md index b0962f09..42cc8095 100644 --- a/plugins/code-review/README.md +++ b/plugins/code-review/README.md @@ -22,23 +22,29 @@ Performs automated code review on a pull request using multiple specialized agen - **Agent #4**: Analyze git blame/history for context-based issues 5. Scores each issue 0-100 for confidence level 6. Filters out issues below 80 confidence threshold -7. Posts review comment with high-confidence issues only +7. Outputs review (to terminal by default, or as PR comment with `--comment` flag) **Usage:** ```bash -/code-review +/code-review [--comment] ``` +**Options:** +- `--comment`: Post the review as a comment on the pull request (default: outputs to terminal only) + **Example workflow:** ```bash -# On a PR branch, run: +# On a PR branch, run locally (outputs to terminal): /code-review +# Post review as PR comment: +/code-review --comment + # Claude will: # - Launch 4 review agents in parallel # - Score each issue for confidence -# - Post comment with issues ≥80 confidence -# - Skip posting if no high-confidence issues found +# - Output issues ≥80 confidence (to terminal or PR depending on flag) +# - Skip if no high-confidence issues found ``` **Features:** @@ -114,17 +120,23 @@ This plugin is included in the Claude Code repository. The command is automatica ### Standard PR review workflow: ```bash # Create PR with changes +# Run local review (outputs to terminal) /code-review # Review the automated feedback # Make any necessary fixes + +# Optionally post as PR comment +/code-review --comment + # Merge when ready ``` ### As part of CI/CD: ```bash # Trigger on PR creation or update -# Automatically posts review comments +# Use --comment flag to post review comments +/code-review --comment # Skip if review already exists ``` diff --git a/plugins/code-review/commands/code-review.md b/plugins/code-review/commands/code-review.md index c46e327f..8d1533fa 100644 --- a/plugins/code-review/commands/code-review.md +++ b/plugins/code-review/commands/code-review.md @@ -1,89 +1,107 @@ --- -allowed-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:*) +allowed-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 description: Code review a pull request disable-model-invocation: false --- Provide a code review for the given pull request. +**Agent assumptions (applies to all agents and subagents):** +- All tools are functional and will work without error. Do not test tools or make exploratory calls. Make sure this is clear to every subagent that is launched. +- Only call a tool if it is required to complete the task. Every tool call should have a clear purpose. + To do this, follow these steps precisely: -1. Use a Haiku agent to check if the pull request (a) is closed, (b) is a draft, (c) does not need a code review (eg. because it is an automated pull request, or is very simple and obviously ok), or (d) already has a code review from you from earlier. If so, do not proceed. -2. Use another Haiku agent to give you a list of file paths to (but not the contents of) any relevant CLAUDE.md files from the codebase: the root CLAUDE.md file (if one exists), as well as any CLAUDE.md files in the directories whose files the pull request modified -3. Use a Haiku agent to view the pull request, and ask the agent to return a summary of the change -4. Then, launch 5 parallel Sonnet agents to independently code review the change. The agents should do the following, then return a list of issues and the reason each issue was flagged (eg. CLAUDE.md adherence, bug, historical git context, etc.): - a. Agent #1: Audit the changes to make sure they compily with the CLAUDE.md. Note that CLAUDE.md is guidance for Claude as it writes code, so not all instructions will be applicable during code review. - b. Agent #2: Read the file changes in the pull request, then do a shallow scan for obvious bugs. Avoid reading extra context beyond the changes, focusing just on the changes themselves. Focus on large bugs, and avoid small issues and nitpicks. Ignore likely false positives. - c. Agent #3: Read the git blame and history of the code modified, to identify any bugs in light of that historical context - d. Agent #4: Read previous pull requests that touched these files, and check for any comments on those pull requests that may also apply to the current pull request. - e. Agent #5: Read code comments in the modified files, and make sure the changes in the pull request comply with any guidance in the comments. -5. For each issue found in #4, launch a parallel Haiku agent that takes the PR, issue description, and list of CLAUDE.md files (from step 2), and returns a score to indicate the agent's level of confidence for whether the issue is real or false positive. To do that, the agent should score each issue on a scale from 0-100, indicating its level of confidence. For issues that were flagged due to CLAUDE.md instructions, the agent should double check that the CLAUDE.md actually calls out that issue specifically. The scale is (give this rubric to the agent verbatim): - a. 0: Not confident at all. This is a false positive that doesn't stand up to light scrutiny, or is a pre-existing issue. - b. 25: Somewhat confident. This might be a real issue, but may also be a false positive. The agent wasn't able to verify that it's a real issue. If the issue is stylistic, it is one that was not explicitly called out in the relevant CLAUDE.md. - c. 50: Moderately confident. The agent was able to verify this is a real issue, but it might be a nitpick or not happen very often in practice. Relative to the rest of the PR, it's not very important. - d. 75: Highly confident. The agent double checked the issue, and verified that it is very likely it is a real issue that will be hit in practice. The existing approach in the PR is insufficient. The issue is very important and will directly impact the code's functionality, or it is an issue that is directly mentioned in the relevant CLAUDE.md. - e. 100: Absolutely certain. The agent double checked the issue, and confirmed that it is definitely a real issue, that will happen frequently in practice. The evidence directly confirms this. -6. Filter out any issues with a score less than 80. If there are no issues that meet this criteria, do not proceed. -7. Use a Haiku agent to repeat the eligibility check from #1, to make sure that the pull request is still eligible for code review. -8. Finally, use the gh bash command to comment back on the pull request with the result. When writing your comment, keep in mind to: - a. Keep your output brief - b. Avoid emojis - c. Link and cite relevant code, files, and URLs - -Examples of false positives, for steps 4 and 5: +1. Launch a haiku agent to check if any of the following are true: + - The pull request is closed + - The pull request is a draft + - The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct) + - Claude has already commented on this PR (check `gh pr view <PR> --comments` for comments left by claude) -- Pre-existing issues -- Something that looks like a bug but is not actually a bug -- Pedantic nitpicks that a senior engineer wouldn't call out -- Issues that a linter, typechecker, or compiler would catch (eg. missing or incorrect imports, type errors, broken tests, formatting issues, pedantic style issues like newlines). No need to run these build steps yourself -- it is safe to assume that they will be run separately as part of CI. -- General code quality issues (eg. lack of test coverage, general security issues, poor documentation), unless explicitly required in CLAUDE.md -- Issues that are called out in CLAUDE.md, but explicitly silenced in the code (eg. due to a lint ignore comment) -- Changes in functionality that are likely intentional or are directly related to the broader change -- Real issues, but on lines that the user did not modify in their pull request + If any condition is true, stop and do not proceed. -Notes: +Note: Still review Claude generated PR's. -- Do not check build signal or attempt to build or typecheck the app. These will run separately, and are not relevant to your code review. -- Use `gh` to interact with Github (eg. to fetch a pull request, or to create inline comments), rather than web fetch -- Make a todo list first -- You must cite and link each bug (eg. if referring to a CLAUDE.md, you must link it) -- For your final comment, follow the following format precisely (assuming for this example that you found 3 issues): +2. Launch a haiku agent to return a list of file paths (not their contents) for all relevant CLAUDE.md files including: + - The root CLAUDE.md file, if it exists + - Any CLAUDE.md files in directories containing files modified by the pull request ---- +3. Launch a sonnet agent to view the pull request and return a summary of the changes -### Code review +4. 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: -Found 3 issues: + Agents 1 + 2: CLAUDE.md compliance sonnet agents + 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. -1. <brief description of bug> (CLAUDE.md says "<...>") + Agent 3: Opus bug agent (parallel subagent with agent 4) + 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. -<link to file and line with full sha1 + line range for context, note that you MUST provide the full sha and not use bash here, eg. https://github.com/anthropics/claude-code/blob/1d54823877c4de72b2316a64032a54afc404e619/README.md#L13-L17> + Agent 4: Opus bug agent (parallel subagent with agent 3) + 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. -2. <brief description of bug> (some/other/CLAUDE.md says "<...>") + **CRITICAL: We only want HIGH SIGNAL issues.** Flag issues where: + - The code will fail to compile or parse (syntax errors, type errors, missing imports, unresolved references) + - The code will definitely produce wrong results regardless of inputs (clear logic errors) + - Clear, unambiguous CLAUDE.md violations where you can quote the exact rule being broken -<link to file and line with full sha1 + line range for context> + Do NOT flag: + - Code style or quality concerns + - Potential issues that depend on specific inputs or state + - Subjective suggestions or improvements -3. <brief description of bug> (bug due to <file and code snippet>) + If you are not certain an issue is real, do not flag it. False positives erode trust and waste reviewer time. -<link to file and line with full sha1 + line range for context> + 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. -🤖 Generated with [Claude Code](https://claude.ai/code) +5. 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. -<sub>- If this code review was useful, please react with 👍. Otherwise, react with 👎.</sub> +6. 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. ---- +7. Output a summary of the review findings to the terminal: + - If issues were found, list each issue with a brief description. + - If no issues were found, state: "No issues found. Checked for bugs and CLAUDE.md compliance." + + If `--comment` argument was NOT provided, stop here. Do not post any GitHub comments. + + If `--comment` argument IS provided and NO issues were found, post a summary comment using `gh pr comment` and stop. + + If `--comment` argument IS provided and issues were found, continue to step 8. + +8. Create a list of all comments that you plan on leaving. This is only for you to make sure you are comfortable with the comments. Do not post this list anywhere. -- Or, if you found no issues: +9. Post inline comments for each issue using `mcp__github_inline_comment__create_inline_comment` with `confirmed: true`. For each comment: + - Provide a brief description of the issue + - For small, self-contained fixes, include a committable suggestion block + - For larger fixes (6+ lines, structural changes, or changes spanning multiple locations), describe the issue and suggested fix without a suggestion block + - Never post a committable suggestion UNLESS committing the suggestion fixes the issue entirely. If follow up steps are required, do not leave a committable suggestion. + + **IMPORTANT: Only post ONE comment per unique issue. Do not post duplicate comments.** + +Use this list when evaluating issues in Steps 4 and 5 (these are false positives, do NOT flag): + +- Pre-existing issues +- Something that appears to be a bug but is actually correct +- Pedantic nitpicks that a senior engineer would not flag +- Issues that a linter will catch (do not run the linter to verify) +- General code quality concerns (e.g., lack of test coverage, general security issues) unless explicitly required in CLAUDE.md +- Issues mentioned in CLAUDE.md but explicitly silenced in the code (e.g., via a lint ignore comment) + +Notes: + +- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch. +- Create a todo list before starting. +- You must cite and link each issue in inline comments (e.g., if referring to a CLAUDE.md, include a link to it). +- If no issues are found and `--comment` argument is provided, post a comment with the following format: --- -### Code review +## Code review No issues found. Checked for bugs and CLAUDE.md compliance. -🤖 Generated with [Claude Code](https://claude.ai/code) +--- -- When linking to code, follow the following format precisely, otherwise the Markdown preview won't render correctly: https://github.com/anthropics/claude-cli-internal/blob/c21d3c10bc8e898b7ac1a2d745bdc9bc4e423afe/package.json#L10-L15 +- When linking to code in inline comments, 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 - Requires full git sha - 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. - Repo name must match the repo you're code reviewing |
