Back to Blog

Claude Code on GitLab: pipelines, merge requests and @claude

Alex Kim
10 min read
Claude Code on GitLab: pipelines, merge requests and @claude

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 @claude comment, 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.md at 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

WayWhere Claude runsBest for
CI/CD jobYour GitLab runnersUnattended runs that end in a merge request
GitLab MCP serverYour own terminalWorking from issue and merge request context while you watch
Claude Agent by GitLabGitLab Duo Agent PlatformMentioning 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 add over HTTP, pointing at https://<your-gitlab-host>/api/v4/mcp, then run /mcp in 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 add line also passes the no-cache flag, which keeps the image small.
  • The claude line ends with three more flags, each with two hyphens: permission-mode acceptEdits, allowedTools "Bash Read Edit Write mcp__gitlab" and debug. Without them, Claude can't edit files or call GitLab tools in a job nobody is watching.
  • The export PATH line is needed because the installer puts claude in ~/.local/bin, which isn't on the image's path.
  • The gitlab-mcp-server line is optional. It starts a GitLab MCP server if your setup provides one, and || true keeps the job going if it doesn't.
  • AI_FLOW_INPUT carries 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:

  1. Add a project webhook for Comments (notes) that sends to an event listener you run.
  2. When a comment contains @claude, have the listener call GitLab's pipeline trigger API with AI_FLOW_INPUT (the request) and AI_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:

ProviderGitLab variablesHow it signs in
Claude APIANTHROPIC_API_KEYMasked variable
Amazon BedrockAWS_ROLE_TO_ASSUME, AWS_REGIONThe job's OIDC token is exchanged for temporary AWS credentials; set CLAUDE_CODE_USE_BEDROCK: "1"
Google CloudGCP_WORKLOAD_IDENTITY_PROVIDER, GCP_SERVICE_ACCOUNT, GCP_PROJECT_IDWorkload 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-turns flag (two hyphens) to limit back-and-forth.
  • Set GitLab's job-level timeout, for example timeout: 30m.
  • Limit concurrency so runs don't stack.
  • Write specific @claude requests and clear issue descriptions, so Claude needs fewer turns.
  • Keep CLAUDE.md short, 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

SymptomLikely causeFix
@claude does nothingNo pipeline is triggeredCheck the webhook and listener, or run the job by hand to test
The job runs but can't reach ClaudeKey or provider variables missingCheck ANTHROPIC_API_KEY or the cloud variables in CI/CD settings
/claude does nothingThe trigger is the mentionUse @claude
Claude can't comment or open a merge requestToken or tool missingGive 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 failsOIDC or federation setupCheck 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.

#claude-code#GitLab#CI/CD#Automation#ai-agents
Free assessment

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.