Claude Code in GitHub Actions: 8 automation patterns | Claude Code Toolkit
Patterns

Claude Code in GitHub Actions: 8 automation patterns

How to run Claude Code from CI to review PRs, backfill tests, sweep docs, and catch regressions — with the workflow YAML and hard-earned lessons on cost, quotas, and idempotency.

FA
Fatima A. August 20, 2026 · 13 min read

Once your team is using Claude Code interactively, the natural next question is: what if we ran it in CI? Some workflows that are annoying to remember (docs sweeps, coverage backfills, dependency reviews) become interesting when they run themselves once a week. Some workflows that are impossible to remember (spec-conformance checks across 40 microservices) become tractable at all.

This post walks through the eight GitHub Actions patterns we run in production, with the workflow YAML and the parts that took real experimentation to get right. Each pattern is independent — you can adopt any of them without the others.

Before you start

You'll need a Claude API key stored as a repo secret, Node available in your runners, and enough context on your workflows to know what would be genuinely helpful to automate. Adding Claude to CI amplifies things — both good judgment and bad. Start small and measure.

Pattern 1: PR review on demand

The simplest useful pattern. When a PR gets a specific label (like needs-claude-review), a workflow runs Claude Code to review the diff and post comments. It doesn't replace human review — it front-loads the mechanical parts (missing null checks, inconsistent naming, obvious optimization opportunities) so the human reviewer can focus on architecture and intent.

yaml
name: Claude review
on:
  pull_request:
    types: [labeled]

jobs:
  claude-review:
    if: github.event.label.name == 'needs-claude-review'
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
      contents: read
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-node@v4
      - run: npx cctk@latest init --ci
      - run: |
          claude-code exec pr-review \
            --pr ${{ github.event.pull_request.number }} \
            --repo ${{ github.repository }}
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The label trigger is important — it gives reviewers a way to say "yes, run Claude on this" without it happening on every PR. On our repo, about 20% of PRs get the label. The rest get faster human review because the comment queue isn't clogged with automated feedback.

Pattern 2: Weekly docs sweep

A cron-triggered workflow that checks README, API docs, and inline JSDoc against actual code, then opens a PR with any drift. Runs at 3am Sunday so the PR is ready to review Monday morning.

yaml
name: Docs sweep
on:
  schedule:
    - cron: '0 3 * * 0'
  workflow_dispatch:

jobs:
  sweep:
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npx cctk@latest init --ci
      - run: claude-code exec docs-agent --scope=all
      - name: Create PR
        uses: peter-evans/create-pull-request@v6
        with:
          title: 'chore: weekly docs sweep'
          branch: docs-sweep-${{ github.run_number }}
          body: 'Auto-generated by Claude docs-agent'
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
The docs sweep is the single highest-ROI automation we've added. It surfaces things nobody would notice otherwise — a README claiming Node 18+ when the code needs Node 20, an example that no longer runs, an env var we renamed six months ago.

Pattern 3: Test coverage backfill for changed files

Not a full coverage sweep — that would generate churn. Instead: on merge to main, look at what files were touched, and for any file whose coverage dropped below a threshold, open a PR with proposed unit tests.

This one took the most tuning. Early versions opened way too many PRs. Now it uses two filters: (1) only if coverage dropped below 60% for the file, and (2) only for files matching src/**/*.ts (skips generated code, tests, tooling). Result: 1-3 test PRs a week, all high-signal.

Pattern 4: Regression checks after dependency updates

When Dependabot opens a PR bumping a dependency, a workflow runs Claude to inspect the changelog of the dependency, cross-reference with our codebase, and flag potentially-breaking changes.

Real example

When we upgraded from Prisma 5 to 6, Claude caught two call sites that used a query method whose semantics changed. Not "breaking" in the sense of throwing an error — subtly different behavior. Human review probably would have caught them; automated review definitely did.

Pattern 5: Spec conformance across microservices

Our team runs 40+ microservices. All of them are supposed to follow a set of internal standards (health check endpoint at /healthz, structured JSON logging, specific error format, prom metrics on /metrics). Historically, we discovered violations when something broke.

Now a weekly workflow scans all repos and produces a compliance report. Not a PR — a Slack message with a table: which services are conformant, which are drifted, which are new since last week. Human decides what to do about each; the automation just catches the drift.

Pattern 6: Automatic changelog from merged PRs

On merge to main, a workflow reads the PR description, categorizes the change (feat/fix/chore/docs), and appends to CHANGELOG.md with a human-readable summary. Simple pattern, big quality-of-life improvement.

yaml
name: Changelog
on:
  pull_request:
    types: [closed]
    branches: [main]

jobs:
  changelog:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
      - run: npx cctk@latest init --ci
      - run: |
          claude-code exec changelog-append \
            --pr ${{ github.event.pull_request.number }}
      - run: |
          git config user.name "claude-bot"
          git config user.email "bot@example.com"
          git add CHANGELOG.md
          git commit -m "chore: update changelog" || echo "nothing to commit"
          git push
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

Pattern 7: The "explain this build failure" comment

When CI fails on a PR, a workflow parses the failed job logs, sends them to Claude with the diff, and posts an explanation as a PR comment. Not a fix — an explanation. "This test failed because you changed the return type of getUser() but the test still expects the old shape." Saves a lot of "what does this stack trace mean?" cycles.

The trick is being disciplined about when it runs. Every failure would be too noisy. We trigger it only on explicit reviewer request via a slash command in a PR comment (/explain-failure), which is handled by a webhook workflow.

Pattern 8: Weekly incident retrospective assist

For any incident that had a postmortem, a weekly workflow runs across the last week's incidents, pulls the resolution PRs, and drafts a "themes and patterns" summary. Sent to the tech lead as a starting point for the weekly ops review — not a substitute for the review itself.

Costs, quotas, and idempotency

Three lessons from actually running these:

1. Cost is not always what you'd guess

The docs sweep is our most expensive workflow — not because it runs often but because it processes a lot of tokens each run. The PR review is cheaper per run but runs 20-50x more often. Model the monthly cost of each workflow separately; the totals shift what you'd prioritize.

2. Quotas need explicit handling

If you hit the API rate limit in the middle of a workflow, the job silently fails or produces partial output. Explicit retry-with-backoff in the CI wrapper is essential; failing hard is better than half-doing the work. Log every failed call for later review.

3. Idempotency saves your Sunday

A workflow that opens a fresh PR every run will fill your queue. Design each workflow to either update its existing PR (by branch name) or skip if one exists. The docs sweep opens PR docs-sweep-{week-number}; if that PR is still open, subsequent runs update it rather than creating new ones.

One thing to avoid

Don't chain workflows that call Claude off each other's output without human review in between. A workflow that opens a PR is fine. A workflow that opens a PR and then triggers another workflow that merges it based on Claude's judgment is a way to have a very bad Monday.

Where this goes

The pattern that will probably matter most over the next year isn't any of these individually — it's that CI becomes a natural place for agentic workflows that don't need to be interactive. The interactive Claude Code session in your terminal is high-bandwidth but expensive to sit through; the CI-triggered one runs at 3am and posts you a summary.

Every team's eight patterns will differ. But the pattern of noticing what repeatable work happens on your team, and asking "could a workflow do that overnight?" — that's where the big compounding wins live. Start with one. See how it changes what your team pays attention to. Add another.

FA

Written by

Fatima A.

Fatima covers developer experience, tooling architecture, and how MCP-native workflows change day-to-day dev.

Get cctk running in one command

85 slash commands, 12 subagents, 12 MCP integrations, 12 hooks. All the patterns from this post are shipped in cctk.

npx cctk@latest init Get cctk v1.5.2 →