CI/CD Pipeline Integration
Integrating Claude Code into CI/CD pipelines with the -p flag for non-interactive mode, structured JSON output for automation, CLAUDE.md as CI context, session isolation for self-review, and practical pipeline examples.
Quick Reference
- →Use -p (--print) flag for non-interactive mode -- essential for CI/CD where there is no terminal
- →Without -p, Claude Code hangs waiting for interactive input and your pipeline times out
- →--output-format json returns structured JSON instead of plain text for machine parsing
- →--json-schema enforces a specific response structure for consistent, parseable CI output
- →CLAUDE.md provides project context to CI-invoked Claude Code -- same rules as interactive use
- →Session context isolation: a separate Claude instance should review code, not the one that generated it
- →Pipe PR diffs into Claude for focused code review: git diff | claude -p 'Review this diff'
- →Include prior review findings in subsequent reviews to avoid duplicate comments
- →Use --allowedTools to restrict CI Claude to read-only operations for safety
- →Claude Code in CI is ideal for: PR review, security scanning, documentation generation, and test generation
Why Claude Code in CI/CD?
Claude Code is not just an interactive tool for developers at their terminals. With the right flags, it becomes a powerful CI/CD automation tool that can review pull requests, enforce coding standards, generate documentation, detect security issues, and more -- all as automated pipeline steps.
The key architectural insight is that CI/CD pipelines are non-interactive: there is no human at a terminal to approve tool use or answer questions. Claude Code's -p (print) mode solves this by running Claude as a single-shot command that takes input, processes it, and returns output -- exactly like any other CLI tool in your pipeline.
Without the -p flag, Claude Code starts in interactive mode and waits for user input from stdin. In a CI pipeline, there is no user. The pipeline will hang until it times out and fails. The -p flag is non-negotiable for any CI/CD usage.