Last updated: November 20, 2026
TL;DR
Claude Code runs on GitLab as a job you add to .gitlab-ci.yml. There is no app to install as there is on GitHub: you add one job and a masked ANTHROPIC_API_KEY variable, and Claude Code runs on your own runners, writes its changes to a branch and opens a merge request for review (Anthropic's GitLab CI/CD docs). The integration is in beta and is maintained by GitLab, not Anthropic. Setting it up takes four decisions:
- ๐ง Which job: the quick-setup job with an API key, or a production job on Amazon Bedrock or Google Cloud with no stored key.
- ๐ฌ What starts a run: a manual pipeline, a merge request event, or an
@claudecomment, which needs a listener you build. - ๐งฑ What a run may touch: the tools you allow, the token it acts with, and the runner it lives on.
- โฑ๏ธ What a run may spend: a turn limit, a job timeout and a cap on parallel runs.
Before you start
- A GitLab project and runners. Claude runs on your GitLab runners and uses their compute minutes.
- Access to the project's CI/CD settings, to add the variable and edit
.gitlab-ci.yml. - A credential. A Claude API key, or for Bedrock or Google Cloud, a cloud account that trusts GitLab's OIDC tokens.
- A short
CLAUDE.mdat the repository root. Claude reads it on every run and follows its rules when it proposes changes.
If you only want Claude Code in your terminal working on GitLab issues, you don't need a pipeline: the next section covers that path. For the same job on GitHub, see our Claude Code GitHub Actions guide.
Three ways to connect Claude Code to GitLab
| Way | Where Claude runs | Best for |
|---|---|---|
| CI/CD job | Your GitLab runners | Unattended runs that end in a merge request |
| GitLab MCP server | Your own terminal | Working from issue and merge request context while you watch |
| Claude Agent by GitLab | GitLab Duo Agent Platform | Mentioning an agent on a merge request with no pipeline to maintain |
The rest of this guide sets up the CI/CD job. The other two are short:
- MCP server. Add GitLab's server with
claude mcp addover HTTP, pointing athttps://<your-gitlab-host>/api/v4/mcp, then run/mcpin Claude Code and sign in in the browser. Claude acts as you and sees only what your account can see. GitLab's MCP server must be enabled on the instance or top-level group (GitLab's Claude Code workflows post). Our MCP servers guide covers adding servers in general. - Claude Agent by GitLab. In the project, go to AI > Agents and enable it. You then mention its service account on a merge request, and it works on the review feedback, commits, and leaves a summary comment. It runs inside GitLab Duo Agent Platform, so its prerequisites are GitLab's.
Step 1: Add a masked API key
In the project, go to Settings โ CI/CD โ Variables and add ANTHROPIC_API_KEY. Mark it masked, and protected if only protected branches should run Claude. Never commit a key to the repository.
Step 2: Add the Claude job
This is Anthropic's quick-setup job. Two flags are written out in prose under it, because this blog doesn't print double hyphens:
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 git curl bash
- curl -fsSL https://claude.ai/install.sh | bash
- export PATH="$HOME/.local/bin:$PATH"
script:
- /bin/gitlab-mcp-server || true
- >
claude
-p "${AI_FLOW_INPUT:-'Review this MR and implement the requested changes'}"
What to add and why:
- Anthropic's
apk addline also passes the no-cache flag, which keeps the image small. - The
claudeline ends with three more flags, each with two hyphens:permission-mode acceptEdits,allowedTools "Bash Read Edit Write mcp__gitlab"anddebug. Without them, Claude can't edit files or call GitLab tools in a job nobody is watching. - The
export PATHline is needed because the installer putsclaudein~/.local/bin, which isn't on the image's path. - The
gitlab-mcp-serverline is optional. It starts a GitLab MCP server if your setup provides one, and|| truekeeps the job going if it doesn't. AI_FLOW_INPUTcarries the request. When a trigger passes it, Claude does that; otherwise it falls back to reviewing the merge request.
Test it by running the job by hand from CI/CD โ Pipelines, or by opening a merge request.
Step 3: Wire up @claude mentions
The job above runs on manual pipelines and merge request events. An @claude comment does nothing on its own. To make mentions work:
- Add a project webhook for Comments (notes) that sends to an event listener you run.
- When a comment contains
@claude, have the listener call GitLab's pipeline trigger API withAI_FLOW_INPUT(the request) andAI_FLOW_CONTEXT(the issue or merge request it came from).
Then requests read as they do on GitHub:
@claude implement this feature based on the issue description
Claude reads the issue and the code, writes the change on a branch, and opens a merge request. In a merge request thread, it updates that merge request instead.
If you'd rather not run a listener, Claude Agent by GitLab takes mentions natively, as above.
Step 4: Decide what a run can touch
Tools. The allowedTools flag is the list of what Claude may do without asking. Keep it to what the job needs: Bash Read Edit Write to change code, mcp__gitlab to comment and open merge requests. Our permissions guide covers the rule syntax.
The token it acts with. By default the job uses CI_JOB_TOKEN. If that can't comment or open merge requests in your project, create a Project Access Token with api scope and store it as a masked GITLAB_ACCESS_TOKEN.
Where it runs. Each run is a container on your runner, under your branch protection and approval rules. Every change arrives as a merge request, so review it like any other contributor's work. Limit the job's network egress where you can.
Step 5: Run it on Bedrock or Google Cloud
For production, Anthropic's docs recommend the manual setup, and the cloud providers keep no long-lived key in GitLab at all:
| Provider | GitLab variables | How it signs in |
|---|---|---|
| Claude API | ANTHROPIC_API_KEY | Masked variable |
| Amazon Bedrock | AWS_ROLE_TO_ASSUME, AWS_REGION | The job's OIDC token is exchanged for temporary AWS credentials; set CLAUDE_CODE_USE_BEDROCK: "1" |
| Google Cloud | GCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT, GCP_PROJECT_ID | Workload Identity Federation; set CLAUDE_CODE_USE_VERTEX: "1" |
Both cloud jobs get their token from an id_tokens: block, which GitLab exposes as GITLAB_OIDC_TOKEN; set its aud to the audience you configured on the cloud side. Restrict the IAM role or service account to your project and protected refs, with least-privilege permissions. Bedrock model IDs carry a region prefix, such as us.anthropic.claude-sonnet-4-6. Our Claude Code on Bedrock guide covers when a team should route through AWS.
Step 6: Cap what each run spends
Each run spends two things: runner minutes on your GitLab plan, and Claude tokens, which grow with the task and the size of the codebase. To keep both down:
- Pass the
max-turnsflag (two hyphens) to limit back-and-forth. - Set GitLab's job-level
timeout, for exampletimeout: 30m. - Limit concurrency so runs don't stack.
- Write specific
@clauderequests and clear issue descriptions, so Claude needs fewer turns. - Keep
CLAUDE.mdshort, and cache package installs on your runners.
Flags can change between versions, so run claude with the help flag in a job to see what yours supports.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
@claude does nothing | No pipeline is triggered | Check the webhook and listener, or run the job by hand to test |
| The job runs but can't reach Claude | Key or provider variables missing | Check ANTHROPIC_API_KEY or the cloud variables in CI/CD settings |
/claude does nothing | The trigger is the mention | Use @claude |
| Claude can't comment or open a merge request | Token or tool missing | Give CI_JOB_TOKEN enough access or use a Project Access Token with api scope, and keep mcp__gitlab in allowedTools |
| Bedrock or Google Cloud sign-in fails | OIDC or federation setup | Check the role or service account, the aud value, the region and model availability |
Frequently asked questions
Does Claude Code work with GitLab?
Yes, three ways. A GitLab CI/CD job runs Claude Code on your runners and opens merge requests. GitLab's MCP server connects Claude Code in your terminal to issues and merge requests. And Claude Agent by GitLab runs inside GitLab Duo Agent Platform, where you mention it on a merge request.
How do I set up Claude Code in GitLab CI/CD?
Add ANTHROPIC_API_KEY as a masked CI/CD variable, then add a job to .gitlab-ci.yml that installs Claude Code and runs it with a prompt, the acceptEdits permission mode and an allowedTools list. Run the job by hand from CI/CD, Pipelines, or trigger it from a merge request.
Who maintains Claude Code for GitLab?
GitLab does. Anthropic's docs mark Claude Code for GitLab CI/CD as beta and say the integration is maintained by GitLab, with support through a GitLab issue. It's built on the Claude Code CLI and Agent SDK.
How do @claude mentions work on GitLab?
Not by default. Add a project webhook for comments that sends to a listener you run, and have the listener call the pipeline trigger API with AI_FLOW_INPUT and AI_FLOW_CONTEXT when a comment contains @claude. Claude Agent by GitLab takes mentions without a listener.
Can Claude Code on GitLab use Amazon Bedrock or Google Cloud?
Yes. The job exchanges GitLab's OIDC token for temporary AWS credentials or a Google Cloud service account through Workload Identity Federation, so no long-lived key is stored. Set CLAUDE_CODE_USE_BEDROCK or CLAUDE_CODE_USE_VERTEX to 1 in the job.
How much does Claude Code on GitLab cost?
Each run uses runner minutes on your GitLab plan plus Claude tokens, which vary with the task and codebase size. Keep both down with specific requests, a short CLAUDE.md, a max-turns limit, a job timeout and a concurrency limit.
Give every run the same rules
A pipeline job starts fresh each time, and the one file it reads on every run is your CLAUDE.md: Anthropic's docs point there for coding standards, review criteria and project rules. Keeping that file short and adding a rule each time a run goes wrong is the method in our guide to compound engineering for Claude Code. For every way to run Claude Code without you, see our Claude Code automation guide, and for scripting one prompt from your own server, headless mode.
Stop guessing. Score your first workflow.
Score one workflow in about five minutes. Nine questions, a grade, and the specific gap holding it back - no call required.
Related Posts

Claude Code effort levels: which one for which task
Claude Code has five effort levels, from low to max, and the newest models start at medium. What each level is for, the default on each model, which setting wins when several apply, and how ultrathink raises a single turn.

Claude Code GitHub Actions: set it up, and decide what it can touch
Claude Code GitHub Actions runs Claude Code in your repository's workflows, on an @claude mention or a prompt on any GitHub event. How to install it, how it signs in, and the four layers that decide what a run can touch and spend.

Claude Code SDK or claude -p: which one to script against
The Claude Code SDK is now the Claude Agent SDK, and it runs the same agent as claude -p. When a script should call claude -p, when your code needs the SDK, what each loads by default, and how each signs in.
