Workflow recipe
Fix a failing CI run with a coding agent
It reads the GitHub Actions logs, explains the cause and fixes it, with stop rules so it never loops or weakens tests.
Bookmark
Bookmarks are kept in your free account, so you can find this page again on any device.
Sign in to bookmarkOn this page
To fix failing CI with an AI agent, first confirm the failure is real, then give the agent the GitHub Actions logs and ask for a diagnosis before any fix. Approve the fix with explicit rules (no skipped tests, loosened lint or added retries), let it verify locally and push once, then review it like any other change.
A failing CI run is a good job for a coding agent. The evidence is in the logs, the fix is usually small, and the test suite tells you whether it worked. It is also a job where agents go wrong in predictable ways: skipping the failing test, loosening a lint rule, adding a retry, or pushing fix after fix while the run history fills with red.
The loop below adds a short list of stop conditions on top. It works with a plain prompt, and two published skills make it smoother: Sentry’s iterate-pr and OpenAI’s gh-fix-ci.
TerminalAbout 5 min
1. Check the failure is real before involving the agent
Look at what failed and whether it is your change:
gh pr checks 1234
gh run view <run-id> --log-failedgh pr checks lists every check with its state and a link. gh run view --log-failed prints only the logs of failed steps, which is what the agent needs. Rule out the cheap explanations first: does the same check fail on the main branch? Did a runner, registry or external service time out? For an infrastructure blip, gh run rerun <run-id> --failed re-runs the failed jobs and costs no agent time.
TerminalAbout 5 min
2. Optionally install a CI skill
A skill gives the agent a tested procedure and helper scripts so it does not improvise the gh commands. Install Sentry’s iterate-pr, pinned to the commit we reviewed:
npx skills add getsentry/skills@a582c51ee29d0f35e6ac321340796f77d43da733 --skill iterate-pr -a claude-codeIt fetches checks and review feedback with bundled scripts, fixes failures, verifies locally, pushes and monitors the next run. It also stops at human gates such as required approvals or draft status. Read its page before installing: it runs scripts and pushes commits.
OpenAI’s gh-fix-ci is narrower: it inspects failing checks, summarises the logs, drafts a fix plan and waits for your approval before changing anything. Its source repository, openai/skills, is deprecated, so check whether a maintained copy exists before you install it. Either works with the prompts below; so does no skill at all.
Claude CodeAbout 10 min
3. Ask for a diagnosis, not a fix
Start the agent on the pull request’s branch and ask it to explain before it edits anything:
Read the diagnosis. You are checking one thing: does the stated cause explain the error? “Test fails because the date is formatted in the runner’s time zone” is a diagnosis. “Test fails, I will update it” is not. If the agent cannot state a cause, the systematic-debugging skill walks it through reproducing and narrowing down the failure instead of guessing.
Claude CodeAbout 15 min
4. Approve the fix with explicit rules
When the diagnosis makes sense, let it fix, with the rules that stop the common bad fixes:
The stop conditions matter more than the fix instructions. An agent that is allowed to keep going will eventually make the check pass by changing what the check checks.
GitHubAbout 5 min
5. Watch the next run, once
After the push, watch the checks:
gh pr checks 1234 --watchIf everything goes green, move on to review. If the same check fails again, do not ask the agent to “try again”. Give it the new log and ask whether its diagnosis was wrong. A second failure usually means the first diagnosis described a symptom.
GitHubAbout 5 min
6. Review the fix like any other change
Read the diff before merging, looking specifically for the patterns the rules banned: skip, xfail, only, eslint-disable, # type: ignore, raised timeouts, changed snapshots, edits to CI config or coverage settings. If any appear, ask why. Sometimes they are the right call, such as a snapshot that should change, but that decision belongs to a person who knows the code.
The commit message should explain the cause. Six months from now, “fix CI” helps nobody; “use UTC in invoice date test, runner time zone differs from local” does.
Check it worked
Verification checklist
0 of 6 done
When it goes wrong
If the failure does not reproduce locally, compare environments before changing code: tool versions, operating system, time zone, locale, environment variables and secrets. Ask the agent to list the differences it can see between the workflow file and your machine. Many “CI only” failures are a missing environment variable or a different Node or Python version.
If the agent keeps proposing changes to the test rather than the code, ask it which one is wrong according to the spec or the pull request description. Sometimes the test is right and the change broke behaviour on purpose; that conversation belongs in the pull request.
If logs are huge, ask for the first error only. Later errors are often consequences of the first one. --log-failed already trims most noise.
If the check runs on an external CI service (Buildkite, CircleCI), gh run view cannot fetch its logs. Paste the relevant log section into the prompt, or use that service’s CLI.
Variations
With iterate-pr installed, a single request such as “iterate on this PR until CI passes” runs the whole loop, including review comments graded high and medium. Add the stop conditions from step 4 to the request; the skill stops at approval gates but not at “pushed twice”.
With Codex, /review in the CLI checks your local diff before you push, which catches some failures before CI sees them. The same diagnose-then-fix prompts work unchanged.
To prevent the failures that agents cause most, add guardrails: a hook that blocks git push --force and edits to workflow files (guardrail hooks), and a line in your instruction file listing the commands that must pass before any push.
Related coding agent guides
Running coding agents headless in CI covers the next step, letting an agent act inside the pipeline itself, and coding agent permissions and sandboxing explains what to allow it. When the failure turns out to be an intermittent test, fix flaky tests with the Playwright healer instead, and for a bug that shows up outside CI, debug with AI starts by reproducing it before any fix. Reviewing AI-written code applies to the fix too. More recipes are in the AI workflow examples hub.
Outcome and tools
- Outcome
- A red pull request turned green by a root-cause fix you approved, or a clear written diagnosis when the agent should stop.
- For
- Developers
- Variants for
- Claude Code, Codex, Cursor
Check your understanding
Fix failing CI with an agent quiz
Confirming the failure is real, CI skills, asking for a diagnosis first, approving a fix with rules and stop conditions, watching one run, and reviewing the fix for banned patterns.
7 questions · pass mark 70%
Review
Related
- Run coding agents headless in CI
Run claude -p and codex exec in GitHub Actions with pinned versions, narrow permissions, scoped secrets and separate jobs for writing back to the pull request.
- Code review with Claude Code on every pull request
Write your checklist once, dry-run it locally, then review every pull request in GitHub Actions and post the findings.
- Set up guardrail hooks for your coding agent
Block dangerous commands in Claude Code with PreToolUse hooks and deny rules, so the agent cannot force-push, wipe files or edit secrets. Test them first.
- Upgrade a dependency with an AI coding agent, without surprises
Get an impact list from the migration guide, bump on a branch, let the agent fix with guardrails, then compare old and new output.
- Rolling out coding agents to a team
Roll out coding agents to a team: shared instruction files, permissions and hooks, spec-first work, agent review in CI and vetted Agent Skills for everyone.