Claude Code GitHub Actions
Configure automation using anthropics/claude-code-action with event routing, subagents, hooks, and MCP integration.
Quick Start
name: Claude Code
on:
issue_comment: { types: [created] }
pull_request: { types: [opened, synchronize] }
issues: { types: [opened, labeled] }
permissions:
contents: write
pull-requests: write
issues: write
jobs:
claude:
if: github.actor != 'github-actions[bot]'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
Core Concepts
| Concept |
Purpose |
Details |
| Event Routing |
Route GitHub events to behaviors |
patterns/event-routing.md |
| Subagents |
Parallel execution in isolated contexts |
patterns/subagents.md |
| Hooks |
Quality gates and automation |
patterns/hooks.md |
| MCP Servers |
External tool integration |
official-docs/configuration.md |
| Permissions |
Tool and access control |
patterns/permissions.md |
| Security |
Fork-safe PR handling |
patterns/security.md |
| Reusable Workflows |
Organization-wide sharing |
patterns/reusable-workflows.md |
| Performance |
Optimization patterns |
patterns/performance.md |
| Skills |
Domain expertise |
patterns/skill-usage.md |
| Official Docs |
Upstream documentation |
official-docs/ |
Key Patterns
Event Routing
jobs:
pr-comment:
if: github.event_name == 'issue_comment' && github.event.issue.pull_request
issue-comment:
if: github.event_name == 'issue_comment' && !github.event.issue.pull_request
label-triggered:
if: contains(github.event.issue.labels.*.name, 'claude-implement')
Subagents
prompt: |
Delegate to 3 parallel subagents:
1. Security Agent: OWASP Top 10, auth checks
2. Performance Agent: N+1 queries, memory leaks
3. Style Agent: Naming, documentation, tests
Hooks
{
"hooks": {
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [{ "type": "command", "command": "npx prettier --write $(jq -r '.tool_input.file_path')" }]
}],
"Stop": [{
"hooks": [{ "type": "command", "command": "npm run lint && npm test" }]
}]
}
}
Performance
concurrency:
group: claude-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
on:
pull_request:
paths: ['src/**', '!**/*.md']
Tuning Reference
| Scenario |
Max Turns |
Model |
Timeout |
| Triage/labeling |
2-3 |
sonnet |
5 min |
| Code review |
8-12 |
sonnet |
15 min |
| Implementation |
15-20 |
sonnet |
20 min |
| Security audit |
10-15 |
opus |
30 min |
Critical Gotchas
--allowedTools vs --disallowedTools
allowedTools only skips prompts—does NOT restrict tools
- Use
disallowedTools to actually block: --disallowedTools Bash,Run,Edit
MCP + Subagents
- MCP tools do NOT work in background subagents
- Always run MCP operations in foreground
Fork Safety
pull_request event = safe (read-only token, no secrets)
pull_request_target = dangerous if you checkout fork code
- Never:
checkout ref: ${{ github.event.pull_request.head.sha }} with secrets
Hook Exit Codes
0 = continue
2 = block, feed stderr to Claude
- Other = log error, don't block
Subagent Limits
- ~10 concurrent subagents max
- Additional tasks queue
Examples
See examples/ for 14 production-ready use cases:
| # |
Use Case |
Techniques |
| 1 |
Parallel Review Pipeline |
Subagents, concurrency |
| 2 |
ChatOps Command Router |
Event routing, comment parsing |
| 3 |
Issue-to-Implementation |
Label triggers, Stop hooks |
| 4 |
Compliance Firewall |
PreToolUse blocking, PostToolUse formatting |
| 5 |
Security Review |
Path filtering, tool restrictions |
| 6 |
Monorepo Support |
dorny/paths-filter, language skills |
| 7 |
Ticket Sync |
MCP servers (foreground!) |
| 8 |
Fork-Safe Review |
pull_request event, disallowedTools |
| 9 |
Scheduled Maintenance |
Cron, parallel subagents |
| 10 |
Documentation Sync |
Scheduled, MCP |
| 11 |
Dependency Review |
Bot filtering, semver skill |
| 12 |
Release Notes |
Release event, categorization |
| 13 |
Reusable Workflow |
workflow_call, inputs/outputs |
| 14 |
CLAUDE.md Pattern |
Project context, conventions |
Patterns
- Event Routing - Conditions, label routing, author associations
- Subagents - Creation, parallel execution, built-in types
- Hooks - All events, exit codes, JSON parsing, examples
- Permissions - Tool control layers, known issues
- Security - Fork handling, external contributors, safe patterns
- Reusable Workflows - workflow_call, composite actions
- Performance - Concurrency, caching, path filtering
- Skills - Domain expertise, skill structure, hooks
Official Docs
Synced from anthropics/claude-code-action:
- Configuration - MCP servers, settings, custom tools
- Security - API key protection, commit signing
- Usage - Inputs, outputs, migration guide
1---2name: cc-actions3description: |4 Configure Claude Code GitHub Actions workflows effectively. Covers automatic mode detection,5 event routing, subagent coordination, hooks for quality gates, MCP server integration,6 reusable workflows, performance optimization, and security best practices for fork-based PRs.7 Use when working with GitHub Actions, CI/CD automation, PR reviews, issue automation,8 claude-code-action, chatops, MCP servers, fork safety, or reusable workflows.9user-invocable: true10allowed-tools: Read Write Edit Glob Grep Bash11---1213# Claude Code GitHub Actions1415Configure automation using [`anthropics/claude-code-action`](https://github.com/anthropics/claude-code-action) with event routing, subagents, hooks, and MCP integration.1617## Quick Start1819```yaml20name: Claude Code21on:22 issue_comment: { types: [created] }23 pull_request: { types: [opened, synchronize] }24 issues: { types: [opened, labeled] }2526permissions:27 contents: write28 pull-requests: write29 issues: write3031jobs:32 claude:33 if: github.actor != 'github-actions[bot]'34 runs-on: ubuntu-latest35 steps:36 - uses: actions/checkout@v437 - uses: anthropics/claude-code-action@v138 with:39 anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}40```4142## Core Concepts4344| Concept | Purpose | Details |45|---------|---------|---------|46| **Event Routing** | Route GitHub events to behaviors | [patterns/event-routing.md](patterns/event-routing.md) |47| **Subagents** | Parallel execution in isolated contexts | [patterns/subagents.md](patterns/subagents.md) |48| **Hooks** | Quality gates and automation | [patterns/hooks.md](patterns/hooks.md) |49| **MCP Servers** | External tool integration | [official-docs/configuration.md](official-docs/configuration.md) |50| **Permissions** | Tool and access control | [patterns/permissions.md](patterns/permissions.md) |51| **Security** | Fork-safe PR handling | [patterns/security.md](patterns/security.md) |52| **Reusable Workflows** | Organization-wide sharing | [patterns/reusable-workflows.md](patterns/reusable-workflows.md) |53| **Performance** | Optimization patterns | [patterns/performance.md](patterns/performance.md) |54| **Skills** | Domain expertise | [patterns/skill-usage.md](patterns/skill-usage.md) |55| **Official Docs** | Upstream documentation | [official-docs/](official-docs/) |5657## Key Patterns5859### Event Routing6061```yaml62jobs:63 pr-comment:64 if: github.event_name == 'issue_comment' && github.event.issue.pull_request65 issue-comment:66 if: github.event_name == 'issue_comment' && !github.event.issue.pull_request67 label-triggered:68 if: contains(github.event.issue.labels.*.name, 'claude-implement')69```7071### Subagents7273```yaml74prompt: |75 Delegate to 3 parallel subagents:76 1. Security Agent: OWASP Top 10, auth checks77 2. Performance Agent: N+1 queries, memory leaks78 3. Style Agent: Naming, documentation, tests79```8081### Hooks8283```json84{85 "hooks": {86 "PostToolUse": [{87 "matcher": "Edit|Write",88 "hooks": [{ "type": "command", "command": "npx prettier --write $(jq -r '.tool_input.file_path')" }]89 }],90 "Stop": [{91 "hooks": [{ "type": "command", "command": "npm run lint && npm test" }]92 }]93 }94}95```9697### Performance9899```yaml100concurrency:101 group: claude-${{ github.workflow }}-${{ github.ref }}102 cancel-in-progress: true103104on:105 pull_request:106 paths: ['src/**', '!**/*.md']107```108109## Tuning Reference110111| Scenario | Max Turns | Model | Timeout |112|----------|-----------|-------|---------|113| Triage/labeling | 2-3 | sonnet | 5 min |114| Code review | 8-12 | sonnet | 15 min |115| Implementation | 15-20 | sonnet | 20 min |116| Security audit | 10-15 | opus | 30 min |117118## Critical Gotchas1191201. **`--allowedTools` vs `--disallowedTools`**121 - `allowedTools` only skips prompts—does NOT restrict tools122 - Use `disallowedTools` to actually block: `--disallowedTools Bash,Run,Edit`1231242. **MCP + Subagents**125 - MCP tools do NOT work in background subagents126 - Always run MCP operations in foreground1271283. **Fork Safety**129 - `pull_request` event = safe (read-only token, no secrets)130 - `pull_request_target` = dangerous if you checkout fork code131 - Never: `checkout ref: ${{ github.event.pull_request.head.sha }}` with secrets1321334. **Hook Exit Codes**134 - `0` = continue135 - `2` = block, feed stderr to Claude136 - Other = log error, don't block1371385. **Subagent Limits**139 - ~10 concurrent subagents max140 - Additional tasks queue141142## Examples143144See [examples/](examples/) for 14 production-ready use cases:145146| # | Use Case | Techniques |147|---|----------|------------|148| 1 | Parallel Review Pipeline | Subagents, concurrency |149| 2 | ChatOps Command Router | Event routing, comment parsing |150| 3 | Issue-to-Implementation | Label triggers, Stop hooks |151| 4 | Compliance Firewall | PreToolUse blocking, PostToolUse formatting |152| 5 | Security Review | Path filtering, tool restrictions |153| 6 | Monorepo Support | dorny/paths-filter, language skills |154| 7 | Ticket Sync | MCP servers (foreground!) |155| 8 | Fork-Safe Review | pull_request event, disallowedTools |156| 9 | Scheduled Maintenance | Cron, parallel subagents |157| 10 | Documentation Sync | Scheduled, MCP |158| 11 | Dependency Review | Bot filtering, semver skill |159| 12 | Release Notes | Release event, categorization |160| 13 | Reusable Workflow | workflow_call, inputs/outputs |161| 14 | CLAUDE.md Pattern | Project context, conventions |162163## Patterns164165- [Event Routing](patterns/event-routing.md) - Conditions, label routing, author associations166- [Subagents](patterns/subagents.md) - Creation, parallel execution, built-in types167- [Hooks](patterns/hooks.md) - All events, exit codes, JSON parsing, examples168- [Permissions](patterns/permissions.md) - Tool control layers, known issues169- [Security](patterns/security.md) - Fork handling, external contributors, safe patterns170- [Reusable Workflows](patterns/reusable-workflows.md) - workflow_call, composite actions171- [Performance](patterns/performance.md) - Concurrency, caching, path filtering172- [Skills](patterns/skill-usage.md) - Domain expertise, skill structure, hooks173174## Official Docs175176Synced from [anthropics/claude-code-action](https://github.com/anthropics/claude-code-action):177178- [Configuration](official-docs/configuration.md) - MCP servers, settings, custom tools179- [Security](official-docs/security.md) - API key protection, commit signing180- [Usage](official-docs/usage.md) - Inputs, outputs, migration guide