Chapter 04 · Section IV · 10 min read
4.4 GitHub Actions: @claude, workflows, env
Wire Claude Code into your CI: the @claude mention in PRs, the workflow YAML shape, and how secrets and env vars flow into the job.
The GitHub Actions integration is Claude Code’s answer to “how do I run this in CI, on PRs, on issues, without maintaining bespoke shell glue?” It ships as a reusable action that responds to @claude mentions or fires on standard events, with a small YAML surface.
The @claude mention
The most common shape: a workflow that watches for @claude in PR comments and reviews.
# .github/workflows/claude.yml
name: Claude
on:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
pull_request:
types: [opened, synchronize]
jobs:
claude:
if: contains(github.event.comment.body, '@claude') || github.event_name == 'pull_request'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
steps:
- uses: actions/checkout@v4
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
The action reads the mention, opens Claude Code inside the workflow’s workspace, and responds — comments back on the PR, opens sub-PRs, or performs whatever action was asked for.
The workflow-level env
For anything beyond the vanilla example, you will want to pass config through env:
- uses: anthropics/claude-code-action@v1
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
model: claude-opus-4-7
permission_mode: acceptEdits
additional_directories: |
packages/shared
docs
env:
MY_INTERNAL_API: ${{ secrets.MY_INTERNAL_API }}
with:— inputs to the action itself.env:— regular workflow env, available to any Bash tool Claude runs.
Permissions on the GitHub token
The action needs a token scoped for whatever it should be able to do:
permissions:
contents: write # push commits, open PRs
pull-requests: write # comment on PRs, edit descriptions
issues: write # comment on issues
Do not over-grant. If Claude only comments, do not give contents: write.
Scheduled runs
The action is not limited to comment triggers. Schedule Claude to run periodic tasks:
on:
schedule:
- cron: '0 9 * * 1' # Monday 9am UTC
Combined with a prompt file, this lets you run a weekly digest, an audit, or a health check without a human trigger.
Check your understanding
Quick check
—