hippo: Picture this—you mention @claude in a GitLab issue, and it analyzes the requirements, writes the code, and opens a merge request. That is not science fiction; it is what GitLab CI/CD + Claude Code ships out of the box.


1. What Is Claude Code for GitLab CI/CD?

Claude Code integrates directly into GitLab CI/CD so you can drive AI coding tasks with @claude mentions. The workflow is straightforward: mention @claude with your request in an issue or merge request → GitLab triggers a CI job → Claude Code inspects the repository and applies changes inside an isolated container → it opens an MR with the results.

Core capabilities at a glance:

Capability Description
Instant MR creation Describe the requirements and Claude generates a complete merge request
Automated implementation Turn an issue into working code with a single mention
Project-aware Reads your repository’s CLAUDE.md and follows existing coding conventions
Enterprise-ready Choose from three cloud backends to satisfy data residency requirements
Secure by default Runs inside an isolated container; every change goes through MR review

2. Official Docs Breakdown

2.1 How It Works: Three Core Mechanisms

Understanding how Claude Code runs inside GitLab CI comes down to three mechanisms:

Event-driven orchestration — GitLab listens for your configured triggers (manual runs, MR events, webhooks). When it detects an @claude mention, the job pulls thread comments and context, fetches the repository code, and builds a structured prompt for Claude.

Provider abstraction — Claude Code supports three AI backends:

Provider Authentication Best For
Claude API (SaaS) API Key Quick start, individuals, and small teams
AWS Bedrock IAM + OIDC (keyless authentication without static secrets) AWS environments and data residency compliance
Google Vertex AI Workload Identity Federation (GCP-native keyless auth) GCP environments and enterprise compliance

Sandboxed execution — Every run executes inside a restricted container. Claude Code enforces workspace-scoped write permissions, and no change reaches the main branch without passing through standard MR review.

2.2 Quickstart: Up and Running in 5 Minutes

Step 1: Add a CI/CD variable to your GitLab project. Go to Settings → CI/CD → Variables, add ANTHROPIC_API_KEY, and check both Mask variable and Protected.

Step 2: Add the following job to .gitlab-ci.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
stages:
- ai

claude:
stage: ai
image: node:24-alpine3.21
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
variables:
GIT_STRATEGY: fetch
before_script:
- apk update
- apk add --no-cache git curl bash
- curl -fsSL https://claude.ai/install.sh | bash
script:
- /bin/gitlab-mcp-server || true
- echo "$AI_FLOW_INPUT for $AI_FLOW_CONTEXT on $AI_FLOW_EVENT"
- >
claude
-p "${AI_FLOW_INPUT:-'Review this MR and implement the requested changes'}"
--permission-mode acceptEdits
--allowedTools "Bash Read Edit Write mcp__gitlab"
--debug

Key flags and variables to understand:

Parameter / Variable Description
-p Inline prompt; AI_FLOW_INPUT injects the user’s request via webhook/API
--permission-mode acceptEdits Lets Claude edit files automatically without interactive confirmation
--allowedTools Tool allowlist; mcp__gitlab grants Claude access to the GitLab API
--debug Emits verbose logs—essential for troubleshooting
AI_FLOW_INPUT User instruction text passed in by the webhook
AI_FLOW_CONTEXT Trigger context (issue/MR ID, etc.)
AI_FLOW_EVENT Event type

/bin/gitlab-mcp-server is GitLab’s MCP (Model Context Protocol) server, which gives Claude the ability to interact with the GitLab API—posting comments and opening MRs both rely on it. Appending || true ensures the rest of the script still runs even if the MCP server fails to start.

2.3 Enterprise Deployment: AWS Bedrock and Google Vertex AI

Enterprises can run Claude Code entirely within their own cloud infrastructure so data never transits Anthropic’s SaaS. Both options share one critical property: no static keys—short-lived credentials are minted via OIDC trust chains.

AWS Bedrock works as follows: the GitLab CI job provides a JWT (CI_JOB_JWT_V2) → the job exchanges that token with AWS STS for temporary credentials → Claude Code calls the Bedrock API using those credentials. Configure two CI/CD variables in GitLab: AWS_ROLE_TO_ASSUME (the IAM role ARN) and AWS_REGION (for example, us-west-2).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
claude-bedrock:
stage: ai
image: node:24-alpine3.21
rules:
- if: '$CI_PIPELINE_SOURCE == "web"'
before_script:
- apk add --no-cache bash curl jq git python3 py3-pip
- pip install --no-cache-dir awscli
- curl -fsSL https://claude.ai/install.sh | bash
# Exchange GitLab OIDC token for temporary AWS credentials
- export AWS_WEB_IDENTITY_TOKEN_FILE="${CI_JOB_JWT_FILE:-/tmp/oidc_token}"
- if [ -n "${CI_JOB_JWT_V2}" ]; then printf "%s" "$CI_JOB_JWT_V2" > "$AWS_WEB_IDENTITY_TOKEN_FILE"; fi
- >
aws sts assume-role-with-web-identity
--role-arn "$AWS_ROLE_TO_ASSUME"
--role-session-name "gitlab-claude-$(date +%s)"
--web-identity-token "file://$AWS_WEB_IDENTITY_TOKEN_FILE"
--duration-seconds 3600 > /tmp/aws_creds.json
- export AWS_ACCESS_KEY_ID="$(jq -r .Credentials.AccessKeyId /tmp/aws_creds.json)"
- export AWS_SECRET_ACCESS_KEY="$(jq -r .Credentials.SecretAccessKey /tmp/aws_creds.json)"
- export AWS_SESSION_TOKEN="$(jq -r .Credentials.SessionToken /tmp/aws_creds.json)"
script:
- /bin/gitlab-mcp-server || true
- >
claude
-p "${AI_FLOW_INPUT:-'Implement the requested changes and open an MR'}"
--permission-mode acceptEdits
--allowedTools "Bash Read Edit Write mcp__gitlab"
--debug
variables:
AWS_REGION: "us-west-2"

Google Vertex AI uses Workload Identity Federation (WIF) for the same keyless authentication pattern. Configure a WIF provider in GCP to trust GitLab OIDC, then obtain access tokens through service account impersonation. Configure three CI/CD variables in GitLab: GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT, and CLOUD_ML_REGION.

CI/CD variable comparison across all three backends:

Variable Claude API AWS Bedrock Vertex AI
Auth variable ANTHROPIC_API_KEY AWS_ROLE_TO_ASSUME GCP_WORKLOAD_IDENTITY_PROVIDER
Region variable — AWS_REGION CLOUD_ML_REGION
Additional variable — — GCP_SERVICE_ACCOUNT
Masking required Yes (API Key) No (OIDC) No (WIF)

3. Common Use Cases & Advanced Configuration

3.1 Three Common Use Cases

Issue to MR — in an issue comment:

1
@claude implement this feature based on the issue description

Claude analyzes the issue and codebase, writes the changes on a branch, and opens an MR for review.

MR discussion assistance — in an MR thread:

1
@claude suggest a concrete approach to cache the results of this API call

Claude proposes a design, implements the code, and updates the MR.

Rapid bug fixes — in an issue or MR comment:

1
@claude fix the TypeError in the user dashboard component

Claude locates the root cause, applies the fix, and updates the branch or opens a new MR.

3.2 Customizing Behavior & Controlling Performance

CLAUDE.md is your highest-leverage investment. Place a CLAUDE.md file in the repository root documenting your coding standards, project conventions, and security requirements; Claude reads and follows it automatically on every run.

You have two ways to pass custom prompts: -p for short inline instructions, and --prompt-file for longer instructions stored in a file (such as a security review checklist). For teams managing spend, the essential guardrails are --max-turns (caps agent iteration cycles) and --timeout-minutes (caps total runtime):

1
2
3
4
5
6
7
8
9
10
11
claude:
stage: ai
timeout: 30m
script:
- >
claude
-p "${AI_FLOW_INPUT:-'Implement the requested changes'}"
--permission-mode acceptEdits
--max-turns 10
--timeout-minutes 20
--allowedTools "Bash Read Edit Write mcp__gitlab"

Common flags and variables reference:

Parameter / Variable Description
-p Inline prompt text
--prompt-file Read prompt instructions from a file
--max-turns Cap Claude’s internal iteration count (cost control)
--timeout-minutes Hard limit on total execution time
GIT_STRATEGY Git checkout strategy; fetch (incremental) is recommended
GITLAB_ACCESS_TOKEN Optional project access token (api scope) overriding CI_JOB_TOKEN

4. Field Notes from hippo

hippo: Here are the pitfalls I hit in real-world usage and the practices that paid off.

4.1 Pitfalls Encountered

@claude does not respond — The three most common culprits: the pipeline never triggered at all (verify that CI_PIPELINE_SOURCE in rules matches your event), the API key variable is missing or misconfigured (Mask and Protected do not conflict, but confirm the variable is actually available to the branch/job), or you typed /claude instead of @claude (/ invokes a slash command; @ triggers a mention).

Job cannot post comments or open MRs — CI_JOB_TOKEN often lacks sufficient default permissions. If Claude executes cleanly but cannot write back to GitLab, check two things: confirm mcp__gitlab is included in --allowedTools, and check whether you need to supply GITLAB_ACCESS_TOKEN instead of relying on the default job token.

OIDC authentication errors — In AWS Bedrock’s OIDC trust policy, a wrong project_path (for instance, omitting the group prefix) causes AssumeRoleWithWebIdentity to fail with a generic "not authorized" error. Inspect the actual sub claim in AWS CloudTrail first, then align your trust policy to match it verbatim.

4.2 Practical Recommendations

Validate the pipeline with Claude API first, then migrate to an enterprise backend. API key setup has the fewest moving parts. Get the full @claude mention → CI execution → MR creation loop working end to end before configuring OIDC for Bedrock or Vertex AI. Otherwise, when something breaks, you will waste time guessing whether the fault is in Claude Code or in your OIDC trust chain.

CLAUDE.md delivers the highest ROI. Rather than endlessly tuning CLI flags, write down your coding standards, test expectations, and forbidden operations clearly. A solid CLAUDE.md lifts Claude’s output from “barely compiles” to “nearly ready to merge.”

Always review MRs manually. Code that passes CI is not guaranteed to be right. Inspect database queries, permission checks, and concurrency logic line by line. Treat Claude like a capable intern who still makes occasional rookie mistakes.


5. Security & Cost

Four security principles: never commit secrets to the repository (use CI/CD variables), prefer OIDC over long-lived credentials, bound job execution (set timeouts and concurrency limits), and review Claude’s MRs with the same rigor as human contributors.

Cost has two components: GitLab Runner compute minutes and AI API token usage. Practical ways to keep costs predictable:

Lever Description
--max-turns Caps iteration loops to prevent runaway jobs
--timeout-minutes Hard wall-clock execution limit
Specific @claude instructions Cuts wasted turns caused by ambiguous prompts
Split large tasks into smaller issues Smaller scope yields more predictable token consumption

Reference token usage by task type:

Scenario Estimated Token Usage Notes
Simple code review 5,000 - 15,000 Reads a handful of files and posts review comments
Bug fix 10,000 - 30,000 Root-cause diagnosis plus patch generation
Feature implementation 30,000 - 100,000+ Scales with codebase size and scope

6. Summary

GitLab CI/CD + Claude Code = mention @claude in an issue, and the AI analyzes, codes, and opens an MR automatically. You get three cloud backends to choose from, keyless OIDC authentication, and mandatory MR review. Get the basic loop running first, invest in a clear CLAUDE.md, and expand from there.


Series Navigation


Based on the official Claude Code GitLab CI/CD documentation.

Last updated: 2026-03-31