C.W.K.
Stream
Lesson 13 of 13 · published

Automation, CI/CD & Headless Patterns

~22 min · automation, ci-cd, headless, github-actions, scripting

Level 0🌱 Novice
0 XP0/70 lessons0/11 achievements
0/120 XP to next level120 XP to go0% complete

From your terminal to your pipelines

Once Claude Code can run via -p with --allowedTools and --output-format json, it stops being a human-only tool and becomes a pipeline primitive. The same model that helps you write code now reviews PRs in CI, generates release notes nightly, and triages errors before a human reads them.

The patterns: TDD loops (ask for failing tests first, then implement, then refactor — Claude excels at red/green/refactor), diff review (git diff main...HEAD | claude -p in a CI step), JSON for downstream (parse Claude's structured output with jq, gate the pipeline on findings), least-privilege automation (--allowedTools gives Claude exactly what the job needs and nothing else).

Anthropic ships an official GitHub Action — anthropics/claude-code-action@v1 — for the common case (@claude mentions in PRs trigger an agent run). For everything else, you orchestrate the same primitives yourself.

Code

Headless review in shell·bash
#!/bin/bash
# scripts/ai-review.sh
set -euo pipefail

DIFF=$(git diff origin/main...HEAD)
[ -z "$DIFF" ] && { echo "no changes"; exit 0; }

REVIEW=$(echo "$DIFF" | claude -p \
  "Review this diff. Format: [SEVERITY: HIGH|MEDIUM|LOW] desc (file:line)" \
  --output-format text \
  --allowedTools "Read,Bash(git log *)")

echo "$REVIEW" > "review-$(date +%Y%m%d-%H%M%S).md"
echo "$REVIEW"

# Gate the pipeline
if echo "$REVIEW" | grep -q "SEVERITY: HIGH"; then
  echo "high-severity findings, blocking"
  exit 1
fi
GitHub Actions PR review·yaml
# .github/workflows/claude-review.yml
name: Claude PR Review
on:
  pull_request:
    types: [opened, synchronize]

permissions:
  contents: read
  pull-requests: write

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }

      - uses: actions/setup-node@v4
        with: { node-version: '22' }

      - run: npm install -g @anthropic-ai/claude-code

      - name: Run Claude review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
        run: |
          git diff origin/main...HEAD | claude -p \
            "Review for bugs, security, missing tests. Markdown output." \
            --output-format text \
            --allowedTools "Read,Bash(git log *),Bash(git show *)" \
            > review.md

      - uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const review = fs.readFileSync('review.md', 'utf8');
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: '## Claude Code Review\n\n' + review
            });

External links

Exercise

Wire a real Claude review step into one of your repos — either a shell script you run locally before pushing, or a GitHub Action on PRs. Use --allowedTools to grant minimum privilege. Test it on a real PR. Capture the comment it posts.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.