OmniscioGuidesExamplesFix a failing CI run
Claude Code Action: fix a failing CI run
This workflow waits for your CI to fail, reads the failing job's log, and pushes a candidate fix to a branch of its own. Save it as .github/workflows/auto-fix-ci.yml on your default branch — GitHub only runs a workflow_run workflow whose file exists there.
It is also the one that needs steps outside the action — a branch to work on, a way to read the failed run's logs, and a guard so a failed fix does not trigger another fix. All of that is in Anthropic's example, reproduced below with one change: the prompt is written out instead of calling a slash command.
Last checked against Anthropic's documentation and the action's examples on November 25, 2026. By the Omniscio team. Updated .
When it runs
On workflow_run — the completion of another workflow, which the workflows: list names. Three conditions narrow it further, all in the job's if::
- The watched run failed.
github.event.workflow_run.conclusion == 'failure'. A cancelled or timed-out run is a different conclusion and is skipped. - The run belongs to a pull request.
github.event.workflow_run.pull_requests[0]must exist, which also excludes fork pull requests from the job. - It is not already a fix. A branch whose name starts with
claude-auto-fix-ci-is skipped — the prefix this workflow gives its own fix branches.
The trigger name has to match your CI workflow's name: exactly. That is the first thing to check when a run never appears.
Source: examples/ci-failure-auto-fix.yml, read November 25, 2026.
The workflow
Anthropic's examples/ci-failure-auto-fix.yml, with three changes, all of them disclosed: the published prompt begins with /fix-ci, a slash command the action's repository does not ship, so the instruction is written out in its place and carries the same variables; the comment lines are dropped; and two explanatory comments inside the file — the header note and the # Required for OIDC token exchange beside id-token: write — are quoted in the prose instead. Every trigger, permission, step, input and tool is as published.
name: Auto Fix CI Failures
on:
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
contents: write
pull-requests: write
actions: read
issues: write
id-token: write
jobs:
auto-fix:
if: |
github.event.workflow_run.conclusion == 'failure' &&
github.event.workflow_run.pull_requests[0] &&
!startsWith(github.event.workflow_run.head_branch, 'claude-auto-fix-ci-')
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
with:
ref: ${{ github.event.workflow_run.head_branch }}
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup git identity
run: |
git config --global user.email "claude[bot]@users.noreply.github.com"
git config --global user.name "claude[bot]"
- name: Create fix branch
id: branch
env:
HEAD_BRANCH: ${{ github.event.workflow_run.head_branch }}
RUN_ID: ${{ github.run_id }}
run: |
SAFE_BRANCH=$(printf '%s' "$HEAD_BRANCH" | tr -cd 'a-zA-Z0-9/_.-')
BRANCH_NAME="claude-auto-fix-ci-${SAFE_BRANCH}-${RUN_ID}"
git checkout -b "$BRANCH_NAME"
echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT"
- name: Get CI failure details
id: failure_details
uses: actions/github-script@v7
with:
script: |
const run = await github.rest.actions.getWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }}
});
const jobs = await github.rest.actions.listJobsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }}
});
const failedJobs = jobs.data.jobs.filter(job => job.conclusion === 'failure');
let errorLogs = [];
for (const job of failedJobs) {
const logs = await github.rest.actions.downloadJobLogsForWorkflowRun({
owner: context.repo.owner,
repo: context.repo.repo,
job_id: job.id
});
errorLogs.push({
jobName: job.name,
logs: logs.data
});
}
return {
runUrl: run.data.html_url,
failedJobs: failedJobs.map(j => j.name),
errorLogs: errorLogs
};
- name: Fix CI failures with Claude
id: claude
uses: anthropics/claude-code-action@v1
with:
prompt: |
Failed CI Run: ${{ fromJSON(steps.failure_details.outputs.result).runUrl }}
Failed Jobs: ${{ join(fromJSON(steps.failure_details.outputs.result).failedJobs, ', ') }}
PR Number: ${{ github.event.workflow_run.pull_requests[0].number }}
Branch Name: ${{ steps.branch.outputs.branch_name }}
Base Branch: ${{ github.event.workflow_run.head_branch }}
Repository: ${{ github.repository }}
The CI workflow failed on this branch. Read the error logs
below, find the cause, fix it in the checked out code, and
commit the fix to this branch. Do not change the tests to
make them pass, and do not merge anything.
Error logs:
${{ toJSON(fromJSON(steps.failure_details.outputs.result).errorLogs) }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
claude_args: "--allowedTools 'Edit,MultiEdit,Write,Read,Glob,Grep,LS,Bash(git:*),Bash(bun:*),Bash(npm:*),Bash(npx:*),Bash(gh:*)'"The original file also carries a security note at the top, and it is worth reading in place. In its words: this workflow checks out the pull request branch and runs build and test commands against it with elevated permissions, so code from that branch executes in a trusted context with access to secrets and the ability to push. It should only be used where everyone with write access is fully trusted.
Source: examples/ci-failure-auto-fix.yml; the slash commands the repository ships are under .claude/commands. Read November 25, 2026.
What each key does
| Key | What it does here |
|---|---|
workflows: ["CI"] | The name of the workflow to watch. It must match that file's name: exactly, not its file name. |
types: [completed] | Fires when the watched run finishes, whether it succeeded or failed. The job's if: is what narrows it to failures. |
if | Three conditions: the run failed, it belongs to a pull request, and its branch is not already an auto-fix branch. |
actions/checkout with ref | Checks out the branch the failed run used, so Claude is looking at the code that failed rather than the default branch. fetch-depth: 0 gives it history. |
| The git identity step | Sets the author for commits made in this job, so the history says who made them. |
| The fix-branch step | Strips anything unsafe from the branch name, then creates claude-auto-fix-ci-<branch>-<run id> and exports it as an output. The run id keeps two fixes of the same branch apart. |
actions/github-script | Reads the failed run, lists its jobs, keeps the failed ones, and downloads each one's log. The result is the JSON the next step reads. |
prompt | Carries the identifiers and the logs as text. Everything Claude knows about the failure arrives this way — that is why the log download step exists at all. |
claude_args | Names the tools the fix needs: edits, search, git, a package manager, and gh. Without them a plain prompt has no shell access. |
Two of those deserve a second look before you copy them. The actions: read permission is what lets the github-script step list jobs and download logs; without it that step fails and there is nothing for Claude to read. And the third if: condition is the loop guard: a fix that fails again produces a run on a branch already carrying the prefix, so it does not trigger another fix.
Source: examples/ci-failure-auto-fix.yml; "Run on a schedule" in Anthropic's GitHub Actions page explains the same rule that a plain prompt has no shell or GitHub API access until tools are granted. Read November 25, 2026.
Secrets and permissions
ANTHROPIC_API_KEY— the credential, as everywhere else. A subscription token substitutesclaude_code_oauth_token.contents: write— to push the fix branch.pull-requests: write— for the pull request the failed run belongs to, and the pre-filled pull request link Claude produces when it pushes the fix branch.actions: read— for the log-download step. This is the permission that makes the whole workflow work.issues: write— carried by the published file. Its prompt never asks for an issue comment, so this is the one permission you can drop without changing what the workflow does.id-token: write— the App exchange. The checkout step passesGITHUB_TOKENfor the fetch; the action itself still authenticates as the App for its own push.
What you are trusting. This job runs code from the pull request's branch, with a secret in the environment and write access to the repository. Anthropic's own warning says it plainly and adds the detail that matters: the pull_requests[0] check limits it to pull requests from inside the repository, but anyone who can push a branch there controls what code runs. Do not use it in a repository that accepts contributions from people you do not trust.
What does not protect you here. The action denies commands that run repository code when a pull request's author has no write access — but Anthropic's guide says plainly that runs on workflow_run, workflow_dispatch, repository_dispatch and schedule events are not covered by that check, and this is a workflow_run. What workflow_run does get is its own check: the actor that started the upstream run must have write access, or the action stops before running Claude. Fork pull requests are skipped by default, and the file's pull_requests[0] condition keeps fork runs out a second time.
Anthropic's guide also carries one instruction this workflow cannot follow as written: do not check out an untrusted ref into the workspace root before the action. The published file does exactly that — ref: ${{ github.event.workflow_run.head_branch }} at the workspace root. That is the risk, stated as plainly as the source states it, and it is why the warning at the top of this page is not boilerplate.
Sources: the security note in examples/ci-failure-auto-fix.yml; "Using this action with pull_request_target or workflow_run" and "Running code from pull requests" in the Security guide. Read November 25, 2026.
How to confirm it ran
- A new run named
Auto Fix CI Failures. It appears in the Actions tab right after the failedCIrun. Its log carries the failed job names, because the prompt passes them to Claude as text. - A branch named
claude-auto-fix-ci-…. If the fix worked, the branch exists with Claude's commit on it. If it does not exist, the branch step or the push failed, and the log says which. - The run log. The full execution trace, including the log text handed to Claude. If that text is empty, the github-script step got nothing — most often a missing
actions: readpermission. - The pull request link. Claude does not open the pull request: it pushes the commit and prints a pre-filled pull request link into the run log, which is where you go to open it.
Sources: the step outputs in examples/ci-failure-auto-fix.yml; "How can I debug what Claude is doing?" in the FAQ. Read November 25, 2026.
The common failure
Nothing runs. Almost always the trigger name. workflows: ["CI"] matches a workflow whose name: is exactly CI. If your CI file has no name:, give it one — that is what the list matches, not the file name. Then check that the failing run actually belongs to a pull request: a failure on a branch with no pull request does not satisfy the second condition.
The run starts and does nothing useful. Two causes:
- The log download step failed. Without
actions: readit cannot list jobs or fetch logs, so the prompt carries no error text and Claude is guessing. - No tools granted. A plain prompt has no shell or GitHub API access until
--allowedToolsnames what it may run. If your project uses a package manager the list does not mention — pnpm, cargo, go — add it.
The fix branch is pushed but no pull request appears. That is by design. Claude pushes commits and gives you a pre-filled pull request link rather than opening the pull request, so branch protection still applies and the merge stays your decision.
Sources: examples/ci-failure-auto-fix.yml for the trigger and permissions; "Run on a schedule" in Anthropic's GitHub Actions page for the tool rule; "Why won't Claude create a pull request?" in the FAQ. Read November 25, 2026.
Where these answers come from
- examples/ci-failure-auto-fix.yml — the workflow on this page, and its security note.
- Security — fork pull requests, and the rule about running code from pull requests.
- Claude Code GitHub Actions — automation mode, the tool rule, and troubleshooting.
- FAQ — CI results, commits, and why Claude does not open pull requests.
- The setup this workflow assumes is on Claude Code GitHub Actions; the other four workflows are on the examples hub.
Common questions
Why does the fix workflow never start?
The workflows: entry must match the watched workflow's name: exactly. Then check that the failed run belonged to a pull request and that the branch is not already an auto-fix branch.
Is it safe to let Claude push CI fixes?
Only where everyone with write access is trusted. The job runs code from the pull request branch with a secret and write access, which is exactly what Anthropic's own warning says.
Can this loop forever?
Not through this route: the third condition under When it runs skips a branch already carrying the prefix this workflow creates.
Does Claude open the pull request?
No. It pushes the commit to the fix branch and gives you a pre-filled pull request link.