Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Claude Code GitHub Actions

Claude Code GitHub Actions

Claude Code GitHub Actions brings AI-driven automation to your GitHub workflow.

By simply mentioning in a PR or issue @claude, Claude can analyze code, create Pull Requests, implement features, and fix bugs, while following your project's standard conventions.


Why Use Claude Code GitHub Actions


Quick Start

Method 1: Automatic Installation (Recommended)

Run in the Claude Code terminal:

/install-github-app

This guides you through:

Requirements: You must be a repository administrator. The GitHub App needs read/write permissions for Contents, Issues, and Pull requests. Only available to users who use the Claude API directly (AWS Bedrock or Google Vertex AI are not supported).

Method 2: Manual Installation

Step 1: Install the Claude GitHub App

to access:https://github.com/apps/claude

Required permissions:

Step 2: Add the API key

Add to the repository Secrets ANTHROPIC_API_KEY

Step 3: Create the workflow file

Copy from the example file:examples/claude.yml to .github/workflows/


Workflow Configuration

Basic Workflow (Responding to @claude Mentions)



name: Claude Code

on:

  issue_comment:

    types: [created]

  pull_request_review_comment:

    types: [created]

jobs:

  claude:

    runs-on: ubuntu-latest

    steps:

      - uses: anthropics/claude-code-action@v1

        with:

          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

Automatic Code Review



name: Code Review

on:

  pull_request:

    types: [opened, synchronize]

jobs:

  review:

    runs-on: ubuntu-latest

    steps:

      - 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."

          claude_args: "--max-turns 5"

Scheduled Tasks



name: Daily Report

on:

  schedule:

    - cron: "0 9 * * *"

jobs:

  report:

    runs-on: ubuntu-latest

    steps:

      - uses: anthropics/claude-code-action@v1

        with:

          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

          prompt: "Generate a summary of yesterday's commits and open issues"

          claude_args: "--model opus"


Common @claude Commands

Use in PR or issue comments:

@claude implement this feature based on the issue description

@claude how should I implement user authentication for this endpoint?

@claude fix the TypeError in the user dashboard component

@claude review this PR for security issues

@claude add tests for this new function


Action Parameter Details

Parameters Description Required
prompt Instructions for Claude (plain text or skill name) No*
claude_args CLI arguments passed to Claude Code No
anthropic_api_key Claude API key Yes**
github_token GitHub Token (for API access) No
trigger_phrase Custom trigger phrase (default:@claude) No
use_bedrock Use AWS Bedrock instead of the Claude API No
use_vertex Use Google Vertex AI instead of the Claude API No

*When used in issue/PR comments, omit prompt and Claude will respond to the trigger phrase

**Required when using the Claude API directly, not needed for Bedrock/Vertex

Common CLI Arguments

Parameters Description
--max-turns Maximum conversation turns (default 10)
--model Model to use (e.g. claude-sonnet-4-6)
--mcp-config MCP configuration file path
--allowedTools Allowed tools (comma-separated)
--append-system-prompt Append system prompt
--debug Enable debug output

claude_args Example



claude_args: |

  --max-turns 5

  --model claude-sonnet-4-6

  --mcp-config /path/to/config.json

  --append-system-prompt "Follow our coding standards"


AWS Bedrock Integration

Prerequisites

Required Secrets

Secret name Description
AWS_ROLE_TO_ASSUME IAM role ARN for Bedrock access
APP_ID GitHub App ID
APP_PRIVATE_KEY GitHub App private key

Bedrock Workflow Example



name: Claude PR Action

permissions:

  contents: write

  pull-requests: write

  issues: write

  id-token: write



on:

  issue_comment:

    types: [created]

  pull_request_review_comment:

    types: [created]



jobs:

  claude-pr:

    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'))

    runs-on: ubuntu-latest

    env:

      AWS_REGION: us-west-2

    steps:

      - name: Checkout repository

        uses: actions/checkout@v4



      - name: Generate GitHub App token

        id: app-token

        uses: actions/create-github-app-token@v2

        with:

          app-id: ${{ secrets.APP_ID }}

          private-key: ${{ secrets.APP_PRIVATE_KEY }}



      - 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



      - uses: anthropics/claude-code-action@v1

        with:

          github_token: ${{ steps.app-token.outputs.token }}

          use_bedrock: "true"

          claude_args: '--model us.anthropic.claude-sonnet-4-6 --max-turns 10'


Google Vertex AI Integration

Prerequisites

Required Secrets

Secret name Description
GCP_WORKLOAD_IDENTITY_PROVIDER Workload Identity Provider resource name
GCP_SERVICE_ACCOUNT Service account email with Vertex AI access
APP_ID GitHub App ID
APP_PRIVATE_KEY GitHub App private key

Vertex AI Workflow Example



name: Claude PR Action

permissions:

  contents: write

  pull-requests: write

  issues: write

  id-token: write



on:

  issue_comment:

    types: [created]



jobs:

  claude-pr:

    if: github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')

    runs-on: ubuntu-latest

    steps:

      - name: Checkout repository

        uses: actions/checkout@v4



      - name: Generate GitHub App token

        id: app-token

        uses: actions/create-github-app-token@v2

        with:

          app-id: ${{ secrets.APP_ID }}

          private-key: ${{ secrets.APP_PRIVATE_KEY }}



      - name: Authenticate to Google Cloud

        id: auth

        uses: google-github-actions/auth@v2

        with:

          workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}

          service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}



      - uses: anthropics/claude-code-action@v1

        with:

          github_token: ${{ steps.app-token.outputs.token }}

          trigger_phrase: "@claude"

          use_vertex: "true"

          claude_args: '--model claude-sonnet-4-5@20250929 --max-turns 10'

        env:

          ANTHROPIC_VERTEX_PROJECT_ID: ${{ steps.auth.outputs.project_id }}

          CLOUD_ML_REGION: us-east5


Upgrading from the Beta Version (v1.0 Breaking Changes)

Beta Inputs New v1.0 Inputs
mode (Removed - automatically detected)
direct_prompt prompt
override_prompt With GitHub variables prompt
custom_instructions claude_args: --append-system-prompt
max_turns claude_args: --max-turns
model claude_args: --model
allowed_tools claude_args: --allowedTools
disallowed_tools claude_args: --disallowedTools

Before and After Comparison

Beta version:



- uses: anthropics/claude-code-action@beta

  with:

    mode: "tag"

    direct_prompt: "Review this PR for security issues"

    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

    custom_instructions: "Follow our coding standards"

    max_turns: "10"

    model: "claude-sonnet-4-6"

GA version (v1.0):



- uses: anthropics/claude-code-action@v1

  with:

    prompt: "Review this PR for security issues"

    anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}

    claude_args: |

      --append-system-prompt "Follow our coding standards"

      --max-turns 10

      --model claude-sonnet-4-6


Troubleshooting

Claude does not respond to @claude commands

CI Does Not Run on Claude's Commits

Authentication Errors


Security considerations


Cost Considerations

Cost Breakdown

Cost Optimization Tips


Best Practices

1. Create CLAUDE.md

Create in the repository root CLAUDE.md file defining code style guidelines and project-specific rules:



# Project Development Guidelines



## 代码风格

- 使用 TypeScript 4.x

- 遵循 ESLint 配置

- 函数必须有 JSDoc 注释



## PR 要求

- 必须通过所有 CI 检查

- 至少一个代码审查

- 更新相关文档



## Prohibited Items

- 不要修改 `migrations/` 目录

- 不要提交 `.env` 文件

2. Use Specific @claude Commands

@claude review this PR for SQL injection vulnerabilities

@claude add unit tests for the new validateEmail function

3. Configure Appropriate Limits



jobs:

  claude:

    runs-on: ubuntu-latest

    timeout-minutes: 15  # 设置超时

    steps:

      - uses: anthropics/claude-code-action@v1

        with:

          claude_args: "--max-turns 5 --allowedTools Read,Grep,Glob,Bash,Write,Edit"

4. CI/CD Automation Scenarios