CC-301g · Module 2

Automated Fix Loops

4 min read

The automated fix loop connects CI failure notifications to Claude Code sessions that diagnose and fix the issue without human intervention. The architecture: CI fails → webhook notifies a monitoring system → the system launches a Claude Code session with the failure context → Claude diagnoses and fixes → commits and pushes → CI re-runs. If the fix succeeds, the loop closes. If it fails after three attempts, a human is notified.

This sounds like science fiction, but the components are all available today. GitHub Actions can trigger on workflow failure events. Claude Code can be invoked programmatically with the -p flag (prompt mode). Git operations are fully automated. The only engineering challenge is the orchestration layer that connects these pieces and implements the retry/escalation logic.

name: Auto-Fix CI Failures
on:
  workflow_run:
    workflows: ['CI']
    types: [completed]

jobs:
  fix:
    if: github.event.workflow_run.conclusion == 'failure'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.workflow_run.head_branch }}
      - name: Get failure logs
        run: |
          gh run view ${{ github.event.workflow_run.id }} --log-failed > failure.log
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      - uses: anthropics/claude-code-action@v1
        with:
          anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
          prompt: 'Read failure.log. Diagnose and fix the CI failure.'