Production Workflows & Automation
Learning Outcomes
- Run Claude in non-interactive (headless) mode for automation
- Integrate Claude Code into CI/CD pipelines
- Automate code review and quality checks
- Build batch processing workflows
- Design team workflows around Claude Code
Lesson Plan
| Segment | Duration | Topic |
|---|---|---|
| Intro | 3 min | From interactive to automated |
| Explain | 8 min | Headless mode and scripting |
| Demo | 12 min | CI/CD integration |
| Demo | 12 min | Automated code review |
| Demo | 10 min | Batch operations |
| Explain | 10 min | Team workflow design |
| Wrap-up | 5 min | Course summary |
Before You Begin
Pre-work:
- Complete Lesson 9
- Familiarity with CI/CD concepts (GitHub Actions, etc.)
- Access to a repository with CI configured (or willingness to set one up)
Shopping List:
- Claude Code installed
- A project with a CI/CD pipeline (or use GitHub Actions)
- Anthropic API key (for headless/automated use)
- Basic shell scripting knowledge
For automation, Claude runs in headless mode — no interactive prompts, no approval dialogs:
claude --headless -p "Analyse the codebase and list all TODO comments"
Key flags for scripting:
# Run a single prompt, output the result
claude -p "prompt" --output-format text
# Print only the result (no formatting)
claude -p "prompt" --output-format json
# Allow all operations without asking
claude -p "prompt" --dangerously-skip-permissions
Piping input:
git diff HEAD~1 | claude -p "Review this diff for bugs"
Reading files and analysing:
claude -p "Read src/api/ and list all endpoints with their HTTP methods"
Important: Headless mode is designed for automation where you've pre-verified what Claude will do. Don't use --dangerously-skip-permissions unless you understand exactly what operations will run.
Claude can be part of your CI pipeline for automated tasks:
Pattern 1: PR Description Generation
# .github/workflows/pr-description.yml
name: Generate PR Description
on:
pull_request:
types: [opened]
jobs:
describe:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- run: npm install -g @anthropic-ai/claude-code
- run: |
DIFF=$(git diff origin/main...HEAD)
claude -p "Write a PR description for these changes: $DIFF" \
--output-format text > description.md
env:
ANTHROPIC_API_KEY: $
Pattern 2: Automated Code Review
name: AI Code Review
on: [pull_request]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: |
claude -p "Review this diff for bugs, security issues,
and style violations. Format as GitHub review comments." \
--output-format json
Pattern 3: Changelog Generation
# Generate changelog from commits since last release
git log v1.2.0..HEAD --oneline | \
claude -p "Generate a user-facing changelog grouped by: Features, Bug Fixes, Breaking Changes"
Set up Claude as an automated reviewer for every PR:
Basic review script:
#!/bin/bash
# scripts/ai-review.sh
DIFF=$(git diff origin/main...HEAD)
REVIEW=$(claude -p "Review this code diff for:
1. Potential bugs or logic errors
2. Security vulnerabilities
3. Missing error handling
4. Performance concerns
Be specific — reference file names and line numbers.
Only report real issues, not style preferences.
Diff:
$DIFF" --output-format text)
echo "$REVIEW"
Focused reviews by area:
# Security-focused review
claude -p "Review for OWASP top 10 vulnerabilities: $(git diff main -- '*.ts')"
# Performance review
claude -p "Review for N+1 queries, missing indexes, or expensive operations: $(git diff main -- 'src/api/')"
# API consistency review
claude -p "Check that all new API endpoints follow our response format ({ data, error, meta }): $(git diff main -- 'src/routes/')"
Integration with GitHub: Post review comments directly to the PR:
COMMENTS=$(claude -p "..." --output-format json)
gh pr review --comment --body "$COMMENTS"
Process multiple files or tasks in a scripted batch:
Example: Add JSDoc to all exported functions:
#!/bin/bash
for file in src/utils/*.ts; do
claude -p "Add JSDoc comments to all exported functions in $file.
Include @param and @returns. Don't modify the logic." \
--dangerously-skip-permissions
done
Example: Generate tests for untested files:
#!/bin/bash
# Find files without test coverage
for file in $(find src -name "*.ts" -not -name "*.test.*"); do
TEST_FILE="${file%.ts}.test.ts"
if [ ! -f "$TEST_FILE" ]; then
claude -p "Generate unit tests for $file. Save to $TEST_FILE.
Use vitest. Cover main paths and edge cases." \
--dangerously-skip-permissions
fi
done
Example: Migration script:
#!/bin/bash
# Migrate all fetch() calls to use new httpClient
FILES=$(grep -rl "fetch(" src/ --include="*.ts")
for file in $FILES; do
claude -p "In $file, replace all fetch() calls with our httpClient
from src/lib/http. The httpClient has the same interface but adds
auth headers automatically." --dangerously-skip-permissions
done
Putting it all together for a team:
The standard team workflow with Claude:
Developer writes code (with Claude assistance)
↓
Developer runs local AI review (scripts/ai-review.sh)
↓
Push branch, create PR
↓
CI runs automated AI review (comments on PR)
↓
Human reviewer reviews (focusing on design/intent)
↓
Claude generates PR description and changelog
↓
Merge → Claude generates release notes
Team configuration checklist:
- [ ] Shared CLAUDE.md in the repository
- [ ] .claude/settings.json with team permissions
- [ ] Custom slash commands for common tasks
- [ ] CI workflow for automated review
- [ ] PR template that integrates with AI-generated descriptions
- [ ] Onboarding doc for new team members
Measuring value:
- Track: time to merge, defect rate, developer satisfaction
- Compare: before and after AI integration
- Iterate: adjust CLAUDE.md, review focus, automation scope
Over 10 lessons, you've gone from first conversation to production automation:
| Lesson | Skill Level |
|---|---|
| 1. First Conversation | Can talk to Claude |
| 2. CLAUDE.md | Claude knows your project |
| 3. File Operations | Claude creates and edits |
| 4. Multi-File | Claude works across your codebase |
| 5. Debugging | Claude helps find and fix bugs |
| 6. Git Integration | Claude manages your source control |
| 7. MCP Servers | Claude connects to external tools |
| 8. Advanced Prompting | Claude handles complex tasks reliably |
| 9. Large Projects | Claude scales to big codebases |
| 10. Automation | Claude runs unattended |
What's next:
- Build custom slash commands for your specific workflow
- Explore more MCP servers for your tools
- Check out the supplemental materials (Rules, Cheat Sheet, Prompt Patterns)
- Contribute to your team's CLAUDE.md
- Keep Claude Code updated — new features ship regularly
Questions & Answers
Key Takeaways
- Headless mode enables scripting and CI integration
- Start read-only — review and analyse before auto-modify
- Batch operations handle repetitive tasks across many files
- Team workflows combine Claude at multiple stages (write, review, describe, release)
- Measure value — track time-to-merge and defect rates
- You've completed Learn Claude! — check out supplemental materials next
Continue learning:
- Rules — best practices for Claude rules files
- Cheat Sheet — quick reference for all commands
- Prompt Patterns — reusable prompt templates