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.

Views1
PublishedJan 14, 2026

Loading actions...

5 minBeginnerpromptSingle file

Skill content

Main instructions and any bundled files for this skill.

markdown

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

  1. Scheduled Trigger: Pipeline runs on a schedule (e.g., every 6 hours)
  2. Issue Discovery: Claude queries Sentry MCP for unresolved issues
  3. Analysis: For each issue, Claude:
    • Gets full stack trace from Sentry
    • Uses Seer AI for root cause analysis
    • Reads relevant source files
  4. Fix Implementation: Claude edits files to fix the bug
  5. MR Creation: Changes are committed, pushed, and an MR is created via GitLab MCP
  6. 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

VariableTypeDescription
GCP_WORKLOAD_IDENTITY_PROVIDERRegularGCP Workload Identity Provider resource name
GCP_SERVICE_ACCOUNTRegularGCP Service Account email for Vertex AI
GCP_PROJECT_IDRegularGCP Project ID with Vertex AI enabled
CLOUD_ML_REGIONRegularVertex AI region (default: europe-west4)
SENTRY_AUTH_TOKENMasked, ProtectedSentry access token with read permissions
SENTRY_ORG_SLUGRegularYour Sentry organization slug

2. Configure GCP Workload Identity Federation

Set up OIDC trust between GitLab and GCP:

  1. Create a Workload Identity Pool in GCP
  2. Add GitLab as an OIDC provider
  3. Grant the service account aiplatform.user role 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

SettingValue
DescriptionSentry Bug Fixer
Interval0 */6 * * * (every 6 hours)
Target branchmain

Configuration

Variables

Override these variables in your project's job definition:

VariableDefaultDescription
SENTRY_PROJECT_SLUG$CI_PROJECT_NAMESentry project to query (defaults to GitLab project name)
MAX_ISSUES5Maximum 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:

  1. Branch naming: Uses bugfix/sentry-{ISSUE_ID} pattern
  2. Claude instructions: Skips issues with existing MRs/branches
  3. Sentry issue ID: Each issue only gets one fix attempt

Troubleshooting

IssueSolution
Job times outReduce MAX_ISSUES or increase timeout
Claude can't access SentryCheck SENTRY_AUTH_TOKEN is valid and masked
MRs not being createdEnsure runner has git push permissions
Fixes don't compileAdd CLAUDE.md with build/test instructions
Too many MRsReduce 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=1 to 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 schedule or web (manual) triggers

Requirements

  • GitLab 14.0+ (for include with project)
  • Node.js 24+ (used in the job image)
  • Sentry project with unresolved issues
  • Anthropic API access

License

MIT

Share: