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
- Instant PR creation: Describe your needs and Claude can create a complete Pull Request
- Automated code implementation: Turn an issue into working code with just one command
- Follow project standards: Respect your
CLAUDE.mdguidelines and existing code patterns - Simple and fast: Get started within a few minutes
- Safe and reliable: Code stays and runs on GitHub's runners
Quick Start
Method 1: Automatic Installation (Recommended)
Run in the Claude Code terminal:
/install-github-app
This guides you through:
- Setting up the GitHub App
- Adding the necessary Secrets
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:
- Contents: Read/write permission
- Issues: Read/write permission
- Pull requests: Read/write permission
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
- AWS Bedrock access is enabled, including permissions for Claude models
- GitHub is configured as an OIDC identity provider in AWS
- The IAM role has Bedrock permissions
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
- Enable the Vertex AI API in the GCP project
- Configure Workload Identity Federation for GitHub
- Service account with Vertex AI permissions
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
- Confirm the GitHub App is properly installed
- Check that the workflow is enabled
- Ensure the API key is set in the repository Secrets
- Confirm the comment contains
@claude(not/claude)
CI Does Not Run on Claude's Commits
- Use a GitHub App or custom app (do not use the Actions user)
- Check that workflow triggers include the necessary events
- Confirm app permissions include CI triggers
Authentication Errors
- Confirm the API key is valid and has sufficient permissions
- For Bedrock/Vertex: check credential configuration
- Ensure Secret names are correct in the workflow
Security considerations
- Never commit API keys directlyto the repository
- Use GitHub Secrets to store API keys:
${{ secrets.ANTHROPIC_API_KEY }} - Limit action permissions, granting only what is necessary
- Review Claude's suggestions before merging
- For AWS/GCP: use OIDC identity providers instead of static credentials
- Create a dedicated service account for each repository
Cost Considerations
Cost Breakdown
- GitHub Actions costs: Run on GitHub-hosted runners, consuming GitHub Actions minutes
- API costs: Each Claude interaction consumes API tokens based on prompt/response length
Cost Optimization Tips
- Use specific
@claudecommands to reduce unnecessary API calls - Configure appropriate
--max-turnsto limit the number of conversation turns - Set workflow timeouts to avoid runaway tasks
- Use GitHub concurrency controls to limit parallel runs
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
- PR auto-review: Automatically trigger review when a PR is opened or updated
- Automatic Issue Triage: Automatically add labels and assignees when a new issue is created
- Scheduled reports: Generate daily code statistics or security reports
- Automated Fixes: Automatically analyze and attempt to fix when CI fails