Skip to content

Add Claude Code GitHub Workflow#2

Open
angelxmoreno wants to merge 2 commits intomainfrom
add-claude-github-actions-1755877417565
Open

Add Claude Code GitHub Workflow#2
angelxmoreno wants to merge 2 commits intomainfrom
add-claude-github-actions-1755877417565

Conversation

@angelxmoreno
Copy link
Copy Markdown
Owner

@angelxmoreno angelxmoreno commented Aug 22, 2025

🤖 Installing Claude Code GitHub App

This PR adds a GitHub Actions workflow that enables Claude Code integration in our repository.

What is Claude Code?

Claude Code is an AI coding agent that can help with:

  • Bug fixes and improvements
  • Documentation updates
  • Implementing new features
  • Code reviews and suggestions
  • Writing tests
  • And more!

How it works

Once this PR is merged, we'll be able to interact with Claude by mentioning @claude in a pull request or issue comment.
Once the workflow is triggered, Claude will analyze the comment and surrounding context, and execute on the request in a GitHub action.

Important Notes

  • This workflow won't take effect until this PR is merged
  • @claude mentions won't work until after the merge is complete
  • The workflow runs automatically whenever Claude is mentioned in PR or issue comments
  • Claude gets access to the entire PR or issue context including files, diffs, and previous comments

Security

  • Our Anthropic API key is securely stored as a GitHub Actions secret
  • Only users with write access to the repository can trigger the workflow
  • All Claude runs are stored in the GitHub Actions run history
  • Claude's default tools are limited to reading/writing files and interacting with our repo by creating comments, branches, and commits.
  • We can add more allowed tools by adding them to the workflow file like:
allowed_tools: Bash(npm install),Bash(npm run build),Bash(npm run lint),Bash(npm run test)

There's more information in the Claude Code action repo.

After merging this PR, let's try mentioning @claude in a comment on any PR to get started!

Summary by CodeRabbit

  • Chores
    • Introduced automated AI code reviews on pull requests to flag potential bugs, security concerns, performance issues, and test gaps early.
    • Enabled on-demand AI assistance by mentioning @claude in issues, comments, or reviews to get context-aware analysis and suggestions.
    • Improves review efficiency and consistency with actionable, constructive feedback integrated into the development workflow.
    • Supports future customization of triggers and behavior to fit team processes without impacting the main application functionality.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Aug 22, 2025

Walkthrough

Adds two new GitHub Actions workflows to run a Claude-based code assistant: one auto-invoked on pull request open/sync for code review, and another triggered by @claude mentions across issues, comments, and reviews. Both check out the repo and execute anthropics/claude-code-action@beta with configurable, mostly commented, options.

Changes

Cohort / File(s) Summary
Automated PR code review workflow
.github/workflows/claude-code-review.yml
New workflow triggered on pull_request opened/synchronize. Defines claude-review job on ubuntu-latest, sets read permissions plus id-token: write, checks out repo with fetch-depth: 1, runs anthropics/claude-code-action@beta using secrets.CLAUDE_CODE_OAUTH_TOKEN and a mandatory direct_prompt. Includes commented options (model, sticky comments, per-file/author prompts, tool access, skip conditions).
Mention-triggered assistant workflow
.github/workflows/claude.yml
New workflow named "Claude Code" triggered on issue_comment, pull_request_review_comment, issues, pull_request_review when content mentions @claude. Runs claude job on ubuntu-latest with read permissions and id-token: write, checks out repo, executes anthropics/claude-code-action@beta with additional_permissions: actions: read. Provides commented configuration for model, trigger phrases, assignee gating, allowed tools, custom instructions, and environment variables.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Dev as Developer
  participant GH as GitHub
  participant WF as Workflow: claude-code-review.yml
  participant Act as Claude Code Action
  participant PR as Pull Request

  Dev->>GH: Open/Synchronize PR
  GH-->>WF: Trigger on pull_request (opened/synchronize)
  WF->>WF: Checkout repo (fetch-depth: 1)
  WF->>Act: Run anthropics/claude-code-action@beta<br/>with CLAUDE_CODE_OAUTH_TOKEN + direct_prompt
  Act-->>PR: Post code review comments/status (as configured)
  note over WF,Act: Optional configs (model, sticky comments, skip logic) are available but commented out
Loading
sequenceDiagram
  autonumber
  participant User as User
  participant GH as GitHub
  participant WF as Workflow: claude.yml
  participant Act as Claude Code Action
  participant Thread as Issue/PR/Review Thread

  User->>GH: Create/Update Issue/Comment/Review mentioning @claude
  GH-->>WF: Conditional trigger (content contains @claude)
  WF->>WF: Checkout repo (fetch-depth: 1)
  WF->>Act: Run anthropics/claude-code-action@beta<br/>with CLAUDE_CODE_OAUTH_TOKEN<br/>+ actions:read permission
  Act-->>Thread: Reply with results/analysis
  note over WF,Act: Optional inputs (model, trigger_phrase, allowed_tools, env) are commented for future use
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I twitch my ears at every PR’s cue,
Hop into workflows, review what’s new—
On mention, I bound with a swift “hello,”
On sync, I nibble through lines in a row.
Carrots of comments, crisp and bright—
CI meadows, green with insight.
Thump! Another merge in sight.

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-claude-github-actions-1755877417565

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (13)
.github/workflows/claude-code-review.yml (7)

3-12: Consider widening triggers (reopened, ready_for_review) and adding manual dispatch.

Captures more real-world PR states and gives maintainers a manual knob.

 on:
   pull_request:
-    types: [opened, synchronize]
+    types: [opened, synchronize, reopened, ready_for_review]
+  workflow_dispatch:

21-27: Tighten permissions; id-token: write likely unnecessary here.

Unless the action explicitly needs OIDC, drop it. Also, issues: read may not be needed for a plain PR review.

 jobs:
   claude-review:
     runs-on: ubuntu-latest
     permissions:
       contents: read
       pull-requests: read
-      issues: read
-      id-token: write
+      # issues: read        # Uncomment only if the action reads issues explicitly
+      # id-token: write     # Uncomment only if OIDC is required by the action

If the action requires either permission, please point to that requirement and keep it. Otherwise, removing them follows least-privilege.


28-33: Harden checkout step (avoid leaking default GITHUB_TOKEN to later steps).

Setting persist-credentials: false prevents accidental reuse of the token by tools the action may invoke.

       - name: Checkout repository
         uses: actions/checkout@v4
         with:
           fetch-depth: 1
+          persist-credentials: false

43-53: Prompt is clear; consider asking for severity labels and actionable diffs.

This improves signal-to-noise in automated reviews.

           direct_prompt: |
             Please review this pull request and provide feedback on:
             - Code quality and best practices
             - Potential bugs or issues
             - Performance considerations
             - Security concerns
             - Test coverage
             
-            Be constructive and helpful in your feedback.
+            Be constructive and helpful. Group findings by severity (Critical/Major/Minor/Nit).
+            Where feasible, include minimal diff suggestions and quick reproduction steps.

54-78: Enable sticky comments and add skip/draft guards to reduce churn.

Sticky comments prevent duplication; skipping drafts and opt-out titles avoids wasted cycles.

-          # use_sticky_comment: true
+          use_sticky_comment: true
@@
-          # if: |
-          #   !contains(github.event.pull_request.title, '[skip-review]') &&
-          #   !contains(github.event.pull_request.title, '[WIP]')
+          # Only run on non-draft PRs and when not opted out
+          if: |
+            !github.event.pull_request.draft &&
+            !contains(github.event.pull_request.title, '[skip-review]') &&
+            !contains(github.event.pull_request.title, '[WIP]')

13-27: Add job-level concurrency to auto-cancel outdated review runs.

Saves compute on rapid pushes.

 jobs:
   claude-review:
+    concurrency:
+      group: claude-review-${{ github.event.pull_request.number }}
+      cancel-in-progress: true

1-79: Fix YAML lint nits (trailing spaces and final blank line).

Yamllint flagged trailing spaces on Lines 20, 27, 51, 56, 64, 67, 70, 73 and an extra blank line at the end. Trim whitespace and remove the final blank line to keep CI and editors happy.

.github/workflows/claude.yml (6)

3-12: Expand event types to catch edits where @claude is added later.

Covers mention edits on issues and comments.

 on:
   issue_comment:
-    types: [created]
+    types: [created, edited]
   pull_request_review_comment:
-    types: [created]
+    types: [created, edited]
   issues:
-    types: [opened, assigned]
+    types: [opened, assigned, edited]
   pull_request_review:
-    types: [submitted]
+    types: [submitted, edited]

21-27: Review permission scope; id-token: write may not be needed.

Unless the action uses OIDC, remove id-token: write. Keeping actions: read is fine for CI visibility.

     permissions:
       contents: read
       pull-requests: read
       issues: read
-      id-token: write
+      # id-token: write   # Uncomment only if required by the action
       actions: read # Required for Claude to read CI results on PRs

28-33: Harden checkout step by disabling credential persistence.

       - name: Checkout repository
         uses: actions/checkout@v4
         with:
           fetch-depth: 1
+          persist-credentials: false

52-54: Be conservative with allowed_tools when you enable it.

If/when you uncomment this, prefer a tight allowlist and short job timeouts to limit blast radius.

         # allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
+        # timeout-minutes: 15

13-20: Add job-level concurrency to avoid duplicate runs on the same item.

 jobs:
   claude:
+    concurrency:
+      group: claude-${{ github.event_name }}-${{ github.event.issue.number || github.event.pull_request.number || github.run_id }}
+      cancel-in-progress: true

1-65: Fix YAML lint nits (trailing spaces and final blank line).

Trim trailing spaces on Lines 42, 45, 48, 51, 54, 60 and remove the trailing blank line at the end to appease yamllint and avoid noisy diffs.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between d5208c9 and 221c4a8.

📒 Files selected for processing (2)
  • .github/workflows/claude-code-review.yml (1 hunks)
  • .github/workflows/claude.yml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/claude.yml

[error] 42-42: trailing spaces

(trailing-spaces)


[error] 45-45: trailing spaces

(trailing-spaces)


[error] 48-48: trailing spaces

(trailing-spaces)


[error] 51-51: trailing spaces

(trailing-spaces)


[error] 54-54: trailing spaces

(trailing-spaces)


[error] 60-60: trailing spaces

(trailing-spaces)


[warning] 64-64: too many blank lines (1 > 0)

(empty-lines)

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

[error] 20-20: trailing spaces

(trailing-spaces)


[error] 27-27: trailing spaces

(trailing-spaces)


[error] 51-51: trailing spaces

(trailing-spaces)


[error] 56-56: trailing spaces

(trailing-spaces)


[error] 64-64: trailing spaces

(trailing-spaces)


[error] 67-67: trailing spaces

(trailing-spaces)


[error] 70-70: trailing spaces

(trailing-spaces)


[error] 73-73: trailing spaces

(trailing-spaces)


[warning] 78-78: too many blank lines (1 > 0)

(empty-lines)

🔇 Additional comments (1)
.github/workflows/claude.yml (1)

39-42: LGTM on additional_permissions.

Appropriately grants read-only access to Actions so Claude can surface CI results.

Comment on lines +34 to +39
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@beta
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin the action to a commit SHA instead of @beta.

Prevents supply-chain surprises if the beta tag moves.

-        uses: anthropics/claude-code-action@beta
+        # Pin to a verified commit SHA to avoid tag drift
+        uses: anthropics/claude-code-action@<COMMIT-SHA>

Replace <COMMIT-SHA> with the published commit you trust.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run Claude Code Review
id: claude-review
uses: anthropics/claude-code-action@beta
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
- name: Run Claude Code Review
id: claude-review
# Pin to a verified commit SHA to avoid tag drift
uses: anthropics/claude-code-action@<COMMIT-SHA>
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
🤖 Prompt for AI Agents
In .github/workflows/claude-code-review.yml around lines 34 to 39, the workflow
uses the action anthropics/claude-code-action@beta which should be pinned to a
specific commit SHA; update the uses line to reference the trusted commit SHA
(replace @beta with @<COMMIT-SHA>) so the workflow uses an immutable, reviewed
version of the action and avoid tag drifting.

Comment on lines +15 to +20
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')))
runs-on: ubuntu-latest
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

⚠️ Potential issue

Gate on author association to ensure only trusted users can trigger runs.

Prevents external users from triggering a workflow that has access to repo context and secrets.

   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')))
+    if: |
+      (
+        github.event_name == 'issue_comment' &&
+        github.event.comment.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
+        contains(github.event.comment.body, '@claude')
+      ) || (
+        github.event_name == 'pull_request_review_comment' &&
+        github.event.comment.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
+        contains(github.event.comment.body, '@claude')
+      ) || (
+        github.event_name == 'pull_request_review' &&
+        github.event.review.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
+        github.event.review.body != null &&
+        contains(github.event.review.body, '@claude')
+      ) || (
+        github.event_name == 'issues' &&
+        github.event.issue.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
+        (
+          (github.event.issue.body != null && contains(github.event.issue.body, '@claude')) ||
+          contains(github.event.issue.title, '@claude')
+        )
+      )

Note: GitHub expressions don’t have a native array membership operator; the above pattern uses multiple equality checks via in [...] for readability—if your linter flags it, expand it to == 'MEMBER' || == 'OWNER' || == 'COLLABORATOR'.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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')))
runs-on: ubuntu-latest
if: |
(
github.event_name == 'issue_comment' &&
github.event.comment.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
contains(github.event.comment.body, '@claude')
) || (
github.event_name == 'pull_request_review_comment' &&
github.event.comment.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
contains(github.event.comment.body, '@claude')
) || (
github.event_name == 'pull_request_review' &&
github.event.review.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
github.event.review.body != null &&
contains(github.event.review.body, '@claude')
) || (
github.event_name == 'issues' &&
github.event.issue.author_association in ['MEMBER','OWNER','COLLABORATOR'] &&
(
(github.event.issue.body != null && contains(github.event.issue.body, '@claude')) ||
contains(github.event.issue.title, '@claude')
)
)
runs-on: ubuntu-latest
🤖 Prompt for AI Agents
.github/workflows/claude.yml around lines 15 to 20: the workflow currently
triggers whenever a comment or issue contains '@claude' but does not restrict
who authored the triggering event; add author association checks so only trusted
users (e.g., OWNER, MEMBER, COLLABORATOR, CONTRIBUTOR) can trigger the job.
Update the if expression for each event branch to also require the appropriate
author association field (github.event.comment.author_association,
github.event.review.author_association, github.event.issue.author_association)
to be one of the allowed values, using explicit equality comparisons joined with
|| (or expand into the linter-friendly form) so untrusted external users cannot
trigger runs with repo context and secrets.

Comment on lines +33 to +38
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@beta
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Pin the action to a commit SHA instead of @beta.

Avoids unexpected behavior if beta updates.

-        uses: anthropics/claude-code-action@beta
+        uses: anthropics/claude-code-action@<COMMIT-SHA>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@beta
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@<COMMIT-SHA>
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
🤖 Prompt for AI Agents
.github/workflows/claude.yml lines 33-38: the workflow currently uses
anthropics/claude-code-action@beta which can change unexpectedly; replace the
floating tag with a specific commit SHA (pin to a fixed revision). Find the
action's repository, pick a stable commit SHA (from the tag or recent release)
and update the uses value to anthropics/claude-code-action@<COMMIT_SHA>; commit
the change and optionally add a comment noting the pinned SHA and why.

@coderabbitai coderabbitai bot mentioned this pull request Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant