Issue 00 · Autumn 2026日本語 · RSS
AgentKoji

Claude Code GitLab CI/CD: Setup, Bedrock and Vertex (Beta)

Claude Code for GitLab CI/CD is a beta maintained by GitLab. Add a masked ANTHROPIC_API_KEY and one job, or use Bedrock OIDC or Vertex WIF without stored keys.

TL;DR

  • Claude Code for GitLab CI/CD is in beta and maintained by GitLab. It runs claude -p inside a job in .gitlab-ci.yml, built on the Claude Code CLI and Agent SDK.
  • The quick setup is two pieces: a masked CI/CD variable ANTHROPIC_API_KEY and a Claude job. Amazon Bedrock (OIDC) and Google Cloud's Agent Platform (Workload Identity Federation) work without stored keys.
  • Unlike GitHub Actions, @claude mentions need your own webhook listener that calls the pipeline trigger API with AI_FLOW_* variables.

Claude Code for GitLab CI/CD runs Claude Code inside a GitLab pipeline job. You add one job to .gitlab-ci.yml and a masked API key, and Claude reads the repository, makes changes in a branch and proposes them as a merge request (MR). The docs mark it as beta and say GitLab maintains it. This guide covers the quick setup, the production setup, Amazon Bedrock and Google Cloud jobs, costs, and what to check when nothing happens. For the GitHub version, see Claude Code GitHub Actions: Setup, @claude and Security.

In our test environment we did not run anything on GitLab. We did not add variables, run a pipeline or configure OIDC (not run). Every YAML example below comes from the official page. We did not run or lint them.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

What it is and who maintains it

ItemWhat the docs say
StatusBeta. Features may change
MaintainerGitLab. Support goes through the GitLab issue linked from the docs
Built onThe Claude Code CLI and Agent SDK
Where it runsYour GitLab runners, with your branch protection and approvals
ProvidersClaude API, Amazon Bedrock, Google Cloud’s Agent Platform

The page lists only those three providers. Microsoft Foundry is not among them, so do not plan a GitLab setup around Foundry.

Each run happens in a container. The docs say Claude Code applies workspace-scoped permissions to writes, and every change goes through an MR so reviewers see the diff.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Quick setup

  1. Go to Settings → CI/CD → Variables and add ANTHROPIC_API_KEY. Mark it masked, and protected if you need it.
  2. Add a Claude job to .gitlab-ci.yml.

This is the official job:

stages:
  - ai

claude:
  stage: ai
  image: node:24-alpine3.21
  # Adjust rules to fit how you want to trigger the job:
  # - manual runs
  # - merge request events
  # - web/API triggers when a comment contains '@claude'
  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
    # The installer places claude in ~/.local/bin, which isn't on PATH in this image
    - export PATH="$HOME/.local/bin:$PATH"
  script:
    # Optional: start a GitLab MCP server if your setup provides one
    - /bin/gitlab-mcp-server || true
    # Use AI_FLOW_* variables when invoking via web/API triggers with context payloads
    - 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

Here is what the job does, line by line:

To test it, run the job by hand from CI/CD → Pipelines, or trigger it from an MR. For how claude -p behaves outside CI, see Claude Code Headless Mode: claude -p for Scripts and Cron.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Production setup and @claude mentions

The docs recommend a manual setup for production:

  1. Provider access. Store ANTHROPIC_API_KEY as a masked variable for the Claude API. For Bedrock, configure GitLab as an AWS OIDC provider and create an IAM role. For Google Cloud, configure Workload Identity Federation.
  2. GitLab API credentials. CI_JOB_TOKEN is the default. For comments and MRs you may need a Project Access Token with api scope, stored as a masked GITLAB_ACCESS_TOKEN.
  3. The job. Use the quick setup job, or a provider job from the examples below.
  4. Mentions (optional). Add a project webhook for “Comments (notes)” that points to an event listener. When a comment contains @claude, the listener calls the pipeline trigger API with variables like AI_FLOW_INPUT and AI_FLOW_CONTEXT.

Step 4 is the big difference from GitHub. On GitHub the action itself watches for @claude. On GitLab the docs give no listener. You run your own and have it start the pipeline. Without it, the job runs only on the rules you set, such as manual or MR events. What the listener runs on and how it authenticates is up to you. The docs don’t cover it, and we have not built one.

With a trigger in place, comments like these start a run:

@claude implement this feature based on the issue description
@claude fix the TypeError in the user dashboard component

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Amazon Bedrock with OIDC

You need Bedrock access to the Claude models you want and GitLab registered as an OIDC identity provider in AWS IAM. You also need an IAM role with least-privilege Bedrock invoke permissions, trusted only for your project and protected refs. Set two CI/CD variables:

GitLab mints the job’s OIDC token from the id_tokens: block as GITLAB_OIDC_TOKEN. Set aud to the audience you configured on the IAM OIDC provider, such as your GitLab instance URL. The job exchanges the token for temporary AWS credentials:

stages:
  - ai

claude-bedrock:
  stage: ai
  image: node:24-alpine3.21
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
  id_tokens:
    GITLAB_OIDC_TOKEN:
      aud: https://gitlab.example.com
  before_script:
    - apk add --no-cache bash curl jq git aws-cli
    - curl -fsSL https://claude.ai/install.sh | bash
    # The installer places claude in ~/.local/bin, which isn't on PATH in this image
    - export PATH="$HOME/.local/bin:$PATH"
    # Exchange the job's OIDC token for AWS credentials
    - export AWS_WEB_IDENTITY_TOKEN_FILE="/tmp/oidc_token"
    - printf "%s" "$GITLAB_OIDC_TOKEN" > "$AWS_WEB_IDENTITY_TOKEN_FILE"
    - >
      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"
    CLAUDE_CODE_USE_BEDROCK: "1"

CLAUDE_CODE_USE_BEDROCK: "1" switches Claude Code to Bedrock. Bedrock model IDs carry a regional prefix, such as us.anthropic.claude-sonnet-4-6. The example requests credentials with --duration-seconds 3600, one hour. Our reading is that a longer job would outlive them, so we would keep the job timeout under an hour. The docs don’t say this (unverified).

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Google Cloud’s Agent Platform with Workload Identity Federation

Claude Code turns this provider on with CLAUDE_CODE_USE_VERTEX, and the page links to the Claude Code docs for Google Vertex AI. You need a project with the Agent Platform API, IAM Credentials API and STS API enabled. You also need a Workload Identity Pool and provider that trust GitLab OIDC, and a dedicated service account with only the Agent Platform roles it needs. Set these variables:

The job writes the OIDC token to a file and builds a credential configuration whose credential_source points to that file. GOOGLE_APPLICATION_CREDENTIALS then exposes it to Claude Code through Application Default Credentials:

stages:
  - ai

claude-vertex:
  stage: ai
  image: gcr.io/google.com/cloudsdktool/google-cloud-cli:slim
  rules:
    - if: '$CI_PIPELINE_SOURCE == "web"'
  id_tokens:
    GITLAB_OIDC_TOKEN:
      aud: https://gitlab.example.com
  before_script:
    - apt-get update && apt-get install -y git && apt-get clean
    - curl -fsSL https://claude.ai/install.sh | bash
    # The installer places claude in ~/.local/bin, which isn't on PATH in this image
    - export PATH="$HOME/.local/bin:$PATH"
    # Write the job's OIDC token where credential_source expects it
    - printf "%s" "$GITLAB_OIDC_TOKEN" > /tmp/oidc_token
    # Write the WIF credential configuration to a file (no downloaded keys)
    - |
      cat > /tmp/cred.json <<EOF
      {
        "type": "external_account",
        "audience": "//iam.googleapis.com/${GCP_WORKLOAD_IDENTITY_PROVIDER}",
        "subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
        "token_url": "https://sts.googleapis.com/v1/token",
        "credential_source": {
          "file": "/tmp/oidc_token"
        },
        "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/${GCP_SERVICE_ACCOUNT}:generateAccessToken"
      }
      EOF
    # Expose the credentials to Claude Code via Application Default Credentials
    - export GOOGLE_APPLICATION_CREDENTIALS=/tmp/cred.json
    # Authenticate the gcloud CLI with the same credential configuration
    - gcloud auth login --cred-file=/tmp/cred.json
    - gcloud config set project "$GCP_PROJECT_ID"
  script:
    - /bin/gitlab-mcp-server || true
    - >
      CLOUD_ML_REGION="${CLOUD_ML_REGION:-us-east5}"
      claude
      -p "${AI_FLOW_INPUT:-'Review and update code as requested'}"
      --permission-mode acceptEdits
      --allowedTools "Bash Read Edit Write mcp__gitlab"
      --debug
  variables:
    CLOUD_ML_REGION: "us-east5"
    CLAUDE_CODE_USE_VERTEX: "1"
    ANTHROPIC_VERTEX_PROJECT_ID: "$GCP_PROJECT_ID"

CLAUDE_CODE_USE_VERTEX: "1" switches Claude Code to Google Cloud, and ANTHROPIC_VERTEX_PROJECT_ID names the project. No service account key is stored anywhere. The docs recommend repository-specific trust conditions. For provider setup outside CI, see Claude Code on Bedrock and Vertex.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Security

The quick setup job passes --debug. We have not checked what that writes to the job log. On a public project, job logs may be visible to others, so read a log before you leave --debug on (unverified).

Put project rules in a CLAUDE.md at the repository root. Claude reads it on every run and follows those conventions when it proposes changes. Keep it short, because it costs tokens each time.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Costs

Each run costs two things:

The docs suggest these limits:

The docs give no cost figures, and we have none either. For how CI runs add up, see Running Claude Code in CI: Costs and Traps.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

When it doesn’t work

SymptomWhat to check
No response to @claudeThe pipeline is actually triggered (manually, by an MR event, or by your note listener). ANTHROPIC_API_KEY or the provider variables exist. The comment says @claude, not /claude. Your mention trigger is set up
The job can’t comment or open MRsCI_JOB_TOKEN has enough permission on the project, or use a Project Access Token with api scope. mcp__gitlab is in --allowedTools. The job runs in the MR’s context or gets context through AI_FLOW_* variables
Authentication errors on the Claude APIANTHROPIC_API_KEY is valid and not expired
Authentication errors on Bedrock or Google CloudThe OIDC or WIF setup, role impersonation, variable names, region, and whether the model is available there

The docs add that flags can change between Claude Code versions, so run claude --help in the job to see what yours supports.

Source: https://code.claude.com/docs/en/gitlab-ci-cd, checked 2026-11-06

Summary

FAQ

Is Claude Code for GitLab CI/CD an official Anthropic product?
It is documented on the Claude Code docs, but the docs say the integration is in beta and maintained by GitLab. Support goes through a GitLab issue.
What do I need for the quick setup?
A masked CI/CD variable named ANTHROPIC_API_KEY under Settings → CI/CD → Variables, and a Claude job in .gitlab-ci.yml that installs Claude Code and runs claude -p.
Can I use Amazon Bedrock or Google Cloud instead of an API key?
Yes. The docs give a Bedrock job that exchanges the job's GitLab OIDC token for temporary AWS credentials, and an Agent Platform job that uses Workload Identity Federation. Neither stores long-lived keys.
Why does Claude not respond to @claude in GitLab?
Check that the pipeline is actually triggered, that ANTHROPIC_API_KEY or the cloud provider variables exist, that the comment says @claude and not /claude, and that your mention trigger is configured.
Why can't the job comment or open merge requests?
CI_JOB_TOKEN may lack permission for the project. Use a Project Access Token with api scope, enable mcp__gitlab in --allowedTools, and make sure the job has MR context or AI_FLOW_* variables.