Skip to content
Agents tracked: 479 Releases (7d): 721 Agent status: all upSince last limit reset: Claude 39d · Codex 1d Updated Nov 1, 2026
Recipe

Auto-fix failing CI with the Codex GitHub Action

When your CI workflow fails, a second GitHub Actions workflow runs Codex on the failing commit, asks it to reproduce the failure and make the smallest fix, and opens a pull request with the patch. The job that runs Codex can only read the repository, and the job that pushes never sees the OpenAI API key.

The problem

A red CI run on a branch usually waits until someone has time to read the logs, reproduce the failure and push a fix, even when the fix is small. Handing that first attempt to an agent is useful, but running an agent in CI with write access and an API key in the same job exposes the key to build scripts, tests and dependency hooks.

Steps

  1. Store your OpenAI API key as a repository secret named OPENAI_API_KEY; do not set it as a job-level environment variable in jobs that check out or run repository code.
  2. Add a workflow that triggers on workflow_run for your main CI workflow with types [completed], and run its first job only when the run's conclusion is failure.
  3. Give that job only contents read permission, check out the failing commit (workflow_run.head_sha) with persist-credentials set to false, and install dependencies before Codex starts.
  4. Run openai/codex-action@v1 with a prompt that names the failed workflow and commit and tells Codex to reproduce the failure with your test command, implement only the minimal fix, rerun the tests and leave unrelated files alone.
  5. Save Codex's local changes with git diff --binary into codex.patch and upload it as an artifact only when the patch is not empty.
  6. In a second job with contents write and pull-requests write but no API key, download the patch, apply it with git apply --index, push a codex/auto-fix branch named after the run ID and open a pull request against the failing branch with gh pr create.
  7. Adjust the setup and test commands to your stack (the docs example assumes Node.js), and review every generated pull request before merging.

From the official docs

- name: Run Codex
  uses: openai/codex-action@v1
  with:
    openai-api-key: ${{ secrets.OPENAI_API_KEY }}
    prompt: |
      The CI workflow "${{ github.event.workflow_run.name }}" failed for commit
      ${{ github.event.workflow_run.head_sha }}.
      Run `npm test --silent` to reproduce the failure. Identify the minimal
      change needed to make the tests pass, implement only that change, and
      run `npm test --silent` again.
      Do not refactor unrelated files.

Results

  • Every failed CI run triggers a Codex attempt on the exact failing commit, and any fix is saved as a patch artifact.
  • A separate job opens a pull request titled "Auto-fix failing CI via Codex" against the failing branch, with a note asking for review before merging.
  • The Codex job only has read access to the repository, and the job with write access never receives the OpenAI API key.

As reported by the source (OpenAI Codex docs (non-interactive mode)); AgentGid did not measure these figures.

Takeaway. Split agent CI automation into a read-only job that holds the key and a write job that holds no key, and pass only a patch between them.
AgentGid's take

This suits teams on GitHub Actions whose CI often breaks on small, local problems such as a failing unit test or a type error, and who already review every pull request. It helps less with flaky infrastructure or failures that need secrets the Codex job should not see. Watch for fixes that weaken a test instead of fixing the code; protect test folders with code owners if that matters to you. The action authenticates with an OpenAI API key, and per AgentGid's OpenAI Codex page (pricing checked Oct 6, 2026) API-key use is billed at API rates, separate from ChatGPT plans (Free $0, Go $8 a month, Plus $20 a month and up), so put a budget limit on the key. The Codex CLI itself is open source (Apache-2.0). This is a pattern from OpenAI's own docs, not a measured result. If your team works with Anthropic models, AgentGid also has a recipe for reviewing pull requests with Claude Code in GitHub Actions.

The agent used here

Similar use cases

Guides