Claude Code GitLab CI/CD Workflow
Set up Claude Code in GitLab CI/CD with masked ANTHROPIC_API_KEY variables, npm-based CLI install, claude -p jobs, and Bedrock or Vertex OIDC alternatives from official GitLab integration docs.
Open the source and read safety notes before installing.
Safety notes
- CI jobs run claude with --permission-mode acceptEdits in official examples—scope repositories and tools narrowly.
- Never commit API keys; store ANTHROPIC_API_KEY as a masked CI/CD variable.
- GitLab MCP write tools can open MRs and post comments as the job identity.
Privacy notes
- Issue titles, MR diffs, and AI_FLOW variables enter model context during jobs.
- CI logs may retain prompts—align retention with corporate policy.
Prerequisites
- GitLab project with CI/CD variables permission and a protected default branch policy.
- Anthropic API key or approved Bedrock or Vertex provider configuration.
- Human review before merging Claude-opened merge requests.
Schema details
- Install type
- copy
- Reading time
- 9 min
- Difficulty score
- 55
- Troubleshooting
- Yes
- Breaking changes
- No
Full copyable content
Add masked ANTHROPIC_API_KEY, install Claude Code with npm in a CI job, run claude -p with scoped --allowedTools, and review MR output before merge.About this resource
TL;DR
Official GitLab CI/CD documentation describes running Claude Code in isolated
GitLab jobs with masked ANTHROPIC_API_KEY, repository cloning, and
claude -p automation. This guide follows those steps using an
npm-based CLI install instead of remote install scripts.
Prerequisites & Requirements
- {"task": "Masked secret", "description": "ANTHROPIC_API_KEY stored under Settings → CI/CD → Variables"}
- {"task": "Job scope", "description": "rules limit when the Claude job runs (web, merge_request_event, or mention triggers)"}
- {"task": "Review gate", "description": "Maintainers review Claude MRs like any contributor"}
- {"task": "CLAUDE.md", "description": "Repository standards file guides automated changes"}
Step-by-Step Setup
- Add
ANTHROPIC_API_KEYas a masked (and protected if needed) CI/CD variable. - Add a
claudestage job using a Node image; install Git and the CLI withnpm install -g @anthropic-ai/claude-code. - Set
GIT_STRATEGY: fetchso the job clones the target repository. - Run
claude -pwith an explicit prompt and--allowedToolsscoped to read and write needs (official examples includemcp__gitlabwhen GitLab MCP is enabled). - Optionally enable
/bin/gitlab-mcp-serverwhen your runner image provides it. - For Amazon Bedrock or Google Vertex AI, follow the OIDC or Workload Identity Federation sections in the official doc instead of
ANTHROPIC_API_KEY.
Example job shape (npm install)
stages:
- ai
claude:
stage: ai
image: node:24-alpine
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
variables:
GIT_STRATEGY: fetch
before_script:
- apk add --no-cache git
- npm install -g @anthropic-ai/claude-code
script:
- >
claude -p "${AI_FLOW_INPUT:-'Review this MR and implement requested changes'}"
--permission-mode acceptEdits
--allowedTools "Bash Read Edit Write"
Adjust --allowedTools to least privilege. Official docs also document Bedrock and Vertex job templates with cloud OIDC.
Source Verification Notes
Verified against Claude Code GitLab CI/CD documentation on 2026-06-16:
- Integration is maintained by GitLab and runs Claude Code in isolated CI jobs.
- Quick setup requires
ANTHROPIC_API_KEYas a masked CI/CD variable. - Jobs can react to web triggers, merge request events, or mention-driven flows with
AI_FLOW_*variables. - Official examples use
claude -p,--permission-mode acceptEdits, and scoped--allowedTools. - Enterprise setups document Bedrock OIDC and Vertex Workload Identity Federation alternatives.
Duplicate Check
Distinct from claude-code-github-actions-review-workflow (GitHub Actions) and
claude-code-gitlab-ci-agent-capability-pack (skills review matrix). This
guide covers GitLab CI job setup from the official GitLab integration doc.
Troubleshooting
Issue: Job cannot comment or open MRs
Fix: Confirm GitLab token permissions and include mcp__gitlab in --allowedTools when using GitLab MCP per official troubleshooting.
Issue: Authentication errors
Fix: Validate ANTHROPIC_API_KEY or cloud OIDC/WIF variables per provider section in the official doc.
Source citations
Add this badge to your README
Show that Claude Code GitLab CI/CD Workflow is listed on HeyClaude. Paste this Markdown into your README — it renders the badge and links back to this page.
[](https://heyclau.de/entry/guides/claude-code-gitlab-ci-cd-workflow)How it compares
Claude Code GitLab CI/CD Workflow side by side with 3 alternatives on trust, install, platform support, and disclosed safety notes — all from reviewed registry metadata.
| Field | Claude Code GitLab CI/CD Workflow Set up Claude Code in GitLab CI/CD with masked ANTHROPIC_API_KEY variables, npm-based CLI install, claude -p jobs, and Bedrock or Vertex OIDC alternatives from official GitLab integration docs. Open dossier | Claude Code GitHub Actions Review Workflow Set up Claude Code GitHub Actions for pull request review: install the Claude GitHub app, store ANTHROPIC_API_KEY in secrets, use anthropics/claude-code-action@v1 with prompt-based automation, and follow documented security practices. Open dossier | Fix Claude Code Environment Variable Configuration Errors Set Claude Code environment variables correctly and debug auth, model, and config issues using only documented variables and the /doctor diagnostics. Open dossier | Secret Handling For MCP Servers And Agent Tools A practical guide for handling secrets when connecting MCP servers and authoring Agent SDK tools in Claude Code: env expansion in .mcp.json, OAuth scope pins, keychain storage, local scope, and redaction before tool arguments reach the model. Open dossier |
|---|---|---|---|---|
| Trust | ||||
| Install risk | Review first | Review first | Review first | Review first |
| Notes | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ | Safety ✓ Privacy ✓ |
| Category | guides | guides | guides | guides |
| Source | source-backed | source-backed | source-backed | source-backed |
| Author | kiannidev | kiannidev | JSONbored | kiannidev |
| Added | 2026-06-16 | 2026-06-16 | 2025-10-27 | 2026-06-16 |
| Platforms | Claude Code | Claude Code | Claude Code | Claude Code |
| Source repo | — | — | — | — |
| Safety notes | ✓CI jobs run claude with --permission-mode acceptEdits in official examples—scope repositories and tools narrowly. Never commit API keys; store ANTHROPIC_API_KEY as a masked CI/CD variable. GitLab MCP write tools can open MRs and post comments as the job identity. | ✓The Claude GitHub app requests Contents, Issues, and Pull requests read and write permissions—scope installation to intended repositories. Never commit API keys; use GitHub encrypted secrets such as ANTHROPIC_API_KEY. Review Claude suggestions before merging; automation should not bypass CODEOWNERS. Workflows consume GitHub Actions minutes and Claude API tokens—set timeouts and max-turn limits. | ✓ANTHROPIC_API_KEY overrides any active subscription and apiKeyHelper runs a shell script whose output becomes auth headers; treat both as credential-bearing configuration. | ✓Stdio MCP servers inherit environment variables you pass via --env or .mcp.json env blocks; treat that as handing the server your credentials. HTTP MCP headers and OAuth tokens authenticate outbound calls; a compromised server or overly broad scope can exfiltrate data through tool results. Agent SDK tool descriptions, inputs, and outputs enter model context each turn—never embed live secrets in schemas or sample responses. Project-scoped .mcp.json is designed for version control; use ${VAR} expansion and local scope for machine-specific secrets instead of committing raw keys. |
| Privacy notes | ✓Issue titles, MR diffs, and AI_FLOW variables enter model context during jobs. CI logs may retain prompts—align retention with corporate policy. | ✓PR diffs and issue comments are sent to the model provider during workflow runs. Logs may retain prompts—align retention with corporate data handling rules. Use repository secrets rather than echoing credentials in workflow YAML. | ✓API keys set via environment variables or settings.json are credentials; avoid committing settings files that contain them and prefer apiKeyHelper for rotating secrets. | ✓MCP tool arguments, resource contents, and error messages can contain API keys, JWTs, customer IDs, and internal URLs that flow into session transcripts. OAuth access tokens for remote MCP servers are stored in the macOS Keychain or a credentials file; revoke with Clear authentication in /mcp when offboarding. Agent SDK handlers that call external APIs may log request metadata; redact at the handler boundary before traces or support exports leave your environment. Shared .mcp.json templates should name required variables (for example API_KEY) without example values that look like real credentials. |
| Prerequisites |
|
| — none listed |
|
| Install | — | — | — | — |
| Config | — | — | — | — |
| Citations | ||||
| Claim | Unclaimed | Unclaimed | Unclaimed | Unclaimed |
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.