ci: add @claude PR comment responder workflow#973
Conversation
Add .github/workflows/claude.yml, which runs a Claude Code session via the official anthropics/claude-code-action whenever a collaborator mentions "@claude" on a PR comment or review. Unlike a subscribed chat session, this fires on the webhook every time, so it keeps working after the session that opened the PR has ended. The job is gated to non-bot authors mentioning the trigger phrase, skips gracefully when ANTHROPIC_API_KEY is unset, and requests only the permissions needed to push a scoped fix and reply. The action is pinned to the reviewed v1.0.178 commit SHA and registered in scripts/github-action-pins.mjs so the Actions pin check passes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0164nBbEeLzQWWZqBn95o3MW
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
📝 WalkthroughWalkthroughAdds a GitHub Actions workflow that runs Claude for human ChangesClaude workflow integration
Estimated code review effort: 2 (Simple) | ~10 minutes Sequence Diagram(s)sequenceDiagram
participant Human
participant GitHub
participant ClaudeWorkflow
participant ClaudeCodeAction
Human->>GitHub: Mention `@claude` in PR discussion
GitHub->>ClaudeWorkflow: Trigger workflow event
ClaudeWorkflow->>ClaudeWorkflow: Validate human author and API key
ClaudeWorkflow->>ClaudeCodeAction: Run pinned action
ClaudeCodeAction->>GitHub: Update PR branch or discussion
Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/claude.yml:
- Around line 27-38: The Claude workflow trigger condition currently allows any
non-bot user to invoke the job. Update the issue_comment,
pull_request_review_comment, and pull_request_review branches in the workflow if
expression to require the corresponding user’s association to be OWNER, MEMBER,
or COLLABORATOR, while preserving the existing `@claude` and event-specific
checks.
- Around line 57-64: Update the Checkout repository step before Run Claude Code
to resolve github.event.issue.pull_request and configure actions/checkout with
the pull request’s repository, head.ref, and head.sha, ensuring Claude runs
against the PR head rather than the issue-comment event ref.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9376f82d-6733-4f4b-8489-eb924ef49efb
📒 Files selected for processing (2)
.github/workflows/claude.ymlscripts/github-action-pins.mjs
| if: > | ||
| (github.event_name == 'issue_comment' && | ||
| github.event.issue.pull_request != null && | ||
| github.event.comment.user.type != 'Bot' && | ||
| contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review_comment' && | ||
| github.event.comment.user.type != 'Bot' && | ||
| contains(github.event.comment.body, '@claude')) || | ||
| (github.event_name == 'pull_request_review' && | ||
| github.event.review.user.type != 'Bot' && | ||
| github.event.review.body != null && | ||
| contains(github.event.review.body, '@claude')) |
There was a problem hiding this comment.
🔒 Security & Privacy | 🔴 Critical | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the workflow around the referenced lines.
wc -l .github/workflows/claude.yml
cat -n .github/workflows/claude.yml | sed -n '1,220p'
# Look for any authorization / collaborator / association checks in the workflow.
rg -n "association|OWNER|MEMBER|COLLABORATOR|trusted|collaborator|bot|`@claude`|permissions:|contents: write|pull-requests: write|issues: write|anthropic|api key|token" .github/workflows/claude.ymlRepository: BigSimmo/Database
Length of output: 4863
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Search for any collaborator/association checks or docs around the Claude workflow.
rg -n "claude-code-action|repository association|COLLABORATOR|MEMBER|OWNER|trusted collaborator|`@claude`|ANTHROPIC_API_KEY|claude_code_oauth_token" . -g '!**/node_modules/**' -g '!**/dist/**' -g '!**/build/**'
# Show any workflow/docs files that mention Claude integration.
git ls-files | rg '(^|/)(README|docs?|\.github/workflows/.*claude.*|.*claude.*)\.(md|yml|yaml)$'Repository: BigSimmo/Database
Length of output: 28335
Require collaborator-only gating before invoking Claude .github/workflows/claude.yml:27-38
The job still accepts any non-bot @claude mention and then runs with write permissions plus ANTHROPIC_API_KEY. Restrict each trigger to trusted repository associations like OWNER, MEMBER, or COLLABORATOR before allowing it to run.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/claude.yml around lines 27 - 38, The Claude workflow
trigger condition currently allows any non-bot user to invoke the job. Update
the issue_comment, pull_request_review_comment, and pull_request_review branches
in the workflow if expression to require the corresponding user’s association to
be OWNER, MEMBER, or COLLABORATOR, while preserving the existing `@claude` and
event-specific checks.
| - name: Checkout repository | ||
| if: ${{ env.ANTHROPIC_API_KEY != '' }} | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| fetch-depth: 1 | ||
| - name: Run Claude Code | ||
| if: ${{ env.ANTHROPIC_API_KEY != '' }} | ||
| uses: anthropics/claude-code-action@af0559ee4f514d1ef21826982bed13f7edc3c35e # v1.0.178 |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
file=".github/workflows/claude.yml"
echo "=== file listing ==="
git ls-files "$file"
echo
echo "=== line count ==="
wc -l "$file"
echo
echo "=== relevant excerpt ==="
sed -n '1,220p' "$file"Repository: BigSimmo/Database
Length of output: 3354
🌐 Web query:
actions/checkout default ref issue_comment github.event.ref default branch documentation claude-code-action current PR head checkout
💡 Result:
The actions/checkout action has specific default behaviors regarding what it checks out depending on the triggering event, and navigating these defaults—particularly for issue_comment events or pull request contexts—often requires explicit configuration [1][2][3]. Default Behavior By default, actions/checkout checks out the reference or SHA that triggered the workflow [1][3]. For events that do not have a specific reference (or when the context is ambiguous), it falls back to the default branch [1][2][3]. Notably, for pull_request events, the default is to checkout the merge commit (refs/pull/PULL_REQUEST_NUMBER/merge), not the individual head branch of the pull request [4][5]. Issue Comment and Pull Request Contexts When a workflow is triggered by an issue_comment event, GitHub does not automatically checkout the pull request branch [6][2]. To checkout the source branch of a pull request from an issue_comment event, you must dynamically determine the PR head reference and pass it to the ref input [6]: 1. Use actions/github-script to retrieve the pull request head ref [6]. 2. Pass that reference to actions/checkout [6]. Example pattern to checkout the PR branch or fallback to default: - uses: actions/github-script@v7 id: pr if: ${{ github.event.issue.pull_request }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | const { data: pr } = await github.rest.pulls.get({ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.issue.number }); core.setOutput('head_ref', pr.head.ref); - uses: actions/checkout@v4 with: ref: ${{ github.event.issue.pull_request && steps.pr.outputs.head_ref || github.ref }} Claude Code Action Configuration For users of anthropics/claude-code-action, the action expects a repository checkout to exist before it runs [7][8]. Standard practice is to run actions/checkout@v4 before the Claude step [7][8]. If you encounter failures related to branch setup (e.g., when using persist-credentials: false), it is often because the action attempts to fetch origin before configuring its own authentication; in such cases, ensure proper credential persistence or follow the maintainer-recommended workarounds for your specific environment [9].
Citations:
- 1: https://github.com/actions/checkout
- 2: checkout not checking out branch actions/checkout#1637
- 3: https://github.com/marketplace/actions/checkout
- 4: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows
- 5: What does "Checkout pull request HEAD commit instead of merge commit" mean? actions/checkout#426
- 6: Any way to checkout PR from
issue_commentevent? actions/checkout#331 - 7: https://code.claude.com/docs/en/github-actions
- 8: https://code.claude.com/docs/en/github-actions.md
- 9: claude-code-action fails when actions/checkout uses persist-credentials: false anthropics/claude-code-action#1236
🌐 Web query:
anthropics claude-code-action README current PR head checkout issue_comment actions/checkout default ref
💡 Result:
In GitHub Actions workflows using anthropics/claude-code-action, the interaction between actions/checkout and the action itself is a critical security and functional consideration [1][2]. For workflows triggered by events like issue_comment or pull_request_target, it is recommended to check out the base repository's code at the workspace root by default [1][2]. Because claude-code-action performs actor permission checks and restores project configuration from the base ref, checking out an untrusted head ref (such as github.event.pull_request.head.sha) directly into the workspace root can pose security risks when running with the base repository's secrets [1][2]. To work safely with Pull Request files: 1. Preferred approach: Check out the base ref (the default) at the workspace root [1][2]. yaml - uses: actions/checkout@v6 # No ref specified → defaults to base branch - uses: anthropics/claude-code-action@v1 2. Accessing PR files: If the action needs access to the PR's specific files, check out the base branch at the root, then check out the head ref into a separate subdirectory and provide it to the action via the --add-dir argument [1][2]. yaml - uses: actions/checkout@v6 # Base branch at workspace root - uses: actions/checkout@v6 with: ref: ${{ github.event.pull_request.head.sha }} path: pr-head - uses: anthropics/claude-code-action@v1 with: claude_args: "--add-dir pr-head" Regarding branch selection, the claude-code-action maintains logic to determine the active branch [3]. While it previously defaulted to "main," recent updates ensure it falls back to the repository's default_branch if available [3]. Users can also explicitly specify a branch for operations using the base_branch input parameter if necessary [4].
Citations:
- 1: https://github.com/anthropics/claude-code-action/blob/main/docs/security.md
- 2: anthropics/claude-code-action@c93e8fe
- 3: anthropics/claude-code-action@c281e17
- 4: Ability to Determine the branch that Claude checks out from anthropics/claude-code-action#62
Check out the PR head before running Claude on issue_comment.
actions/checkout will otherwise use the event ref here, which is the base branch for issue comments, so Claude works from the wrong code. Resolve github.event.issue.pull_request and pass the PR’s repository plus head.ref/head.sha into checkout first.
🧰 Tools
🪛 zizmor (1.26.1)
[warning] 57-61: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/claude.yml around lines 57 - 64, Update the Checkout
repository step before Run Claude Code to resolve
github.event.issue.pull_request and configure actions/checkout with the pull
request’s repository, head.ref, and head.sha, ensuring Claude runs against the
PR head rather than the issue-comment event ref.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/claude.yml:
- Around line 62-68: Update the “Run Claude Code” workflow step and its action
configuration to use the flow that applies fixes directly to the triggering pull
request branch instead of creating a new claude/ branch and returning a separate
PR link. Preserve the existing API-key condition and secret wiring.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 03f7c63d-4735-48b6-9bd3-8d51379e526a
📒 Files selected for processing (2)
.github/workflows/claude.ymlscripts/github-action-pins.mjs
| - name: Run Claude Code | ||
| if: ${{ env.ANTHROPIC_API_KEY != '' }} | ||
| uses: anthropics/claude-code-action@af0559ee4f514d1ef21826982bed13f7edc3c35e # v1.0.178 | ||
| with: | ||
| # The action's default trigger phrase is "@claude"; it reads the | ||
| # triggering comment/review and acts on the current PR head. | ||
| anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== workflow file ==\n'
cat -n .github/workflows/claude.yml | sed -n '1,180p'
printf '\n== references to claude-code-action ==\n'
rg -n "claude-code-action|ANTHROPIC_API_KEY|`@claude`|claude/" .github/workflows . -g '*.yml' -g '*.yaml' -g '*.md' -g '*.txt' || trueRepository: BigSimmo/Database
Length of output: 50374
🏁 Script executed:
#!/bin/bash
set -euo pipefail
cat -n .github/workflows/claude.yml | sed -n '1,180p'Repository: BigSimmo/Database
Length of output: 3702
🌐 Web query:
anthropics/claude-code-action docs security default @claude creates branch PR-creation link direct update flow
💡 Result:
Claude Code and its associated GitHub Action provide automated workflows for branch management and pull request (PR) creation, supported by specific security configurations [1][2]. Security and Default Behaviors: For the Claude Code Action on GitHub, bot user control is enabled by default for security, meaning bots cannot trigger the action unless explicitly configured via the allowed_bots parameter [3][4]. Caution is advised when using wildcards ('*') for allowed bots, as this can allow external, uninstalled apps to trigger workflows on public repositories [3][4]. Claude Code itself enforces strict read-only permissions by default, requiring explicit user approval for any operations that modify files, execute shell commands, or perform network requests [5][6]. Branch and PR Creation Flow: Claude Code automates the Git lifecycle through natural language instructions [2][7]. Users can request branch creation and PR generation directly within the conversational interface [8][2]. 1. Branch Creation: When asked to create a branch, Claude Code typically handles the naming based on project conventions (e.g., CLAUDE.md) or defaults to patterns like feature/ or fix/ [9][7]. It executes the necessary git checkout commands automatically [2]. 2. PR Creation: Claude uses the GitHub CLI (gh) tool under the hood to manage pull requests [2][7]. A single command like "create a PR" triggers a process where Claude analyzes commits, generates a title and summary, and creates the PR via gh pr create [2][7]. 3. Session Linking: When a PR is created through this flow, the active conversational session is automatically linked to that PR [8][9]. This allows users to resume the session later using the PR number or URL to continue working on feedback or CI results [8][10]. For direct update flows, Claude Code performs background checks for updates on startup, with native installations updating automatically by default [11][12]. Users can configure release channels or disable these updates depending on their installation method (e.g., Homebrew/WinGet vs. native) [11][12].
Citations:
- 1: https://code.claude.com/docs/en/github-actions
- 2: https://institute.sfeir.com/en/claude-code/claude-code-git-integration/tutorial/
- 3: https://github.com/anthropics/claude-code-action/blob/main/docs/security.md
- 4: https://github.com/anthropics/claude-code-action/blob/refs/heads/main/docs/security.md
- 5: https://code.claude.com/docs/en/security
- 6: https://code.claude.com/docs/en/permissions
- 7: https://institute.sfeir.com/en/claude-code/claude-code-git-integration/
- 8: https://code.claude.com/docs/en/common-workflows
- 9: https://developertoolkit.ai/en/claude-code/quick-start/version-control/
- 10: https://code.claude.com/docs/en/web-quickstart
- 11: https://code.claude.com/docs/en/install
- 12: https://code.claude.com/docs/en/
🌐 Web query:
site:github.com/anthropics/claude-code-action/docs/security.md "@claude" branch PR current PR head anthropic_api_key claude_code_oauth_token
💡 Result:
Key points from security.md:
- If you use
pull_request_targetorworkflow_run, don’t check out the PR head into the workspace root beforeclaude-code-action; if you do, Claude runs on that untrusted checkout. Use the base branch at the root, or check out the PR head into a subdirectory and pass it via--add-dir. The doc specifically referencesgithub.event.pull_request.head.shaandgithub.event.workflow_run.head_sha. [1] - Never hardcode
anthropic_api_keyorclaude_code_oauth_tokenin workflow files; store them in GitHub Secrets instead. [1] - In the default
@claudeflow, Claude does not auto-create PRs; it commits to a new branch and gives you a PR link to open manually. [1]
If you want, I can extract the exact YAML-safe pattern from that doc.
Update .github/workflows/claude.yml:62-68 to match the actual flow. The default @claude path creates a new claude/ branch and returns a PR link, so this does not push fixes to the triggering PR branch.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In @.github/workflows/claude.yml around lines 62 - 68, Update the “Run Claude
Code” workflow step and its action configuration to use the flow that applies
fixes directly to the triggering pull request branch instead of creating a new
claude/ branch and returning a separate PR link. Preserve the existing API-key
condition and secret wiring.
Summary
.github/workflows/claude.yml: a workflow that runs a Claude Code session (via the officialanthropics/claude-code-action) whenever a collaborator mentions@claudeon a PR comment or review. Claude reads the triggering comment, works on the PR's current head, pushes a scoped fix to the PR branch, and replies in the thread.ANTHROPIC_API_KEYis unset.anthropics/claude-code-actioninscripts/github-action-pins.mjs, pinned to the reviewed v1.0.178 commit SHA (af0559e), so the Actions pin check passes.runs-onisubuntu-24.04per the repo's pin policy.Action required before this works: add an
ANTHROPIC_API_KEYrepository secret (Settings → Secrets and variables → Actions). To use a Claude subscription instead of pay-per-use API billing, generate a token withclaude setup-token, store it asCLAUDE_CODE_OAUTH_TOKEN, and swap the action inputanthropic_api_key→claude_code_oauth_token.Verification
npm run verify:pr-localnode scripts/check-github-action-pins.mjs(pass),node scripts/check-codex-autofix-workflow.mjs(pass, unaffected),node scripts/check-pr-policy-workflow.mjs(pass), Prettier--check(pass), and a YAML parse of the new workflow (valid; jobs=[claude], triggers=[issue_comment, pull_request_review_comment, pull_request_review]).npm run verify:pr-local— this is a CI-config-only change (one workflow file + a pin-allowlist entry) with no application source, RAG, or build surface; the relevant Actions-pin and PR-policy gates were run directly instead.npm run verify:ui— not applicable (no UI, routing, styling, or browser behavior changed).Risk and rollout
.github/workflows/claude.ymland revert thegithub-action-pins.mjsentry, or remove theANTHROPIC_API_KEYsecret to disable without a code change.@claudeis used — this is the explicitly requested behavior and is billed to whichever key/token is configured. No effect until the secret is set.Clinical Governance Preflight
Not applicable — this change is CI configuration only and does not touch ingestion, answer generation, search/ranking, source rendering, document access, privacy, production env, or clinical output.
Notes
@claude; it acts only for users with write access to the repo (built-in permission check).@claudeon plain issues, add anissuestrigger and branch — happy to follow up if wanted.Generated by Claude Code
Summary by CodeRabbit
New Features
Chores