-
Notifications
You must be signed in to change notification settings - Fork 3.1k
added claude code review CI workflow #33037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| name: 'Check: Code Review' | ||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize] | ||
|
Comment on lines
+3
to
+4
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: For the anthropics/claude-code-action v1 used with the pull_request_target trigger, the key security guidance for checking out the PR head follows GitHub Actions best practices to avoid executing untrusted code in a privileged context. Do not check out the PR head (github.event.pull_request.head.sha) directly in pull_request_target workflows, as this grants attackers access to secrets like ANTHROPIC_API_KEY while running potentially malicious code from the PR branch. This is a well-documented supply chain attack vector. Official examples in anthropics/claude-code-action docs/solutions.md and security.md use 'on: pull_request' (not _target) with standard actions/checkout@v4+ (fetch-depth:1), which checks out the merge commit safely in a read-only context without secrets. The action supports pull_request_target (added in PR Citations:
🏁 Script executed: cat -n .github/workflows/check_review.ymlRepository: musescore/MuseScore Length of output: 608 🏁 Script executed: fd -e yml -e yaml .github/workflows/ | head -20Repository: musescore/MuseScore Length of output: 440 🏁 Script executed: fd . '.github/workflows/' -e yml -e yamlRepository: musescore/MuseScore Length of output: 960 🏁 Script executed: cat -n .github/workflows/triage_prs.ymlRepository: musescore/MuseScore Length of output: 1036 🏁 Script executed: cat -n .github/workflows/claude.ymlRepository: musescore/MuseScore Length of output: 2461 Security: This workflow uses
Apply these mitigations together:
Note: The 🤖 Prompt for AI Agents |
||
| jobs: | ||
| review: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: anthropics/claude-code-action@v1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider pinning This action ships with an API key and is granted write access to PRs/issues. A mutable Note: this repo's convention for 🤖 Prompt for AI Agents |
||
| with: | ||
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | ||
|
Comment on lines
+6
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Declare an explicit least-privilege Two concerns based on the upstream
♻️ Suggested baseline jobs:
review:
runs-on: ubuntu-latest
+ permissions:
+ contents: read
+ pull-requests: write
+ issues: write
steps:
+ - uses: actions/checkout@v4
+ with:
+ fetch-depth: 1
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: "Review this pull request for code quality, correctness, and security. Analyze the diff, then post your findings as review comments."
claude_args: "--max-turns 5"Please confirm against the pinned 🤖 Prompt for AI Agents |
||
| prompt: "Review this pull request for code quality, correctness, and security. Analyze the diff, then post your findings as review comments." | ||
| claude_args: "--max-turns 5" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: Claude Code | ||
|
|
||
| on: | ||
| issue_comment: | ||
| types: [created] | ||
| pull_request_review_comment: | ||
| types: [created] | ||
| issues: | ||
| types: [opened, assigned] | ||
| pull_request_review: | ||
| types: [submitted] | ||
|
|
||
| jobs: | ||
| claude: | ||
| if: | | ||
| (github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) || | ||
| (github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) | ||
|
Comment on lines
+15
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider gating Any user who can comment on an issue/PR (including drive-by accounts) can invoke this workflow by typing (github.event.comment.author_association == 'OWNER' ||
github.event.comment.author_association == 'MEMBER' ||
github.event.comment.author_association == 'COLLABORATOR')applied per event type. This prevents anonymous cost/abuse exposure while keeping the feature available to maintainers. 🤖 Prompt for AI Agents |
||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| issues: write | ||
| id-token: write | ||
| actions: read # Required for Claude to read CI results on PRs | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Run Claude Code | ||
| id: claude | ||
| uses: anthropics/claude-code-action@v1 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Same mutable-ref concern as This is consistent with the prior review on the sibling workflow; the repo's 🤖 Prompt for AI Agents |
||
| with: | ||
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} | ||
|
|
||
| # Optional: Customize the trigger phrase (default: @claude) | ||
| # trigger_phrase: "/claude" | ||
|
|
||
| # Optional: Trigger when specific user is assigned to an issue | ||
| # assignee_trigger: "claude-bot" | ||
|
|
||
| # Optional: Configure Claude's behavior with CLI arguments | ||
| # claude_args: | | ||
| # --model claude-opus-4-1-20250805 | ||
| # --max-turns 10 | ||
| # --allowedTools "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)" | ||
| # --system-prompt "Follow our coding standards. Ensure all new code has tests. Use TypeScript for new files." | ||
|
|
||
| # Optional: Advanced settings configuration | ||
| # settings: | | ||
| # { | ||
| # "env": { | ||
| # "NODE_ENV": "test" | ||
| # } | ||
| # } | ||
|
Comment on lines
+39
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Strip commented-out boilerplate before merging. ~20 lines of vendor-example comments add no value in a production workflow and will decay over time as the upstream example changes. If any of these options are planned (e.g., 🤖 Prompt for AI Agents |
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 761
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 601
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 1707
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 45
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 118
🌐 Web query:
GitHub Actions fork pull_request secrets not available documentation💡 Result:
In GitHub Actions, repository secrets (and organization/environment secrets) are not available to workflows triggered by pull_request events from forked repositories. This is a security feature to prevent malicious actors from accessing secrets via PRs from forks. Official documentation explicitly states: "With the exception of GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository." (Using secrets in GitHub Actions). Also, "Actions secrets are not passed to workflows that are triggered by a pull request from a fork." (Understanding GitHub secret types). To use secrets in workflows for PRs from forks: - Use the pull_request_target event instead of pull_request. This runs the workflow in the context of the base branch (trusted), providing access to secrets and a read/write GITHUB_TOKEN. - Critical security warning: Do not checkout or execute untrusted code from the PR (e.g., avoid actions/checkout with ref: ${{ github.event.pull_request.head.sha }} unchecked). Use only for safe actions like labeling, commenting, or metadata checks. Always review PR changes, especially to .github/workflows/. For private repositories, repo settings allow limited options like "Send secrets to workflows from pull requests" under Fork pull request workflows (requires org/repo admin), but this is not recommended for public repos and still has risks. GITHUB_TOKEN is always available but read-only for pull_request from forks. Primary docs: - https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions (Result 6) - https://docs.github.com/en/code-security/getting-started/understanding-github-secret-types (Result 19) - https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/enabling-features-for-your-repository/managing-github-actions-settings-for-a-repository (Result 10)
Citations:
🌐 Web query:
anthropics claude-code-action requirements checkout permissions💡 Result:
Anthropic's claude-code-action is a GitHub Action for integrating Claude Code into GitHub workflows, enabling AI-powered code reviews, edits, and automation on PRs and issues via
@claudementions. Requirements: - Repository admin access. - Anthropic API key (ANTHROPIC_API_KEY) or Claude Code OAuth token (CLAUDE_CODE_OAUTH_TOKEN) as repo secret. - actions/checkout@v4 step in workflow to check out repository code (standard for GitHub Actions; Claude uses native Read/Glob/Grep tools on checked-out files). Permissions (GitHub App): Official Claude app (https://github.com/apps/claude): Install to repo; requests: - Repository permissions: Contents (Read & Write), Issues (Read & Write), Pull requests (Read & Write). - Account permissions: None. Custom GitHub App (minimum): - Repository: Contents (Read & Write), Issues (Read & Write), Pull requests (Read & Write). Workflow example: jobs: claude: runs-on: ubuntu-latest permissions: contents: write issues: write pull-requests: write steps: - uses: actions/checkout@v4 - uses: anthropics/claude-code-action@v1 with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} Claude Code permissions (tool use): Configurable via claude_args (e.g., --allowed-tools), /permissions command, or settings.json. Read-only tools (Read, Grep) need no approval; Bash etc. do. Note: Tool restrictions may not fully block native file reads in CI. Security: Use secrets, minimal permissions, sandbox (e.g., Docker). Known issue: Restricted tools may still allow file reads on checked-out repo.Citations:
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 96
🏁 Script executed:
Repository: musescore/MuseScore
Length of output: 645
Fork PRs will fail:
ANTHROPIC_API_KEYis not exposed to workflows triggered bypull_requestfrom forks, andactions/checkoutis missing.GitHub does not pass repository secrets to
pull_requestruns originating from forked repositories—external contributors' PRs will execute with an emptyANTHROPIC_API_KEYand fail silently. Additionally,anthropics/claude-code-action@v1requires anactions/checkout@v4step (the action uses native Read/Glob/Grep tools on checked-out files), which is currently missing.Two options:
if: github.event.pull_request.head.repo.full_name == github.repository) to avoid red X's on every external PR. If pursuing this path, still addactions/checkout@v4for non-fork runs.pull_request_targetinstead, which runs in the context of the base branch with write-scoped secrets and secret access. Do not combine this withactions/checkoutof the PR head, and keep the prompt/config entirely in-repo to avoid privilege-escalation via malicious PR content. Add this step for checkout:- uses: actions/checkout@v4(checks out the base branch by default underpull_request_target).Additionally:
permissionsblock (contents, issues, pull-requests all read/write) per the official example.concurrencygroup to prevent multiple expensive Claude API runs from racing when rapid pushes occur onsynchronizeevents.🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@CodeRabbit please check again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 538
@igorkorsukov, the file has not changed since my initial review — all four issues are still present. Here's a summary and a suggested corrected workflow:Issues still present
pull_requesttrigger — secrets not available to fork PRsANTHROPIC_API_KEYwill be empty for external contributors; workflow fails silentlyactions/checkout@v4Checkout repositorystep (usingactions/checkout@v4withfetch-depth: 0) beforeanthropics/claude-code-action@v1— Claude needs the repo files to analyse the diffpermissionsblockcontents: write,pull-requests: write,issues: write, andid-token: writeat the job level; without these the action cannot post review commentsconcurrencygroupsynchronizeevents, rapid pushes will queue up multiple expensive Claude API runsSuggested fix
Key changes:
if:condition — skips the job for fork PRs to avoid red check failures from missing secrets.actions/checkout@v4— required by the action to read repository files.permissions— grants the action the rights to post PR review comments.concurrency— cancels in-progress runs when a new push arrives on the same PR.🧠 Learnings used