Skip to content

Commit 875c3ba

Browse files
committed
Merge branch 'code-review'
2 parents e41c3af + afaf90e commit 875c3ba

File tree

2 files changed

+88
-58
lines changed

2 files changed

+88
-58
lines changed

.claude/commands/code-review.md

Lines changed: 12 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
---
2-
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
3-
description: Code review a pull request
2+
allowed-tools: Bash(git diff:*), Bash(git log:*), Bash(git merge-base:*), Bash(git rev-parse:*)
3+
description: Code review changes since branch diverged from default branch
44
---
55

6-
Provide a code review for the given pull request.
6+
Review the code changes introduced since this branch diverged from the default branch (main).
77

88
**Agent assumptions (applies to all agents and subagents):**
99
- 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.
1010
- Only call a tool if it is required to complete the task. Every tool call should have a clear purpose.
1111

1212
To do this, follow these steps precisely:
1313

14-
1. Launch a haiku agent to check if any of the following are true:
15-
- The pull request is closed
16-
- The pull request is a draft
17-
- The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct)
18-
- Claude has already commented on this PR (check `gh pr view <PR> --comments` for comments left by claude)
19-
20-
If any condition is true, stop and do not proceed.
21-
22-
Note: Still review Claude generated PR's.
14+
1. Run `git diff main...HEAD` to get the diff and `git log main..HEAD --oneline` to get the commit list. If the diff is empty, stop and report there are no changes to review.
2315

2416
2. Launch a haiku agent to return a list of file paths (not their contents) for all relevant CLAUDE.md files including:
2517
- The root CLAUDE.md file, if it exists
26-
- Any CLAUDE.md files in directories containing files modified by the pull request
27-
28-
3. Launch a sonnet agent to view the pull request and return a summary of the changes
18+
- Any CLAUDE.md files in directories containing files modified in the diff
2919

30-
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:
20+
3. 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:
3121

3222
Agents 1 + 2: CLAUDE.md compliance sonnet agents
3323
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.
@@ -50,33 +40,15 @@ Note: Still review Claude generated PR's.
5040

5141
If you are not certain an issue is real, do not flag it. False positives erode trust and waste reviewer time.
5242

53-
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.
43+
4. For each issue found in the previous step by agents 3 and 4, launch parallel subagents to validate 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.
5444

55-
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.
45+
5. Filter out any issues that were not validated in step 4. This step will give us our list of high signal issues for our review.
5646

57-
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.
58-
59-
7. Output a summary of the review findings to the terminal:
60-
- If issues were found, list each issue with a brief description.
47+
6. Output a summary of the review findings to the terminal:
48+
- If issues were found, list each issue with a brief description and the file/line it occurs in.
6149
- If no issues were found, state: "No issues found. Checked for bugs and CLAUDE.md compliance."
6250

63-
If `--comment` argument was NOT provided, stop here. Do not post any GitHub comments.
64-
65-
If `--comment` argument IS provided and NO issues were found, post a summary comment using `gh pr comment` and stop.
66-
67-
If `--comment` argument IS provided and issues were found, continue to step 8.
68-
69-
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.
70-
71-
9. Post inline comments for each issue using `mcp__github_inline_comment__create_inline_comment` with `confirmed: true`. For each comment:
72-
- Provide a brief description of the issue
73-
- For small, self-contained fixes, include a committable suggestion block
74-
- For larger fixes (6+ lines, structural changes, or changes spanning multiple locations), describe the issue and suggested fix without a suggestion block
75-
- 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.
76-
77-
**IMPORTANT: Only post ONE comment per unique issue. Do not post duplicate comments.**
78-
79-
Use this list when evaluating issues in Steps 4 and 5 (these are false positives, do NOT flag):
51+
Use this list when evaluating issues in Steps 3 and 4 (these are false positives, do NOT flag):
8052

8153
- Pre-existing issues
8254
- Something that appears to be a bug but is actually correct
@@ -87,23 +59,5 @@ Use this list when evaluating issues in Steps 4 and 5 (these are false positives
8759

8860
Notes:
8961

90-
- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch.
9162
- Create a todo list before starting.
92-
- You must cite and link each issue in inline comments (e.g., if referring to a CLAUDE.md, include a link to it).
93-
- If no issues are found and `--comment` argument is provided, post a comment with the following format:
94-
95-
---
96-
97-
## Code review
98-
99-
No issues found. Checked for bugs and CLAUDE.md compliance.
100-
101-
---
102-
103-
- 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
104-
- Requires full git sha
105-
- 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.
106-
- Repo name must match the repo you're code reviewing
107-
- # sign after the file name
108-
- Line range format is L[start]-L[end]
109-
- 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`)
63+
- You must cite each issue with the file path and line number.

.claude/commands/pr-review.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
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
3+
description: Code review a pull request
4+
---
5+
6+
Provide a code review for the given pull request.
7+
8+
**Agent assumptions (applies to all agents and subagents):**
9+
- 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.
10+
- Only call a tool if it is required to complete the task. Every tool call should have a clear purpose.
11+
12+
To do this, follow these steps precisely:
13+
14+
1. Launch a haiku agent to check if any of the following are true:
15+
- The pull request is closed
16+
- The pull request is a draft
17+
- The pull request does not need code review (e.g. automated PR, trivial change that is obviously correct)
18+
19+
If any condition is true, stop and do not proceed.
20+
21+
Note: Still review Claude generated PR's.
22+
23+
2. 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+
27+
3. Launch a sonnet agent to view the pull request and return a summary of the changes
28+
29+
4. **Follow steps 3–5 from `/code-review`** to run the parallel review agents and validate issues. Use the PR diff (obtained via `gh pr diff`) as the diff input. Pass the PR title and description as context to each subagent so they understand the author's intent.
30+
31+
5. Output a summary of the review findings to the terminal:
32+
- If issues were found, list each issue with a brief description.
33+
- If no issues were found, state: "No issues found. Checked for bugs and CLAUDE.md compliance."
34+
35+
If `--comment` argument was NOT provided, stop here. Do not post any GitHub comments.
36+
37+
If `--comment` argument IS provided and NO issues were found, post a summary comment using `gh pr comment` and stop.
38+
39+
If `--comment` argument IS provided and issues were found, continue to step 6.
40+
41+
6. 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.
42+
43+
7. Post inline comments for each issue using `mcp__github_inline_comment__create_inline_comment` with `confirmed: true`. For each comment:
44+
- Provide a brief description of the issue
45+
- For small, self-contained fixes, include a committable suggestion block
46+
- For larger fixes (6+ lines, structural changes, or changes spanning multiple locations), describe the issue and suggested fix without a suggestion block
47+
- 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.
48+
- If there's already a previous inline comment for the issue, update it instead of creating a new inline comment.
49+
- Suffix every comment body with: "Generated by AI (Anthropic Claude, [model name of the agent posting the comment])"
50+
51+
**IMPORTANT: Only post ONE comment per unique issue. Do not post duplicate comments.**
52+
53+
8. Check for previous comments from Claude about issues that are not present anymore and resolve the conversation.
54+
55+
Notes:
56+
57+
- Use gh CLI to interact with GitHub (e.g., fetch pull requests, create comments). Do not use web fetch.
58+
- Create a todo list before starting.
59+
- You must cite and link each issue in inline comments (e.g., if referring to a CLAUDE.md, include a link to it).
60+
- If no issues are found and `--comment` argument is provided, post a comment with the following format:
61+
62+
---
63+
64+
No issues found through automated code review.
65+
66+
Generated by AI (Anthropic Claude, [model name])
67+
68+
---
69+
70+
- 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
71+
- Requires full git sha
72+
- 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.
73+
- Repo name must match the repo you're code reviewing
74+
- # sign after the file name
75+
- Line range format is L[start]-L[end]
76+
- Provide at least 1 line of context before and after, centered on the line you are commenting about (e.g. if you are commenting about lines 5-6, you should link to `L4-7`)

0 commit comments

Comments
 (0)