Sentry Bug Fixer
Automated bug fixing using Claude Code and Sentry MCP integration. This GitLab CI template periodically fetches unresolved issues from Sentry, uses AI to analyze and fix them, and creates merge requests automatically.
Loading actions...
Skill content
Main instructions and any bundled files for this skill.
Sentry Bug Fixer
Automated bug fixing using Claude Code and Sentry MCP integration. This GitLab CI template periodically fetches unresolved issues from Sentry, uses AI to analyze and fix them, and creates merge requests automatically.
How It Works
- Scheduled Trigger: Pipeline runs on a schedule (e.g., every 6 hours)
- Issue Discovery: Claude queries Sentry MCP for unresolved issues
- Analysis: For each issue, Claude:
- Gets full stack trace from Sentry
- Uses Seer AI for root cause analysis
- Reads relevant source files
- Fix Implementation: Claude edits files to fix the bug
- MR Creation: Changes are committed, pushed, and an MR is created via GitLab MCP
- Human Review: Developers review and merge the automated MRs
Quick Start
1. Set Up Group-Level Variables
In your GitLab Group settings: Settings → CI/CD → Variables
| Variable | Type | Description |
|---|---|---|
GCP_WORKLOAD_IDENTITY_PROVIDER | Regular | GCP Workload Identity Provider resource name |
GCP_SERVICE_ACCOUNT | Regular | GCP Service Account email for Vertex AI |
GCP_PROJECT_ID | Regular | GCP Project ID with Vertex AI enabled |
CLOUD_ML_REGION | Regular | Vertex AI region (default: europe-west4) |
SENTRY_AUTH_TOKEN | Masked, Protected | Sentry access token with read permissions |
SENTRY_ORG_SLUG | Regular | Your Sentry organization slug |
2. Configure GCP Workload Identity Federation
Set up OIDC trust between GitLab and GCP:
- Create a Workload Identity Pool in GCP
- Add GitLab as an OIDC provider
- Grant the service account
aiplatform.userrole for Vertex AI
2. Include Template in Your Project
Add to your project's .gitlab-ci.yml:
stages:
- build
- test
- bugfix # Add this stage
include:
- project: 'your-group/sentry-bugfixer'
file: '/bugfixer.yml'
ref: main
sentry-bugfix:
extends: .sentry-bugfix
3. Create a Pipeline Schedule
In your project: CI/CD → Schedules → New schedule
| Setting | Value |
|---|---|
| Description | Sentry Bug Fixer |
| Interval | 0 */6 * * * (every 6 hours) |
| Target branch | main |
Configuration
Variables
Override these variables in your project's job definition:
| Variable | Default | Description |
|---|---|---|
SENTRY_PROJECT_SLUG | $CI_PROJECT_NAME | Sentry project to query (defaults to GitLab project name) |
MAX_ISSUES | 5 | Maximum issues to process per run |
Example with Custom Configuration
sentry-bugfix:
extends: .sentry-bugfix
variables:
SENTRY_PROJECT_SLUG: "my-custom-sentry-project"
MAX_ISSUES: "3"
Project-Specific Context (Optional)
Create a CLAUDE.md file in your project root to provide context:
# Project Context
## Tech Stack
- Language: TypeScript
- Framework: Next.js
- Testing: Jest + React Testing Library
## Code Standards
- Use TypeScript strict mode
- Follow existing patterns in the codebase
- Add tests for bug fixes when possible
## Build & Test Commands
- Run tests: `npm test`
- Type check: `npm run typecheck`
- Lint: `npm run lint`
Security
- Job Isolation: Each job runs in a fresh, isolated container
- No persistent state: Environment is destroyed after each run
- MR-based changes: All fixes go through merge requests for review
- Branch protection: Your existing protection rules still apply
- Masked variables: Secrets are never exposed in job logs
Deduplication
The system prevents duplicate MRs through:
- Branch naming: Uses
bugfix/sentry-{ISSUE_ID}pattern - Claude instructions: Skips issues with existing MRs/branches
- Sentry issue ID: Each issue only gets one fix attempt
Troubleshooting
| Issue | Solution |
|---|---|
| Job times out | Reduce MAX_ISSUES or increase timeout |
| Claude can't access Sentry | Check SENTRY_AUTH_TOKEN is valid and masked |
| MRs not being created | Ensure runner has git push permissions |
| Fixes don't compile | Add CLAUDE.md with build/test instructions |
| Too many MRs | Reduce schedule frequency or MAX_ISSUES |
Cost Considerations
- GitLab CI minutes: ~30-60 min per run depending on issue count
- Claude API: Variable based on codebase size and issue complexity
- Recommendation: Start with
MAX_ISSUES=1to test, then increase
Manual Trigger
You can manually trigger the bugfix job from:
- CI/CD → Pipelines → Run pipeline (select branch, run)
- The job only runs on
scheduleorweb(manual) triggers
Requirements
- GitLab 14.0+ (for
includewithproject) - Node.js 24+ (used in the job image)
- Sentry project with unresolved issues
- Anthropic API access
License
MIT
Related Skills
Frontend Typescript Linting.mdc
TypeScript and ESLint rules that MUST be followed when creating, modifying, or reviewing any file under apps/frontend/, including .ts, .tsx, .js, and .jsx files. Also apply when discussing frontend li...
2. Apply Deepthink Protocol (reason about dependencies
risks