This guide walks you through setting up GitLab webhooks and permissions to work with the Claude Code integration service.
- Prerequisites
- GitLab Token Setup
- Webhook Configuration
- Project Permissions
- Branch Protection Settings
- Testing the Integration
- Troubleshooting
Before configuring GitLab, ensure you have:
- GitLab Account: Admin or maintainer access to the target GitLab project
- Webhook Service: The Claude webhook service running and accessible
- Domain/IP: Public URL where your webhook service is hosted
- Webhook Secret: A secure secret token for webhook verification
-
Go to GitLab → Preferences → Access Tokens
- URL:
https://gitlab.com/-/profile/personal_access_tokens(for GitLab.com) - For self-hosted:
https://your-gitlab-instance.com/-/profile/personal_access_tokens
- URL:
-
Create a new token with the following settings:
- Token name:
claude-code-integration - Expiration date: Set according to your security policy
- Scopes: Select the following permissions:
- ✅
api- Complete read/write access to the API - ✅
read_user- Read user information - ✅
read_repository- Read access to repository - ✅
write_repository- Write access to repository
- ✅
- Token name:
-
Important: Copy the token immediately and store it securely. It won't be shown again.
For project-specific access:
- Go to your Project → Settings → Access Tokens
- Create a new token with:
- Token name:
claude-code-bot - Role:
Maintainer(required for pushing changes) - Scopes:
- ✅
api - ✅
read_repository - ✅
write_repository
- ✅
- Token name:
- Navigate to your GitLab project
- Go to Settings → Webhooks
- Click Add new webhook
Configure the following fields:
https://your-domain.com:3000/webhook
Replace your-domain.com with your actual domain or IP address.
Enter the same secret you configured in your service's WEBHOOK_SECRET environment variable.
Select the following events:
- ✅ Issues events - For
@claudementions in issues - ✅ Merge request events - For
@claudementions in MR descriptions - ✅ Comments - For
@claudementions in comments - ✅ Pipeline events - (Optional) For pipeline-related integrations
- ✅ Wiki Page events - (Optional) If you want wiki integration
- ✅ Enable SSL verification - Recommended for production
- ❌ Disable only for testing with self-signed certificates
- Click Add webhook to save
- Find your newly created webhook in the list
- Click Test → Push events to send a test payload
- Check your webhook service logs for successful reception
Ensure the token owner has the following project permissions:
| Permission | Required Level | Purpose |
|---|---|---|
| Repository | Developer+ | Clone and read repository |
| Issues | Reporter+ | Read and comment on issues |
| Merge Requests | Developer+ | Read and comment on MRs |
| Push to Repository | Developer+ | Commit and push changes |
- Unprotected branches: No additional setup required
- Protected branches: See Branch Protection Settings
If you have protected branches (like main or develop):
- Go to Project Settings → Repository → Protected Branches
- Find your protected branch
- Under Allowed to push, add:
- The user associated with your GitLab token
- Or create a specific service account for Claude
- Configure the service to create merge requests instead of direct pushes
- Set up auto-merge rules for Claude-generated MRs
- Add this to your
.envconfiguration:GITLAB_USE_MR=true GITLAB_AUTO_MERGE=true
Create push rules that allow the service account to bypass certain restrictions:
- Go to Project Settings → Push Rules
- Add exception for the service account
- Configure rules as needed
Create a new issue with:
@claude Hello! Can you help me understand what this service does?
Create an issue with:
@claude Please review the main entry point file and suggest any improvements.
Create a merge request and comment:
@claude
Please review this MR for:
- Security vulnerabilities
- Performance issues
- Code style consistency
- Missing error handling
After each test:
- Check webhook service logs for processing
- Look for Claude's response comments in GitLab
- Verify any code changes were properly committed
- Confirm new branches/MRs were created if applicable
Symptoms: 403 errors in webhook service logs Solutions:
- Verify
WEBHOOK_SECRETmatches GitLab webhook secret token exactly - Check GitLab webhook logs for delivery attempts
- Ensure webhook URL is correct and accessible
Symptoms: 401 errors when accessing GitLab API Solutions:
- Verify GitLab token is valid and hasn't expired
- Check token permissions include required scopes
- Test token manually:
curl -H "Authorization: Bearer $TOKEN" https://gitlab.com/api/v4/user
Symptoms: Git push errors in service logs Solutions:
- Check branch protection settings
- Verify token has push permissions
- Review Git credentials configuration
- Check if branch exists and is accessible
Symptoms: Webhook received but no Claude processing Solutions:
- Verify
@claudemention format is correct - Check if issue/MR contains actual content to process
- Review Claude service logs for errors
- Confirm Anthropic API token is valid
curl -X POST https://your-domain.com:3000/webhook \
-H "Content-Type: application/json" \
-H "X-Gitlab-Token: your-webhook-secret" \
-H "X-Gitlab-Event: Issue Hook" \
-d @test-payload.json- Go to Project Settings → Webhooks
- Click on your webhook
- Scroll down to Recent Deliveries
- Click on individual deliveries to see request/response details
Add to your service configuration:
LOG_LEVEL=debug
GITLAB_DEBUG=trueIf you encounter rate limiting:
- GitLab.com: 2,000 requests per minute per token
- Self-hosted: Check your instance configuration
- Solutions:
- Implement request queuing
- Add delays between API calls
- Use project tokens instead of personal tokens
- Consider upgrading GitLab plan for higher limits
- Check firewall rules allow incoming connections on webhook port
- Verify DNS resolution for your webhook URL
- Test connectivity:
curl -I https://your-domain.com:3000/health - Consider using ngrok for local testing:
ngrok http 3000 # Use the generated HTTPS URL as your webhook URL
- Check outbound firewall rules
- Verify DNS resolution for GitLab instance
- Test connectivity:
curl -I https://gitlab.com - Check proxy settings if behind corporate network
- ✅ Use HTTPS for webhook URLs
- ✅ Enable webhook secret verification
- ✅ Use minimal required token permissions
- ✅ Regular token rotation
- ✅ Monitor webhook logs for suspicious activity
- ✅ Implement rate limiting on webhook endpoint
- ✅ Use dedicated service accounts
- ✅ Regular security audits
- Store tokens in secure environment variables
- Never commit tokens to repository
- Use token rotation policies
- Monitor token usage in GitLab audit logs
- Revoke tokens immediately if compromised
For additional help, check the main README.md or create an issue in the project repository.