This directory contains example GitLab CI/CD configurations for integrating Claude Code into your GitLab workflows.
- GitLab App Setup Guide - Comprehensive guide for setting up Claude Code as a GitLab OAuth application
- Webhook Service Setup - Detailed instructions for deploying the webhook service
- Self-Hosted GitLab Guide - Configuration for on-premise GitLab instances
The easiest way to integrate Claude Code is to clone the repository directly in your CI/CD pipeline:
claude_assistant:
image: oven/bun:1.1.29-alpine
before_script:
# Clone Claude Code for GitLab
- apk add --no-cache git openssh-client
- git clone https://github.com/RealMikeChong/claude-code-for-gitlab.git /tmp/claude-code
- cd /tmp/claude-code
- bun install --frozen-lockfile
- cd $CI_PROJECT_DIR
script:
- cd /tmp/claude-code && bun run src/entrypoints/prepare.ts
variables:
CLAUDE_CODE_OAUTH_TOKEN: $CLAUDE_CODE_OAUTH_TOKEN
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'For faster pipeline execution, build a Docker image from the Claude Code repository:
claude_assistant:
image: your-registry/claude-code-gitlab:latest
script:
- claude-code-action
variables:
CLAUDE_CODE_OAUTH_TOKEN: $CLAUDE_CODE_OAUTH_TOKENSee docker-integration.gitlab-ci.yml for complete Docker build instructions.
For the absolute simplest integration, you can include a remote configuration:
include:
- remote: "https://raw.githubusercontent.com/RealMikeChong/claude-code-for-gitlab/main/examples/gitlab/include/claude-code.gitlab-ci.yml"
variables:
CLAUDE_CODE_OAUTH_TOKEN: $CLAUDE_CODE_OAUTH_TOKENThe standard configuration for using Claude Code in GitLab CI/CD:
- Merge request comment triggers
- Issue comment handling
- Support for Anthropic API, AWS Bedrock, and Google Vertex AI
- Custom MCP server configuration
Advanced setup using GitLab webhooks for more control:
- Webhook configuration for different event types
- Automatic webhook setup job
- Payload parsing and handling
Configuration for self-hosted GitLab instances:
- Custom certificate handling
- Proxy configuration
- Local LLM support via Ollama
- Enhanced security restrictions
Comprehensive example with advanced capabilities:
- User permission validation
- Rate limiting
- Code quality analysis
- Automatic testing and merging
- Scheduled maintenance tasks
- Choose a configuration that matches your needs
- Copy the configuration to your project's
.gitlab-ci.yml - Set up CI/CD variables in GitLab:
- Recommended:
CLAUDE_CODE_OAUTH_TOKEN- Claude Code OAuth token (replaces both GitLab and Anthropic tokens) - Alternative:
CLAUDE_GITLAB_TOKEN- GitLab personal access token withapiscopeCLAUDE_API_KEY- Your Anthropic API key (or credentials for other providers)
- Recommended:
- Customize the trigger phrase and other settings as needed
The GitLab token needs the following scopes:
api- Full API accessread_repository- Read repository contentwrite_repository- Push changes to branches
- Merge Request Comments: Mention
@claudein MR comments - Issue Comments: Mention
@claudein issue comments (requires webhook) - Manual Triggers: Use GitLab's web UI with custom prompts
- Scheduled Runs: Automatic maintenance and code review
- Anthropic API: Direct integration with Claude
- AWS Bedrock: Using AWS credentials or OIDC
- Google Vertex AI: Using service accounts or workload identity
- Local LLMs: Ollama integration for on-premise deployments
- User permission validation
- Rate limiting
- Tool restrictions
- File access controls
- Audit logging
CI_PROJECT_ID- Project IDCI_MERGE_REQUEST_IID- Merge request internal IDCI_SERVER_URL- GitLab instance URLGITLAB_USER_NAME- User who triggered the pipelineGITLAB_USER_EMAIL- User's email addressCI_COMMIT_SHA- Current commit SHACI_PIPELINE_URL- URL to the current pipeline
Option 1 - OAuth Token (Recommended):
CLAUDE_CODE_OAUTH_TOKEN- Claude Code OAuth token (handles both GitLab and AI authentication)
Option 2 - Traditional Tokens:
CLAUDE_GITLAB_TOKEN- GitLab personal access tokenCLAUDE_API_KEY- Anthropic API key (or provider credentials)
CLAUDE_TRIGGER_PHRASE- Custom trigger phrase (default:@claude)CLAUDE_MODEL- Model to use (default:sonnet)CLAUDE_BRANCH_PREFIX- Prefix for branches created by ClaudeBASE_BRANCH- Base branch for comparisons (default:main)CLAUDE_INSTRUCTIONS- Custom instructions for ClaudeCLAUDE_ALLOWED_TOOLS- Whitelist of allowed toolsCLAUDE_DISALLOWED_TOOLS- Blacklist of disallowed tools
variables:
CLAUDE_TRIGGER_PHRASE: "@ai-helper" # Change from default @claudevariables:
CLAUDE_ALLOWED_TOOLS: |
read_file
write_file
search_files
CLAUDE_DISALLOWED_TOOLS: |
run_command: rm, curl
browser_actionvariables:
CLAUDE_INSTRUCTIONS: |
You are helping with a Python project.
Follow PEP 8 style guidelines.
Always write unit tests for new functions.variables:
CLAUDE_MODEL: "claude-3-opus-latest" # Use Opus for complex tasks- Use Protected Variables: Store sensitive tokens as protected CI/CD variables
- Limit Trigger Users: Use permission validation to restrict who can trigger Claude
- Review Changes: Always review Claude's changes before merging
- Use Branch Protection: Require approvals for Claude's merge requests
- Audit Logs: Monitor pipeline logs for Claude's activities
- Check if the trigger phrase is correct
- Verify CI/CD variables are set correctly
- Check pipeline logs for error messages
- Ensure GitLab token has
apiscope - Check if the user has Developer or higher access
- Verify branch protection rules allow Claude to push
- Verify certificate configuration
- Check proxy settings
- Ensure GitLab instance URL is correct