Skip to content

CI/CD Integration

Claude Code runs anywhere a shell does — including GitHub Actions, GitLab CI/CD, and any script that can call a binary. This section covers how to automate Claude in pipelines: reviewing pull requests on every push, generating release notes from tags, and piping build artifacts through Claude for instant analysis.

The key mental model is simple: claude -p "prompt" is a Unix program. It reads stdin, writes stdout, and exits with a status code. Everything else is plumbing.

When to Use CI vs Local

Not every task belongs in a pipeline. The rule of thumb:

TriggerWhere to run Claude
Every PR openedCI — automated, consistent, no human required
Every merge to mainCI — release notes, changelog updates
Nightly codebase auditCI — scheduled cron job
Exploring an unfamiliar codebaseLocal — interactive, needs back-and-forth
Debugging a complex bugLocal — you need to ask follow-up questions
Writing a new featureLocal — iterative, context-heavy
Quick file analysis from a build artifactEither — `cat error.log

The dividing line is interactivity. CI runs are one-shot: you give Claude a prompt, it produces output, the job exits. Local runs are iterative: you refine the prompt, read the response, ask follow-ups.

If you find yourself wanting to reply to what Claude said in CI, run it locally instead.


Decision Table: Which Integration to Use

GitHub ActionsGitLab CI/CDHeadless (claude -p)
Best forGitHub repos, PR automationGitLab repos, MR automationAny script, any CI system
Setup complexityLow — official ActionMedium — manual .gitlab-ci.ymlMinimal — just install the CLI
Trigger on PR/MR commentsYes — @claude mentionsYes — @claude mentionsNo — pipeline events only
Output destinationPR comments, artifactsMR comments, artifactsstdout, files
Enterprise providersAWS Bedrock, Vertex AIAWS Bedrock, Vertex AIInherited from env
Cost visibilityGitHub + Anthropic billingGitLab + Anthropic billingAnthropic billing only

Use the GitHub/GitLab Action when you want Claude to respond to comments in PRs and MRs. Use headless mode directly when you want Claude as a step in a broader pipeline that just needs text output — linting, summarizing, extracting structured data.


How CI Automation Works

The trigger flow is the same regardless of platform:

graph TD A[git push / PR opened] --> B[Workflow triggered] B --> C[Runner installs claude CLI] C --> D[claude -p prompt] D --> E{Output format?} E -->|text| F[stdout → artifact / comment] E -->|json| G[JSON → parsed by script] E -->|stream-json| H[Real-time events → monitoring] F --> I[Job exits 0] G --> I H --> I style A fill:#1e293b,color:#7dd3fc,stroke:#334155 style B fill:#1e293b,color:#7dd3fc,stroke:#334155 style C fill:#1e293b,color:#7dd3fc,stroke:#334155 style D fill:#1e293b,color:#f59e0b,stroke:#334155 style E fill:#1e293b,color:#a78bfa,stroke:#334155 style F fill:#1e293b,color:#86efac,stroke:#334155 style G fill:#1e293b,color:#86efac,stroke:#334155 style H fill:#1e293b,color:#86efac,stroke:#334155 style I fill:#1e293b,color:#86efac,stroke:#334155

The only required ingredient is ANTHROPIC_API_KEY available as an environment variable. Everything else — install method, trigger type, output destination — is up to you.


Prerequisites (All Platforms)

Before any CI integration works, you need one thing:

ANTHROPIC_API_KEY — your Anthropic API key stored as a CI secret, never hardcoded.

  • GitHub: Settings → Secrets and variables → Actions → New repository secret
  • GitLab: Settings → CI/CD → Variables → Add variable (mask it)
  • Local scripts: export ANTHROPIC_API_KEY=... in your shell or .env

Without this, every claude -p call will fail with an authentication error.


Pages in This Section

PageWhat you’ll learn
GitHub ActionsUsing anthropics/claude-code-action@v1, @claude mentions in PRs, PR review and release notes templates
GitLab CI/CD.gitlab-ci.yml jobs, GitLab variable syntax, MR automation
Headless Modeclaude -p in depth — pipes, output formats, package.json scripts, --bare for fast CI runs

Start with Headless Mode if you want to understand the underlying primitive. Start with GitHub Actions or GitLab CI/CD if you want a working integration in 10 minutes.


  • Creator Workflows — Boris’s /loop and /schedule patterns for local automation
  • Common Workflows — Everyday prompt patterns that translate directly to CI prompts