1- name : Claude Code
1+ # Claude Code Review Workflow
2+ # - Auto-reviews PRs targeting main (excludes drafts and forks)
3+ # - Responds to @claude mentions from org members only
4+ # - Uses OIDC auth with Claude GitHub App (id-token: write)
5+ # - Mention jobs checkout base branch to avoid CodeQL "untrusted checkout" alerts
6+
7+ name : Claude review
28
39on :
4- # Auto-review PRs to main
10+ # Trigger: new/updated PRs to main
511 pull_request :
612 types : [opened, synchronize, ready_for_review, reopened]
713 branches :
814 - main
915
10- # @claude mentions in PR comments
16+ # Trigger: @claude mentions in comments
1117 issue_comment :
1218 types : [created]
1319 pull_request_review_comment :
1622 types : [submitted]
1723
1824jobs :
19- # Auto-review PRs targeting main
25+ # Job 1: Auto-review on PR open/update (no forks, no drafts)
2026 auto-review :
21- if : github.event_name == 'pull_request' && !github.event.pull_request.draft
27+ if : |
28+ github.event_name == 'pull_request' &&
29+ !github.event.pull_request.draft &&
30+ !github.event.pull_request.head.repo.fork
2231 runs-on : ubuntu-latest
32+ timeout-minutes : 15
2333 permissions :
2434 contents : read
2535 pull-requests : write
2636 id-token : write
37+ actions : read
2738 steps :
2839 - uses : actions/checkout@v6
2940 with :
41+ ref : ${{ github.event.pull_request.head.sha }}
3042 fetch-depth : 1
3143
3244 - uses : anthropics/claude-code-action@v1
3345 with :
3446 anthropic_api_key : ${{ secrets.ORG_ANTHROPIC_API_KEY }}
47+ additional_permissions : " actions: read"
3548 track_progress : true
3649 use_sticky_comment : true
3750 prompt : |
51+ Follow CLAUDE.md for project context and conventions.
52+ For contract details, read the relevant docs in /docs folder.
53+
3854 REPO: ${{ github.repository }}
3955 PR NUMBER: ${{ github.event.pull_request.number }}
4056
41- Perform a comprehensive code review focusing on:
42- - Code quality and best practices
43- - Potential bugs or security issues
44- - Performance considerations
45- - Test coverage
57+ First, identify the PR type from the title (feat|fix|docs|test|refactor|ci|perf|style|chore|release):
58+ - **feat/fix**: Full review - correctness, security, edge cases, gas, events, test coverage
59+ - **perf**: Focus on gas optimization correctness and no functional regressions
60+ - **test**: Check assertions are correct, edge cases covered, no false positives
61+ - **docs**: Check accuracy against actual code behavior
62+ - **style/refactor**: No functional changes - verify behavior is preserved
63+ - **chore/ci/release**: Light review - check for unintended side effects
64+
65+ For Solidity changes, check:
66+ 1. **Correctness**: Does it work? Edge cases handled? Invariants preserved?
67+ 2. **Security**: Access control, reentrancy, overflow, unsafe external calls
68+ 3. **Integration**: How do changes affect other contracts that interact with this one?
4669
47- Use inline comments for specific issues.
48- Use top-level comments for general observations.
70+ For each issue found:
71+ - Use inline comment on the specific line
72+ - Explain the problem
73+ - Provide a suggested fix as a diff block:
74+ ```diff
75+ - old code
76+ + new code
77+ ```
78+
79+ Use top-level comment for summary only.
4980
5081 claude_args : |
51- --allowedTools "Read,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
82+ --allowedTools "Read,Glob,Grep,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr checks:*),Bash(gh run list:*),Bash(gh run view:*)"
83+ --system-prompt "If you inspect CI logs, never paste raw logs. Summarize likely cause only. Redact tokens, keys, credentials, or URLs with credentials. If unsure, say log may contain sensitive data and stop."
5284 --max-turns 15
5385
54- # Respond to @claude mentions (members only, PRs only)
55- mention-response :
86+ # Job 2: @claude in PR conversation comments (members only)
87+ mention-pr-comment :
5688 if : |
57- (
58- (github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@claude')) ||
59- (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
60- (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude'))
61- ) &&
89+ github.event_name == 'issue_comment' &&
90+ github.event.issue.pull_request &&
91+ contains(github.event.comment.body, '@claude') &&
6292 (
6393 github.event.comment.author_association == 'MEMBER' ||
6494 github.event.comment.author_association == 'COLLABORATOR' ||
65- github.event.review.author_association == 'MEMBER' ||
66- github.event.review.author_association == 'COLLABORATOR'
95+ github.event.comment.author_association == 'OWNER'
96+ )
97+ runs-on : ubuntu-latest
98+ timeout-minutes : 10
99+ permissions :
100+ contents : read
101+ pull-requests : write
102+ issues : write
103+ id-token : write
104+ actions : read
105+ steps :
106+ # Verify this is not a fork PR (issue_comment doesn't have fork info in payload)
107+ - name : Check if fork PR
108+ id : fork-check
109+ env :
110+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
111+ run : |
112+ if ! IS_FORK=$(gh pr view ${{ github.event.issue.number }} --json isCrossRepository -q '.isCrossRepository'); then
113+ echo "Unable to determine fork status; skipping."
114+ echo "is_fork=true" >> $GITHUB_OUTPUT
115+ exit 0
116+ fi
117+ if [ "$IS_FORK" = "true" ]; then
118+ echo "Skipping fork PR"
119+ echo "is_fork=true" >> $GITHUB_OUTPUT
120+ else
121+ echo "is_fork=false" >> $GITHUB_OUTPUT
122+ fi
123+
124+ # Checkout base branch (trusted) - Claude reads PR diff via gh pr diff
125+ - uses : actions/checkout@v6
126+ if : steps.fork-check.outputs.is_fork != 'true'
127+ with :
128+ fetch-depth : 1
129+
130+ - uses : anthropics/claude-code-action@v1
131+ if : steps.fork-check.outputs.is_fork != 'true'
132+ with :
133+ anthropic_api_key : ${{ secrets.ORG_ANTHROPIC_API_KEY }}
134+ additional_permissions : " actions: read"
135+ claude_args : |
136+ --allowedTools "Read,Glob,Grep,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr checks:*),Bash(gh run list:*),Bash(gh run view:*)"
137+ --system-prompt "If you inspect CI logs, never paste raw logs. Summarize likely cause only. Redact tokens, keys, credentials, or URLs with credentials. If unsure, say log may contain sensitive data and stop."
138+ --max-turns 10
139+
140+ # Job 3: @claude in review comments/reviews (members only)
141+ mention-review :
142+ if : |
143+ !github.event.pull_request.head.repo.fork &&
144+ (
145+ (
146+ github.event_name == 'pull_request_review_comment' &&
147+ contains(github.event.comment.body, '@claude') &&
148+ (
149+ github.event.comment.author_association == 'MEMBER' ||
150+ github.event.comment.author_association == 'COLLABORATOR' ||
151+ github.event.comment.author_association == 'OWNER'
152+ )
153+ ) ||
154+ (
155+ github.event_name == 'pull_request_review' &&
156+ contains(github.event.review.body, '@claude') &&
157+ (
158+ github.event.review.author_association == 'MEMBER' ||
159+ github.event.review.author_association == 'COLLABORATOR' ||
160+ github.event.review.author_association == 'OWNER'
161+ )
162+ )
67163 )
68164 runs-on : ubuntu-latest
165+ timeout-minutes : 10
69166 permissions :
70167 contents : read
71168 pull-requests : write
72169 id-token : write
170+ actions : read
73171 steps :
172+ # Checkout base branch (trusted) - Claude reads PR diff via gh pr diff
74173 - uses : actions/checkout@v6
75174 with :
76175 fetch-depth : 1
77176
78177 - uses : anthropics/claude-code-action@v1
79178 with :
80179 anthropic_api_key : ${{ secrets.ORG_ANTHROPIC_API_KEY }}
180+ additional_permissions : " actions: read"
81181 claude_args : |
82- --allowedTools "Read,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*)"
182+ --allowedTools "Read,Glob,Grep,mcp__github_inline_comment__create_inline_comment,Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr checks:*),Bash(gh run list:*),Bash(gh run view:*)"
183+ --system-prompt "Follow CLAUDE.md for context. For issues found, provide a diff block showing the fix. If you inspect CI logs, summarize only - never paste raw logs. Redact any tokens, keys, or credentials."
83184 --max-turns 10
0 commit comments