Skip to content

Commit e646420

Browse files
CamSoperclaude
andauthored
Optimize Claude Code Review workflow for efficiency and reliability (#16312)
* Optimize Claude Code Review workflow for efficiency and reliability This change addresses two issues with the Claude Code Review workflow: 1. Reviews were not appearing on PRs (only in logs) 2. Excessive token usage from failed commands (~40-50% waste) Changes: - Instruct Claude to post its own review using gh pr comment - Add GITHUB_TOKEN env var to enable gh CLI authentication - Remove separate PR comment posting step (Claude does it directly) - Embed review criteria directly in prompt instead of failed /docs-review - Add CI efficiency guidelines to minimize token usage - Streamline allowed tools to essentials (Read, Glob, Grep, gh commands) - Reference .claude/commands/docs-review.md as source of truth Token savings: - Eliminates ~15K tokens from failed /docs-review slash command - Prevents wasted attempts at make serve, make lint, make build - Guides Claude to work from diffs before reading full files - Estimated 40-50% reduction in tokens per review (33K → 16-20K) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * Clarify terminology in fix-issue documentation by updating "Root Cause Analysis" to "Analysis" * Clarify analysis step in fix-issue documentation to specify desired outcome based on issue description --------- Co-authored-by: Claude <[email protected]>
1 parent 9eb88fb commit e646420

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

.claude/commands/fix-issue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Review and follow:
3030

3131
Create a detailed, step-by-step plan that includes:
3232

33-
1. **Root Cause Analysis**: Clearly identify what's causing the issue
33+
1. **Analysis**: Clearly identify the desired outcome in the docs based on the issue description and current implementation
3434
1. **Proposed Solution**: Describe the approach to fix the issue
3535
1. **Files to Modify**: List specific files and line numbers that need changes
3636
1. **Implementation Steps**: Break down the work into logical, sequential tasks

.github/workflows/claude-code-review.yml

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,40 @@ jobs:
3131
- name: Run Claude Code Review
3232
id: claude-review
3333
uses: anthropics/claude-code-action@v1
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3436
with:
3537
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
36-
# The /docs-review command (defined in .claude/commands/docs-review.md) contains the
37-
# canonical review criteria for this repository. This workflow invokes it
38-
# with PR-specific context.
38+
# The canonical review criteria are defined in .claude/commands/docs-review.md.
39+
# This prompt directs Claude to read that file as the source of truth.
3940
prompt: |
40-
You are reviewing pull request #${{ github.event.pull_request.number }}. Use the /docs-review command, defined in this repository at `.claude/commands/docs-review.md`, to guide your review.
41+
You are reviewing pull request #${{ github.event.pull_request.number }}.
4142
42-
Provide your review as a single GitHub pull request review comment, not multiple comments.
43-
44-
Use ````suggestion` blocks for any code suggestions.
43+
**CI Efficiency Guidelines (IMPORTANT - minimize token usage):**
44+
1. Start by running `gh pr view ${{ github.event.pull_request.number }} --json title,body,files,additions,deletions` to get PR metadata
45+
2. Get the full diff with `gh pr diff ${{ github.event.pull_request.number }}`
46+
3. Work primarily from the diff output - this is much more efficient than reading full files
47+
4. Only use the Read tool on specific files when the diff doesn't provide enough context
48+
5. Do NOT attempt to run `make serve`, `make lint`, or `make build` - these commands are not available in CI and will fail
49+
6. Focus your review on the changed lines shown in the diff, not entire files
50+
7. Use Grep sparingly - only when absolutely necessary to understand context
4551
46-
Include an instruction at the end of your review that informs the author how they can request additional reviews or have you apply your suggestions.
52+
**Review Criteria:**
53+
Read `.claude/commands/docs-review.md` for the complete, canonical review criteria. Use those criteria to guide your review.
54+
55+
**Posting Your Review:**
56+
After completing your review, post it to the PR by running:
57+
```
58+
gh pr comment ${{ github.event.pull_request.number }} --body "YOUR_REVIEW_CONTENT_HERE"
59+
```
60+
61+
Your review should include:
62+
- Issues found with specific line numbers
63+
- Constructive suggestions using ````suggestion` blocks
64+
- An instruction at the end telling the author how to request additional reviews
4765
4866
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
4967
# or https://docs.anthropic.com/en/docs/claude-code/sdk#command-line for available options
50-
claude_args: '--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:*)"'
68+
# Allow essential file reading tools (Read, Glob, Grep) and gh commands for PR interaction
69+
claude_args: '--allowed-tools "Read,Glob,Grep,Bash(gh pr view:*),Bash(gh pr diff:*),Bash(gh pr comment:*),Bash(gh issue view:*)"'
5170

0 commit comments

Comments
 (0)