Claude Code Action

repository·main·Indexed 27 days ago

https://github.com/anthropics/claude-code-action

A GitHub Action that integrates Claude Code capabilities into PRs and issues for automated code reviews, implementation, and repository maintenance. It includes the agent-approval-check to require human approvals for AI-authored commits and the claude-code-base-action, a wrapper to execute Claude Code within workflows with support for Anthropic API, Amazon Bedrock, and Google Vertex AI via OIDC authentication.

Tokens
35K
Snippets
77
Records
127
Agent score
93%

What's inside claude-code-action

  1. Overview of Claude Code Base Action

    main

    The anthropics/claude-code-base-action is a GitHub Action that allows you to run Claude Code directly within your GitHub Actions workflows. It acts as a thin wrapper that installs and executes Claude Code with your provided inputs.

    Important Security Note: This action does not enforce trust boundaries. It reads project-level configuration (like .claude/, CLAUDE.md, or .mcp.json) from the working directory. The caller is responsible for ensuring the working directory and prompt are trusted. For workflows processing untrusted input (e.g., issues or fork PRs), use anthropics/claude-code-action instead.

  2. Overview of Claude Code Action Features

    main

    Claude Code Action is a general-purpose GitHub action for PRs and issues that can answer questions and implement code changes. It features:

    • Intelligent Mode Detection: Automatically selects execution modes based on workflow context (e.g., @claude mentions or issue assignments).
    • Interactive Assistant & Code Review: Can answer architectural questions, analyze PR changes, and suggest improvements.
    • Code Implementation: Capable of implementing simple fixes, refactoring, and new features.
    • Flexible Tool Access: Access to GitHub APIs and file operations; additional tools can be enabled via configuration.
    • Progress Tracking: Uses visual checkboxes in GitHub comments to show task completion.
    • Structured Outputs: Provides validated JSON results that can be used as GitHub Action outputs for automation.
    • Infrastructure: Runs entirely on your own GitHub runner.
  3. Understand Claude Code Action capabilities

    main

    Claude Code Action is an agentic tool that operates primarily by updating a single initial comment to provide progress and results.

    Key Capabilities:

    • Code Implementation: Makes simple to moderate code changes based on requests.
    • Code Review: Analyzes PR changes and provides detailed feedback.
    • Pull Request Preparation: Creates commits on a branch and provides a link to a prefilled PR creation page.
    • Question Answering: Analyzes code to provide explanations.
    • Smart Branch Handling:
      • Issues: Always creates a new branch.
      • Open PRs: Pushes directly to the existing PR branch.
      • Closed PRs: Creates a new branch.
    • CI/CD Visibility: Can view GitHub Actions results (workflow runs, job logs, test results) if actions: read permission is configured.

    Key Limitations:

    • No Formal PR Reviews: Cannot submit formal GitHub PR reviews or approve pull requests.
    • Single Comment Constraint: Cannot post multiple comments; it only updates its initial comment.
    • Restricted Execution: Cannot execute arbitrary Bash commands by default (requires allowed_tools configuration) and cannot execute commands outside its provided context.
    • Limited Git Operations: Cannot merge branches or rebase; it is limited to pushing commits.
  4. Quickstart: Install Claude Code Action via Claude Code CLI

    main

    The fastest way to set up the action is using the claude terminal interface. This method is specifically for users using the direct Anthropic API.

    1. Open claude in your terminal.
    2. Run the /install-github-app command.
    3. Follow the interactive prompts to set up the GitHub app and required secrets.

    Requirements & Limitations:

    • You must have repository admin permissions.
    • This method is not available for users configuring via AWS Bedrock, Google Vertex AI, or Microsoft Foundry. For those providers, refer to the cloud provider documentation.
    /install-github-app
  5. Quickstart: Add Claude Code Action to GitHub Workflows

    main

    To use the Claude Code Action, create a workflow file in your repository (e.g., .github/workflows/claude.yml). The action can be triggered by issue comments, pull request review comments, new issues, or pull request reviews. You must provide either an anthropic_api_key or a claude_code_oauth_token to authenticate.

    name: Claude Assistant
    on:
      issue_comment:
        types: [created]
      pull_request_review_comment:
        types: [created]
      issues:
        types: [opened, assigned, labeled]
      pull_request_review:
        types: [submitted]
    
    jobs:
      claude-response:
        runs-on: ubuntu-latest
        steps:
          - uses: anthropics/claude-code-action@v1
            with:
              anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
  6. Interact with Claude via @claude mentions

    main

    By default, Claude is triggered in PRs or Issues whenever a user mentions @claude. Claude has access to the full PR context and can perform several tasks:

    • Ask Questions: @claude What does this function do?
    • Request Fixes: @claude Can you add error handling to this function?
    • Code Review: @claude Please review this PR and suggest improvements
    • Visual Bug Fixing: Upload a screenshot and ask @claude Here's a screenshot of a bug... Can you fix it?

    You can customize the trigger phrase using the trigger_phrase input in your workflow configuration.

  7. Understand Mode Detection (Interactive vs. Automation)

    main

    The action switches between two modes based on the presence of the prompt input:

    • Interactive Mode: Triggered when no prompt input is provided. It responds to @claude mentions in comments and creates tracking comments with progress indicators.
    • Automation Mode: Triggered when a prompt input is provided. It executes immediately without requiring manual mentions.

    Note on Tracking: In v1, Automation Mode does not create tracking comments by default to reduce noise. To enable progress tracking in automation mode, set the track_progress: true input parameter.

  8. Securely configure the Anthropic API key

    main

    Never hardcode API keys in your workflow files. Instead, store your key in GitHub Actions secrets and reference it using the anthropic_api_key input.

    1. Create a repository secret named ANTHROPIC_API_KEY in your GitHub repository settings.
    2. Reference it in your YAML workflow using the ${{ secrets.ANTHROPIC_API_KEY }} syntax.
    # ✅ CORRECT - Uses GitHub secrets
    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
  9. Use a Custom GitHub App

    main

    If you cannot use the official Claude app (e.g., due to organization policies or if using AWS Bedrock/Google Vertex AI), you can use a custom GitHub App.

    Use the Quick Setup Tool or the github-app-manifest.json to automatically configure all required permissions.

    Option 2: Manual Setup

    1. Create App: Create a new GitHub App with these minimum permissions:
      • Repository permissions:
        • Contents: Read & Write
        • Issues: Read & Write
        • Pull requests: Read & Write
    2. Generate Key: Generate and download a .pem private key.
    3. Install App: Install the app on your target repository.
    4. Configure Secrets: Add APP_ID and APP_PRIVATE_KEY (the .pem content) to your repository secrets.
    5. Workflow Integration: Use actions/create-github-app-token@v1 to generate a token for the Claude action.
    jobs:
      claude-response:
        runs-on: ubuntu-latest
        steps:
          - name: Generate GitHub App token
            id: app-token
            uses: actions/create-github-app-token@v1
            with:
              app-id: ${{ secrets.APP_ID }}
              private-key: ${{ secrets.APP_PRIVATE_KEY }}
    
          - uses: anthropics/claude-code-action@v1
            with:
              anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
              github_token: ${{ steps.app-token.outputs.token }}
  10. Configure Claude Code Action with Microsoft Foundry

    main

    To use Microsoft Foundry, set use_foundry: "true" and specify the Foundry-compatible model name using the claude_args input. Microsoft Foundry requires OIDC authentication and requires setting the ANTHROPIC_FOUNDRY_BASE_URL environment variable.

    - uses: anthropics/claude-code-action@v1
      with:
        use_foundry: "true"
        claude_args: |
          --model claude-sonnet-4-5
        # ... other inputs
      env:
        ANTHROPIC_FOUNDRY_BASE_URL: https://my-resource.services.ai.azure.com
  11. Use Amazon Bedrock with OIDC authentication

    main

    To use Claude via Amazon Bedrock, use OIDC authentication (e.g., via aws-actions/configure-aws-credentials) and set use_bedrock: "true". You must use provider-specific model names (e.g., anthropic.claude-3-7-sonnet-20250219-v1:0). The Bedrock API endpoint is automatically constructed using the AWS_REGION environment variable, but can be overridden with ANTHROPIC_BEDROCK_BASE_URL.

    - name: Configure AWS Credentials (OIDC)
      uses: aws-actions/configure-aws-credentials@v4
      with:
        role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}
        aws-region: us-west-2
    
    - name: Run Claude Code with AWS OIDC
      uses: anthropics/claude-code-base-action@beta
      with:
        prompt: "Your prompt here"
        use_bedrock: "true"
        model: "anthropic.claude-3-7-sonnet-20250219-v1:0"
        allowed_tools: "Bash(git:*),View,GlobTool,GrepTool,BatchTool"