GitHub Actions Examples for Claude Code
Production-ready workflow examples for common Claude Code automation scenarios.
π― Example Categories
1. Code Review Automation
Comprehensive PR Review
name: Comprehensive PR Review
on:
pull_request:
types: [opened, synchronize, ready_for_review]
jobs:
code-review:
runs-on: ubuntu-latest
permissions:
pull-requests: write
contents: read
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for better context
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
github_token: ${{ secrets.GITHUB_TOKEN }}
direct_prompt: |
Perform a comprehensive code review:
1. **Security Analysis**
- Check for SQL injection vulnerabilities
- Identify hardcoded secrets or credentials
- Review authentication/authorization logic
- Check for XSS vulnerabilities
2. **Code Quality**
- Identify code smells and anti-patterns
- Suggest refactoring opportunities
- Check for proper error handling
- Review naming conventions
3. **Performance**
- Identify potential performance bottlenecks
- Check for N+1 queries
- Review algorithm complexity
- Suggest optimization opportunities
4. **Testing**
- Verify test coverage for new code
- Suggest missing test cases
- Check test quality
5. **Documentation**
- Verify inline documentation
- Check if README needs updates
- Review API documentation
Format findings as:
- π΄ Critical issues (must fix)
- π‘ Warnings (should fix)
- π’ Suggestions (nice to have)
- π Good practices observedLanguage-Specific Reviews
name: TypeScript Specific Review
on:
pull_request:
paths:
- '**.ts'
- '**.tsx'
jobs:
typescript-review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Review TypeScript code for:
1. Type Safety
- Any use of 'any' type
- Missing type annotations
- Type assertions that could be avoided
- Proper use of generics
2. Modern TypeScript Features
- Suggest const assertions where appropriate
- Recommend template literal types
- Check for proper use of utility types
3. React Specific (if applicable)
- Proper typing of props and state
- Use of React.FC vs function declarations
- Event handler typing
4. Best Practices
- Prefer interfaces over type aliases for objects
- Use enums vs const assertions appropriately
- Proper error handling with Result types2. Automated Bug Fixes
Smart Bug Fixer
name: Automated Bug Fix
on:
issues:
types: [labeled]
jobs:
fix-bug:
if: contains(github.event.label.name, 'auto-fix')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
- name: Setup environment
run: |
# Cache key for dependencies
echo "CACHE_KEY=${{ runner.os }}-${{ hashFiles('**/package-lock.json') }}" >> $GITHUB_ENV
- uses: actions/cache@v3
with:
path: node_modules
key: ${{ env.CACHE_KEY }}
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_env: |
NODE_ENV: test
CI: true
direct_prompt: |
Analyze the bug described in this issue and:
1. Reproduce the bug by:
- Understanding the issue description
- Writing a failing test case
- Confirming the test fails
2. Fix the bug by:
- Identifying root cause
- Implementing minimal fix
- Ensuring all tests pass
3. Prevent regression by:
- Adding comprehensive test coverage
- Documenting the fix
- Checking for similar issues
4. Create a PR with:
- Clear description of the fix
- Link to this issue
- Test resultsTest Failure Fixer
name: Fix Failing Tests
on:
workflow_run:
workflows: ["CI Tests"]
types: [completed]
jobs:
fix-tests:
if: ${{ github.event.workflow_run.conclusion == 'failure' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
actions: read
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.workflow_run.head_branch }}
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
additional_permissions: |
actions: read
direct_prompt: |
Analyze the test failures and fix them:
1. Download and analyze test logs
2. Identify failing tests and error messages
3. Determine if it's a:
- Test issue (fix the test)
- Code issue (fix the code)
- Flaky test (improve stability)
4. Implement fixes
5. Verify all tests pass locally
6. Create fix PR with explanation3. Feature Implementation
Issue to Implementation
name: Implement Feature from Issue
on:
issues:
types: [labeled]
issue_comment:
types: [created]
jobs:
implement-feature:
if: |
(github.event_name == 'issues' && contains(github.event.label.name, 'implement')) ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude implement'))
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
max_conversation_turns: 30 # Complex features need more turns
timeout_minutes: 45
direct_prompt: |
Implement the feature described in this issue:
1. Analysis Phase:
- Break down requirements
- Identify affected components
- Plan implementation approach
2. Implementation Phase:
- Create feature branch
- Implement incrementally
- Follow existing patterns
- Add proper error handling
3. Testing Phase:
- Write unit tests
- Add integration tests
- Test edge cases
- Verify performance
4. Documentation Phase:
- Update API docs
- Add usage examples
- Update README if needed
- Add inline comments
5. Create PR with:
- Feature description
- Testing instructions
- Screenshots if UI changes
- Breaking changes notedAPI Endpoint Generator
name: Generate API Endpoint
on:
issues:
types: [labeled]
jobs:
generate-api:
if: contains(github.event.label.name, 'new-api')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Create a new API endpoint based on the issue description:
1. Generate endpoint code:
- Route handler
- Request validation
- Business logic
- Response formatting
- Error handling
2. Add middleware:
- Authentication
- Rate limiting
- Request logging
- CORS if needed
3. Create tests:
- Unit tests for handler
- Integration tests
- Error case tests
- Performance tests
4. Generate documentation:
- OpenAPI/Swagger spec
- Usage examples
- Error responses
- Rate limits
5. Update related files:
- Route configuration
- Type definitions
- API client if exists4. Documentation Automation
Smart Documentation Updates
name: Auto-Update Documentation
on:
push:
branches: [main]
paths:
- 'src/**'
- 'api/**'
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 2 # Need previous commit
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v39
with:
files: |
src/**
api/**
- uses: anthropics/claude-code-action@beta
if: steps.changed-files.outputs.any_changed == 'true'
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Update documentation for changed files:
${{ steps.changed-files.outputs.all_changed_files }}
Tasks:
1. Update API documentation
2. Update code examples
3. Update README sections
4. Generate migration guide if breaking changes
5. Update changelog
Skip if changes are:
- Only formatting
- Only internal refactoring
- Test-only changes5. CI/CD Integration
Intelligent Deployment Checker
name: Pre-Deployment Validation
on:
pull_request:
branches: [main]
types: [opened, synchronize]
jobs:
deployment-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_env: |
DEPLOYMENT_ENV: production
CHECK_BREAKING_CHANGES: true
direct_prompt: |
Perform pre-deployment validation:
1. Breaking Changes Check:
- API compatibility
- Database migrations needed
- Configuration changes
- Deprecation warnings
2. Performance Impact:
- New dependencies size
- Query performance
- Memory usage changes
- Build time impact
3. Security Scan:
- Dependency vulnerabilities
- New external connections
- Permission changes
- Secrets handling
4. Rollback Plan:
- Feature flags needed
- Database rollback scripts
- Quick disable options
Create deployment checklist as PR comment6. Monitoring and Alerts
Performance Regression Detector
name: Performance Analysis
on:
pull_request:
types: [opened, synchronize]
jobs:
perf-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run benchmarks
run: |
npm run benchmark > benchmark-results.txt
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Analyze performance impact:
1. Review benchmark results
2. Compare with baseline
3. Identify regressions:
- >10% slower: Critical
- 5-10% slower: Warning
- <5% slower: Info
4. Suggest optimizations
5. Comment on PR with findingsπ§ Utility Workflows
Repository Maintenance
name: Weekly Maintenance
on:
schedule:
- cron: '0 9 * * 1' # Every Monday at 9 AM
jobs:
maintenance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Perform weekly maintenance tasks:
1. Check for outdated dependencies
2. Review stale issues/PRs
3. Update documentation TODOs
4. Check for deprecated API usage
5. Create maintenance report issueSmart Issue Triage
name: Issue Triage
on:
issues:
types: [opened]
jobs:
triage:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: anthropics/claude-code-action@beta
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
direct_prompt: |
Triage this issue:
1. Categorize (bug/feature/question)
2. Assess priority (P0-P3)
3. Suggest relevant labels
4. Check for duplicates
5. Add initial response
6. Assign to appropriate teamπ‘ Best Practices
1. Error Handling
- uses: anthropics/claude-code-action@beta
id: claude
continue-on-error: true
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
- name: Handle Claude errors
if: steps.claude.outcome == 'failure'
run: |
echo "Claude action failed, falling back to manual process"
# Notify team or trigger alternative workflow2. Cost Control
# Limit Claude usage to specific conditions
if: |
github.event.pull_request.draft == false &&
github.event.pull_request.user.type != 'Bot' &&
contains(github.event.pull_request.labels.*.name, 'needs-review')3. Caching Strategies
- name: Cache Claude context
uses: actions/cache@v3
with:
path: .claude-cache
key: claude-${{ github.sha }}
restore-keys: |
claude-${{ github.event.pull_request.base.sha }}
claude-π Resources
πΊοΈ Navigation
β GitHub Actions Guide | Advanced Patterns β | Troubleshooting β