A robust webhook service that integrates GitLab with Claude Code CLI, enabling AI-powered code assistance directly from GitLab issues, merge requests, and comments.
- GitLab Integration: Receives webhook events from GitLab for issues, merge requests, and comments
- Claude AI Processing: Automatically detects
@claudementions and executes Claude Code CLI commands - Secure Webhook Verification: Validates webhook signatures to ensure security
- Branch-aware Processing: Automatically creates new branches for Claude changes with merge request workflow
- Automatic Code Changes: Commits and pushes changes made by Claude back to the repository
- Smart Merge Requests: Creates professional MRs with conventional commit titles and structured descriptions
- Real-time Feedback: Posts results and errors as comments back to GitLab
- Node.js 18+ or Docker
- Claude Code installed (if running locally)
- GitLab project with webhook access
- Anthropic API key
- GitLab API token
- Clone the repository:
git clone <repository-url>
cd gitlab-claude-webhook- Copy environment configuration:
cp .env.example .env- Configure environment variables in
.env:
# Claude API Configuration
ANTHROPIC_BASE_URL=https://api.anthropic.com
ANTHROPIC_AUTH_TOKEN=sk-your-anthropic-token
# GitLab Configuration
GITLAB_BASE_URL=https://gitlab.com
GITLAB_TOKEN=glpat-your-gitlab-token
# Webhook Configuration
WEBHOOK_SECRET=your-webhook-secret
PORT=3000
# Working Directory
WORK_DIR=/tmp/gitlab-claude-work
# Logging
LOG_LEVEL=info# Build and run with Docker Compose
docker-compose up -d
# View logs
docker-compose logs -f# Install dependencies
npm install
# Build the project
npm run build
# Start the service
# Note: must run with non-root privilege, due to the requirement for Claude Code's parameter --dangerously-skip-permissions
npm start
# For development with hot reload
# Note: must run with non-root privilege, due to the requirement for Claude Code's parameter --dangerously-skip-permissions
npm run devFor detailed GitLab setup instructions, including webhook configuration, token permissions, and troubleshooting, see:
π Complete GitLab Setup Guide
- Create GitLab Token: Generate a personal or project access token with
api,read_repository, andwrite_repositoryscopes - Configure Webhook: Add webhook to your project with URL
http://your-domain:3000/webhookand secret token - Set Trigger Events: Enable Issues events, Merge request events, and Comments
- Test Integration: Create an issue with
@claudemention to verify setup
Create or comment on an issue with:
@claude Please help me optimize this function in src/utils/helper.js
Add to MR description or comment:
@claude Review the security implications of these changes and suggest improvements
You can provide specific instructions:
@claude
- Fix the TypeScript errors in the authentication module
- Add proper error handling
- Update the unit tests accordingly
- Webhook Reception: Service receives GitLab webhook events
- Signature Verification: Validates webhook authenticity using secret
- Content Analysis: Scans for
@claudementions in issues/MRs/comments - Project Preparation: Clones the GitLab project to a temporary directory
- Branch Management: Creates timestamp-based branch for Claude changes
- Claude Execution: Runs Claude Code CLI with the extracted instructions
- Change Handling: Commits and pushes any code changes made by Claude
- Smart MR Creation: Automatically creates merge requests with conventional commit format
- Feedback: Posts results or errors as comments back to GitLab
Here's what the GitLab integration looks like in action when you use @claude mentions:
The screenshot shows the complete workflow:
- Request: User creates an issue or comment with
@claudemention and specific instructions - Instant Reply: Service immediately acknowledges the request and starts processing
- Final Reply: Claude processes the request, makes the necessary changes, and creates a merge request with detailed information about what was modified
The service automatically:
- Creates a timestamped branch for the changes
- Executes the Claude Code CLI with the provided instructions
- Commits and pushes any code modifications
- Generates a professional merge request with conventional commit format
- Provides a direct link to review and merge the changes
GET /- Service informationGET /health- Health check endpointPOST /webhook- GitLab webhook receiver
For detailed configuration instructions including environment variable expansion, Docker setup, and troubleshooting, see:
π Environment Configuration Guide
| Variable | Description | Default |
|---|---|---|
ANTHROPIC_BASE_URL |
Anthropic API base URL | https://api.anthropic.com |
ANTHROPIC_AUTH_TOKEN |
Anthropic API token | Required |
GITLAB_BASE_URL |
GitLab instance URL | https://gitlab.com |
GITLAB_TOKEN |
GitLab API token | Required |
WEBHOOK_SECRET |
Webhook validation secret | Required |
PORT |
Server port | 3000 |
WORK_DIR |
Temporary work directory | /tmp/gitlab-claude-work |
LOG_LEVEL |
Logging level | info |
Your GitLab token needs the following scopes:
api- Full API accessread_user- Read user informationread_repository- Read repositorywrite_repository- Write to repository
- Always use webhook secrets for signature verification
- Limit GitLab token permissions to minimum required
- Run the service in a secure environment
- Monitor logs for suspicious activity
- Consider network restrictions and firewall rules
-
"Claude Code CLI not found"
- Ensure Claude Code CLI is installed and in PATH
- For Docker: Claude Code CLI needs to be available in the container
-
"Invalid webhook signature"
- Verify
WEBHOOK_SECRETmatches GitLab webhook configuration - Check that GitLab is sending the correct header
- Verify
-
"Failed to clone project"
- Verify GitLab token has repository access
- Check network connectivity to GitLab
- Ensure branch exists
-
"Permission denied"
- Verify GitLab token has write permissions
- Check repository settings and branch protection rules
View detailed logs:
# Docker
docker-compose logs -f gitlab-claude-webhook
# Local
tail -f combined.lognpm run buildnpm run lintsrc/
βββ __tests__/ # Test files
β βββ setup.ts # Jest test setup
β βββ webhook.test.ts # Webhook functionality tests
βββ index.ts # Main entry point with environment loading
βββ server/
β βββ webhookServer.ts # Express server and webhook handling
βββ services/
β βββ eventProcessor.ts # GitLab event processing logic
β βββ projectManager.ts # Git operations and project management
β βββ claudeExecutor.ts # Basic Claude Code CLI execution
β βββ streamingClaudeExecutor.ts # Streaming Claude execution with real-time updates
β βββ gitlabService.ts # GitLab API interactions
βββ types/
β βββ gitlab.ts # GitLab-related type definitions
β βββ common.ts # Common type definitions
βββ utils/
βββ config.ts # Configuration management with variable expansion
βββ configDebug.ts # Configuration debugging utilities
βββ logger.ts # Winston-based logging utility
βββ webhook.ts # Webhook utilities and signature verification
βββ mrGenerator.ts # Smart merge request generation
- π GitLab Configuration Guide - Complete setup instructions for GitLab integration
- βοΈ Environment Configuration Guide - Detailed configuration instructions with variable expansion and Docker setup
- π§ API Reference - Available endpoints and usage
- ποΈ Project Structure - Codebase organization
- π Troubleshooting - Common issues and solutions
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details
