Exam Scenarios/Practice Scenarios
Advanced15 min

Scenario: Claude Code for Continuous Integration

Build a CI/CD pipeline that uses Claude Code for automated code review, test generation, and deployment validation. Covers headless mode, Batch API selection, multi-file review strategies, and structured output.

Quick Reference

  • Use -p (print/pipe) flag for non-interactive CI environments — prevents stdin hangs
  • Batch API is for latency-tolerant tasks (overnight reports) not time-sensitive tasks (pre-merge checks)
  • Multi-file PR review: per-file analysis pass + integration pass catches both local and cross-file issues
  • --output-format json with --json-schema produces structured, parseable review output
  • Idempotent review design (hash-based dedup) prevents duplicate comments on re-runs

Scenario Description

You are integrating Claude Code into your team's CI/CD pipeline. The pipeline runs on GitHub Actions and handles two workflows: (1) pre-merge code review — triggered on every pull request, must complete within 5 minutes, and posts review comments directly on the PR; and (2) overnight code quality reports — runs at 2 AM on the main branch, produces a comprehensive report covering code quality trends, test coverage gaps, and architectural drift. The pre-merge review must be fast, actionable, and have a low false-positive rate. The overnight report can take longer but must be thorough.

Your implementation uses Claude Code in headless mode (non-interactive) within Docker containers. Key challenges include: running Claude Code without a terminal (stdin), choosing the right API mode for each workflow (standard vs. Batch API), handling large pull requests with many files, producing structured output that integrates with existing review tools, and ensuring reviews are idempotent when the pipeline re-runs on the same PR.