YouTip LogoYouTip

Claude Code Github Actions

Claude Code GitHub Actions brings AI-powered automation to your GitHub workflows. By simply mentioning `@claude` in a PR or Issue, Claude can analyze code, create Pull Requests, implement features, fix bugs, and follow your project's standard guidelines. * * * ## Why Use Claude Code GitHub Actions * **Instant PR Creation**: Describe your needs, and Claude will create a complete Pull Request * **Automated Code Implementation**: Transform Issues into working code with a single command * **Follows Project Standards**: Respects your `CLAUDE.md` guidelines and existing code patterns * **Simple and Fast**: Get started in minutes * **Safe and Reliable**: Code runs on GitHub's runners * * * ## Quick Start ### Method 1: Automatic Installation (Recommended) Run in the Claude Code terminal: /install-github-app This will guide you through: * Setting up the GitHub App * Adding necessary Secrets > Requirements: You must be a repository admin. The GitHub App needs read/write permissions for Contents, Issues, and Pull requests. Only available for users directly using the Claude API (not supported for AWS Bedrock or Google Vertex AI). ### Method 2: Manual Installation #### Step 1: Install Claude GitHub App Visit: [https://github.com/apps/claude](https://github.com/apps/claude) Required permissions: * **Contents**: Read and write * **Issues**: Read and write * **Pull requests**: Read and write #### Step 2: Add API Key Add `ANTHROPIC_API_KEY` to your repository Secrets #### Step 3: Create Workflow File Copy from example: `examples/claude.yml` to `.github/workflows/` * * * ## Workflow Configuration ### Basic Workflow (Responds to @claude mentions) name: Claude Code on: issue_comment: types: pull_request_review_comment: types: jobs: claude: runs-on: ubuntu-latest steps: - uses: anthropics/claude-code-action@v1 with: anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }} ### Automated 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 Parameters Explained | Parameter | 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 Claude API | No | | `use_vertex` | Use Google Vertex AI instead of Claude API | No | *Omit prompt when used in issue/PR comments; Claude will respond to the trigger phrase **Required when using Claude API directly, not needed for Bedrock/Vertex ### Common CLI Parameters | Parameter | 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 Examples 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 enabled with Claude model permissions * GitHub configured as OIDC identity provider in AWS * IAM role with 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: pull_request_review_comment: types: 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 * Vertex AI API enabled in GCP project * Workload Identity Federation configured 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: 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 Beta (v1.0 Breaking Changes) | Beta Input | New v1.0 Input | | --- | --- | | `mode` | (Removed - auto-detected) | | `direct_prompt` | `prompt` | | `override_prompt` | `prompt` with GitHub variables | | `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 Not Responding to @claude Commands * Confirm GitHub App is properly installed * Check if workflow is enabled * Ensure API key is set in repository Secrets * Verify comment contains `@claude` (not `/claude`) ### CI Not Running on Claude's Commits * Use GitHub App or custom app (not Actions user) * Check workflow triggers include necessary events * Confirm app permissions include CI triggers ### Authentication Errors * Confirm API key is valid with sufficient permissions * For Bedrock/Vertex: check credential configuration * Ensure Secrets names are correct in workflow * * * ## Security Considerations * **Never commit API keys directly** to repository * Use GitHub Secrets to store API keys: `${{ secrets.ANTHROPIC_API_KEY }}` * Limit action permissions to only what's necessary * Review Claude's suggestions before merging * For AWS/GCP: Use OIDC identity providers instead of static credentials * Create dedicated service accounts for each repository * * * ## Cost Considerations ### Cost Components * **GitHub Actions costs**: Runs 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 `@claude` commands to reduce unnecessary API calls * Configure appropriate `--max-turns` to limit conversation turns * Set workflow timeouts to prevent runaway tasks * Use GitHub concurrency controls to limit parallel runs * * * ## Best Practices ### 1. Create CLAUDE.md Create a `CLAUDE.md` file in your repository root to define code style guidelines and project-specific rules: # Project Development Standards## Code Style- Use TypeScript 4.x- Follow ESLint configuration- Functions must have JSDoc comments## PR Requirements
← Ref Math Exp2Claude Code Env β†’