Skip to content

Add Claude Code GitHub Workflow - #90

Merged
maxim-uvarov merged 2 commits into
mainfrom
add-claude-github-actions-1765656899770
Dec 13, 2025
Merged

maxim-uvarov merged 2 commits into
mainfrom
add-claude-github-actions-1765656899770

Conversation

@maxim-uvarov

Copy link
Copy Markdown
Member

🤖 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!

@maxim-uvarov
maxim-uvarov merged commit 797fbdd into main Dec 13, 2025
1 check passed
@maxim-uvarov
maxim-uvarov deleted the add-claude-github-actions-1765656899770 branch December 13, 2025 20:15
@claude

claude Bot commented Dec 13, 2025

Copy link
Copy Markdown

Code Review: Claude Code GitHub Workflow

I've reviewed PR #90 which adds Claude Code integration to the repository. Here's my detailed feedback:

✅ Positive Aspects

  1. Good Security Practices

    • Uses GitHub secrets for API tokens (CLAUDE_CODE_OAUTH_TOKEN)
    • Implements minimal required permissions (read-only for most resources)
    • Restricts Claude's bash tools to specific gh commands via allowed-tools in the code review workflow
  2. Well-Structured Workflows

    • Two separate workflows for different use cases:
      • claude.yml: Interactive @claude mentions in comments
      • claude-code-review.yml: Automatic PR reviews
    • Clear conditional logic to trigger only when Claude is mentioned
    • Proper use of GitHub Actions best practices (checkout@v4, explicit fetch-depth)
  3. Good Documentation

    • Clear comments explaining optional configurations
    • Links to documentation for customization
    • Helpful PR description explaining how the feature works

⚠️ Issues and Recommendations

1. Missing write Permissions for Code Review Workflow

CRITICAL: The claude-code-review.yml workflow instructs Claude to post comments via gh pr comment, but only grants pull-requests: read permission. This will cause the workflow to fail when attempting to post the review.

Fix needed in .github/workflows/claude-code-review.yml:22-26:

permissions:
  contents: read
  pull-requests: write  # Changed from 'read' to 'write'
  issues: read
  id-token: write

2. Limited Tool Access for Nushell Project

The claude-code-review.yml workflow restricts Claude to only gh commands, which prevents it from:

  • Running project tests (nu toolkit.nu testing)
  • Executing Nushell scripts to verify code works
  • Running numd commands to test markdown processing

Recommendations:

  • Add Nushell-specific tools to allowed-tools:
    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:*),Bash(nu toolkit.nu testing:*),Bash(nu toolkit.nu testing-unit:*),Bash(nu toolkit.nu testing-integration:*)"'
  • Or consider allowing broader access with appropriate safeguards:
    # Allow test execution but prevent destructive operations
    claude_args: '--allowed-tools "Bash(gh:*),Bash(nu toolkit.nu:*)"'

3. Missing Write Permissions in Interactive Workflow

The claude.yml workflow (line 21-26) also only has read permissions, which will prevent Claude from:

  • Creating commits when fixing bugs
  • Creating new branches
  • Pushing changes
  • Commenting back to confirm completion

Recommended permissions for .github/workflows/claude.yml:21-26:

permissions:
  contents: write        # Allow creating commits/branches
  pull-requests: write   # Allow commenting and creating PRs
  issues: write          # Allow commenting on issues
  id-token: write
  actions: read

4. Code Review Workflow Triggers on Every PR

Currently triggers on ALL PRs (types: [opened, synchronize]). This could:

  • Consume API credits rapidly in active repos
  • Create noise on internal/WIP PRs
  • Review PRs from maintainers who don't need automatic reviews

Consider:

  • Uncommenting the author filter (lines 16-19) to target specific users
  • Adding path filters (lines 6-11) to only review code changes
  • Adding a workflow_dispatch trigger for manual reviews

5. Missing Nushell Installation

The workflows checkout the repository but don't install Nushell, which means Claude cannot execute any nu commands even if granted permission.

Add before the Claude step:

- name: Setup Nushell
  uses: hustcer/setup-nu@v3
  with:
    version: '0.99.0'  # or 'latest'

📋 Suggestions for Future Enhancements

  1. Add Resource Limits: Set timeout-minutes to prevent runaway workflows
  2. Environment Variables: Consider exposing repo-specific config via environment variables
  3. Testing: Add a test PR to verify the workflows work correctly before deploying to production
  4. Rate Limiting: Document expected API usage and cost implications

🔒 Security Considerations

✅ Good:

  • Secrets properly stored
  • Minimal permissions by default
  • Tool access restrictions in place

⚠️ Consider:

  • The interactive workflow (claude.yml) allows ANY user to trigger Claude by mentioning it in comments. Ensure your repo settings restrict who can comment on PRs (e.g., require approval for first-time contributors)
  • Document who has access to the CLAUDE_CODE_OAUTH_TOKEN secret

Summary

The implementation is well-structured and follows GitHub Actions best practices. However, the workflows will not function as intended without write permissions. Priority fixes:

  1. ✅ Add pull-requests: write to claude-code-review.yml
  2. ✅ Add contents: write, pull-requests: write, issues: write to claude.yml
  3. ✅ Install Nushell in both workflows
  4. 🔄 Consider expanding allowed tools for Nushell testing

Would you like me to create a follow-up PR with these fixes?

@maxim-uvarov

Copy link
Copy Markdown
Member Author

@claude can you address the issues that you found in previous comment?

Summary

The implementation is well-structured and follows GitHub Actions best practices. However, the workflows will not function as intended without write permissions. Priority fixes:

✅ Add pull-requests: write to claude-code-review.yml
✅ Add contents: write, pull-requests: write, issues: write to claude.yml
✅ Install Nushell in both workflows
🔄 Consider expanding allowed tools for Nushell testing
Would you like me to create a follow-up PR with these fixes?

@claude

claude Bot commented Dec 13, 2025 •

Copy link
Copy Markdown

Claude finished @maxim-uvarov's task in 2m 29s —— View job


Addressing GitHub Workflow Issues

I've analyzed the workflow files and prepared all the necessary fixes. However, I cannot push them directly due to GitHub App permission restrictions - workflow files require special workflows permission to modify.

Summary of Changes Made

I've successfully implemented all 5 priority fixes locally:

  • ✅ Added write permissions to claude.yml - Now allows creating commits, branches, and commenting
  • ✅ Added write permissions to claude-code-review.yml - Now allows posting review comments
  • ✅ Installed Nushell in claude.yml - Using hustcer/setup-nu@v3 with latest version
  • ✅ Installed Nushell in claude-code-review.yml - Using hustcer/setup-nu@v3 with latest version
  • ✅ Expanded allowed tools - Added Nushell testing commands (nu toolkit.nu testing, etc.)

How to Apply These Changes

Since I cannot push workflow file changes, here are your options:

Option 1: Manual Edits (Recommended)

Apply these 5 changes to the workflow files in your main branch:

1. Update permissions in .github/workflows/claude.yml (lines 21-26)

Replace:

    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write
      actions: read # Required for Claude to read CI results on PRs

With:

    permissions:
      contents: write        # Allow creating commits/branches
      pull-requests: write   # Allow commenting and creating PRs
      issues: write          # Allow commenting on issues
      id-token: write
      actions: read          # Required for Claude to read CI results on PRs
2. Update permissions in .github/workflows/claude-code-review.yml (lines 22-26)

Replace:

    permissions:
      contents: read
      pull-requests: read
      issues: read
      id-token: write

With:

    permissions:
      contents: read
      pull-requests: write  # Required to post review comments
      issues: read
      id-token: write
3. Add Nushell setup to .github/workflows/claude.yml (after line 31)

Add this step after the checkout step:

      - name: Setup Nushell
        uses: hustcer/setup-nu@v3
        with:
          version: 'latest'
4. Add Nushell setup to .github/workflows/claude-code-review.yml (after line 32)

Add this step after the checkout step:

      - name: Setup Nushell
        uses: hustcer/setup-nu@v3
        with:
          version: 'latest'
5. Expand allowed tools in .github/workflows/claude-code-review.yml (line 56)

Replace:

          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:*)"'

With:

          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:*),Bash(nu toolkit.nu testing:*),Bash(nu toolkit.nu testing-unit:*),Bash(nu toolkit.nu testing-integration:*),Bash(use numd;*)"'

Option 2: Complete Fixed Files

View complete claude.yml
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')))
    runs-on: ubuntu-latest
    permissions:
      contents: write        # Allow creating commits/branches
      pull-requests: write   # Allow commenting and creating PRs
      issues: write          # Allow commenting on issues
      id-token: write
      actions: read          # Required for Claude to read CI results on PRs
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Setup Nushell
        uses: hustcer/setup-nu@v3
        with:
          version: 'latest'

      - name: Run Claude Code
        id: claude
        uses: anthropics/claude-code-action@v1
        with:
          claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}

          # This is an optional setting that allows Claude to read CI results on PRs
          additional_permissions: |
            actions: read

          # Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
          # prompt: 'Update the pull request description to include a summary of changes.'

          # Optional: Add claude_args to customize behavior and configuration
          # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
          # or https://code.claude.com/docs/en/cli-reference for available options
          # claude_args: '--allowed-tools Bash(gh pr:*)'
View complete claude-code-review.yml
name: Claude Code Review

on:
  pull_request:
    types: [opened, synchronize]
    # Optional: Only run on specific file changes
    # paths:
    #   - "src/**/*.ts"
    #   - "src/**/*.tsx"
    #   - "src/**/*.js"
    #   - "src/**/*.jsx"

jobs:
  claude-review:
    # Optional: Filter by PR author
    # if: |
    #   github.event.pull_request.user.login == 'external-contributor' ||
    #   github.event.pull_request.user.login == 'new-developer' ||
    #   github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'

    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write  # Required to post review comments
      issues: read
      id-token: write

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 1

      - name: Setup Nushell
        uses: hustcer/setup-nu@v3
        with:
          version: 'latest'

      - name: Run Claude Code Review
        id: claude-review
        uses: anthropics/claude-code-action@v1
        with:
          claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
          prompt: |
            REPO: ${{ github.repository }}
            PR NUMBER: ${{ github.event.pull_request.number }}

            Please review this pull request and provide feedback on:
            - Code quality and best practices
            - Potential bugs or issues
            - Performance considerations
            - Security concerns
            - Test coverage

            Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.

            Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.

          # See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
          # or https://code.claude.com/docs/en/cli-reference for available options
          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:*),Bash(nu toolkit.nu testing:*),Bash(nu toolkit.nu testing-unit:*),Bash(nu toolkit.nu testing-integration:*),Bash(use numd;*)"'

Why I Cannot Push

GitHub Apps require special workflows permission to modify files in .github/workflows/. This is a security measure to prevent automated tools from modifying CI/CD pipelines. When I attempted to push:

! [remote rejected] claude/pr-90-20251213-2019 -> claude/pr-90-20251213-2019 
  (refusing to allow a GitHub App to create or update workflow without `workflows` permission)

What These Fixes Enable

Once applied, these changes will:

  • ✅ Allow Claude to create commits and branches when fixing bugs
  • ✅ Allow Claude to comment on PRs and issues with responses
  • ✅ Enable Nushell commands in both workflows
  • ✅ Allow code reviews to run nu toolkit.nu testing commands
  • ✅ Fully resolve all 5 issues identified in the previous review

The changes are ready to go - just need to be applied to the main branch manually!


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