Guide Agent Setup

Codex GitHub Integration: Tag @codex on Pull Requests

Connect the repository once, turn on review, then mention @codex on the pull request where the work already is.

Last checked against the sources on November 23, 2026

Two ways to run Codex on GitHub

"Codex on GitHub" means one of two different setups, and most confusion comes from mixing them up:

  • The Codex GitHub integration. You connect a repository to Codex from your ChatGPT account, and anyone on the team can mention @codex on a pull request. Codex runs on OpenAI's cloud, reacts to the comment and posts a review, or starts a Codex task with the pull request as context. Nothing is added to .github/workflows/.
  • The Codex GitHub Action (openai/codex-action@v1). You commit a workflow that runs the Codex CLI on your own Actions runners with an OpenAI API key, on whatever event you choose. It's the do-it-yourself path for CI checks, custom review bots and scheduled jobs.
GitHub integration (@codex)GitHub Action
Triggered by@codex review, @codex security review or another @codex request in a PR comment, or automatic review on new pull requestsAny GitHub Actions event your workflow listens for
Runs onCodex Cloud, OpenAI's hosted containersYour GitHub Actions runners, using your Actions minutes
Paid withA ChatGPT plan that includes Codex cloud features (Plus, Pro, Business, Enterprise)An OpenAI API key, billed at API rates
Set up inCodex settings in ChatGPTA workflow file and one repository secret
Posts to GitHub asThe ChatGPT Codex Connector GitHub AppWhatever token your workflow gives the step that posts

If you want the same tag-it-on-the-PR flow with Anthropic's agent instead, see our guide to Claude Code GitHub Actions, which works the other way round: a workflow in your repository rather than a hosted integration.

Cursor's pull request reviewer, Bugbot, is also a hosted integration, started by a bugbot run comment rather than an @ mention; see our guide to Cursor Bugbot.

Before you start

  • A ChatGPT plan with Codex cloud features. OpenAI's Codex pricing page lists GitHub code review and automatic PR reviews on Plus, Pro, Business and Enterprise, and not on API-key-only access. Free and Go don't list them; check the pricing page for the current table.
  • A repository on github.com. GitLab merge request review is in beta and set up separately; this guide covers GitHub only.
  • Push or admin permission on the repository, which Codex asks for before you can change its code review settings.
  • Permission to install a GitHub App on the account or organization that owns the repository, or an organization owner who will approve it.
  • On Business and Enterprise workspaces, Codex cloud and GitHub access are controlled by workspace admins. If you can't see the Codex settings described below, ask an admin to enable them.

Connect GitHub to Codex

  1. Sign in to ChatGPT, open Codex, choose Work in → Cloud, and select Create environment (also under Settings → Codex Cloud → Environments).
  2. Select Connect GitHub when prompted. GitHub asks you to install the ChatGPT Codex Connector app; choose the account or organization and give it only the repositories Codex should see.
  3. Pick the repositories for the environment and let Codex inspect them, install dependencies and test the setup. Review the setup report, then publish the environment.
  4. Add an AGENTS.md at the repository root with your build, lint and test commands. Codex reads it in cloud tasks to find how to check its work, and in reviews to find your review rules.

OpenAI's docs say the older Codex Cloud (Legacy) environment settings, at chatgpt.com/codex/settings/environments, still back Code Review and the GitHub and Linear integrations, and that the legacy experience is due to be retired. If a repository you connected doesn't show up in code review settings, check that it also has an environment there.

Each person who tags @codex needs their own Codex account linked to their GitHub account. A comment from a teammate who hasn't connected gets a reply asking them to create a Codex account and connect GitHub, not a review.

@codex review and automatic reviews

  1. Go to Codex code review settings at chatgpt.com/settings/code-review.
  2. Choose the repository and turn on Automatic review under Review code.
  3. On any pull request in that repository, comment @codex review.
  4. Codex reacts with 👀 while it works, then posts a standard GitHub code review on the pull request, the same way a teammate would.
@codex review
@codex review for issues in the database migration
  • On GitHub, Codex flags only P0 and P1 issues, so expect a few comments on serious problems rather than style notes. Leave formatting and lint to CI.
  • Text after @codex review focuses that one review, as in the second line above.
  • To have every pull request reviewed without a comment, turn on Automatic review under Personal preferences in the same settings page and choose when it runs with Review trigger.
  • A review posts comments only. It doesn't approve or merge, so keep a person as the required reviewer.

Teach the review your rules in AGENTS.md

Codex looks for AGENTS.md files in the repository and follows the code review rules that apply to each changed file. Put them under a ## Code Review Rules heading, grouped with ### headings:

## Code Review Rules

### Database

- Flag any migration that drops or renames a column in the same release that stops reading it.
  Safe path: ship the code change first, drop the column in a later migration.

### Public API

- Flag changes to response fields under api/v1 without a matching entry in CHANGELOG.md.
  • Repository-wide rules go in the root AGENTS.md; rules for one service go in a nested file such as services/billing/AGENTS.md. Codex applies the root file plus the more specific one for each changed path.
  • Start with two or three rules your reviewers keep explaining by hand, and say what the safe path is, so Codex can tell a real problem from expected behavior.
  • Open a representative pull request, run @codex review, and cut any rule that produces noise. Rules guide the review; they don't replace tests, branch protection or required approvals.

In a monorepo, nested AGENTS.md files are also how each package keeps its own conventions; our piece on coding agent setup on Nx or Turborepo monorepos covers how those files resolve.

@codex security review

Security Review is a separate, deeper pass on security risks in a pull request, in research preview at the time of writing. Turn it on in the same code review settings: under Review security vulnerabilities, switch on Auto security review, choose whose pull requests it reviews, and set Trigger to Whenever code review runs to pair it with every code review. To ask for one by hand, comment @codex security review. Findings are posted on the pull request, and the full report is on the Security Report tab of the linked Codex task. Expect some overlap with ordinary code review, which also catches security issues.

Asking @codex to change code

A mention that isn't a review request starts a Codex Cloud task on the repository's environment, with the pull request as context:

@codex fix the failing test in the checkout flow
@codex address the review comments above
  • Codex works in its own container: it checks out the repository, runs the environment's setup, then edits code and runs the checks it finds in AGENTS.md.
  • Open the linked task in Codex to read the diff and the work log before anything lands. How a task's changes reach GitHub (a new pull request or a push to the existing branch) depends on the task and has changed over time, so check the task's result before assuming the PR was updated.
  • Write the request the way you'd write it for a teammate: the failing check, the expected behavior, and what not to touch. Vague requests use more of your plan's usage and come back further from what you wanted.
  • Your branch rules still apply to anything Codex pushes. See least-privilege branch protection rules for agent commits.

The Codex GitHub Action

Use openai/codex-action@v1 when you want Codex to run inside your own CI: a review bot with your own prompt, a check that gates merges, or a scheduled migration. It installs the Codex CLI, starts a proxy to the Responses API with your key, and runs codex exec. You need an OPENAI_API_KEY repository secret, a Linux or macOS runner, and a checkout step before the action. This trimmed workflow from OpenAI's docs reviews each new pull request and posts the result as a comment:

name: Codex pull request review
on:
  pull_request:
    types: [opened, synchronize, reopened]
jobs:
  codex:
    runs-on: ubuntu-latest
    permissions:
      contents: read
    outputs:
      final_message: ${{ steps.run_codex.outputs.final-message }}
    steps:
      - uses: actions/checkout@v5
        with:
          ref: refs/pull/${{ github.event.pull_request.number }}/merge
          fetch-depth: 0
          persist-credentials: false
      - name: Run Codex
        id: run_codex
        uses: openai/codex-action@v1
        with:
          openai-api-key: ${{ secrets.OPENAI_API_KEY }}
          prompt-file: .github/codex/prompts/review.md
  post_feedback:
    runs-on: ubuntu-latest
    needs: codex
    if: needs.codex.outputs.final_message != ''
    permissions:
      issues: write
      pull-requests: write
    steps:
      - uses: actions/github-script@v7
        env:
          CODEX_FINAL_MESSAGE: ${{ needs.codex.outputs.final_message }}
        with:
          script: |
            await github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.payload.pull_request.number,
              body: process.env.CODEX_FINAL_MESSAGE,
            });

Two jobs keep the key and the write token apart: the Codex job can only read the repository, and the job that can comment never runs Codex. Put your review instructions in the prompt file (or inline with prompt; use one or the other).

Locking it down

  • Give the ChatGPT Codex Connector app only the repositories Codex should touch, not every repository in the organization. Our piece on GitHub App permission scopes for coding agents covers how to weigh what an app asks for.
  • Keep agent internet access off in cloud environments unless a task needs it, and allow only the domains it needs. In the legacy environments that back the GitHub integration, setup scripts get internet access and the agent phase doesn't by default; secrets there are available to setup scripts only and are removed before the agent runs.
  • Treat pull request and issue text from outside contributors as untrusted. Instructions hidden in an issue body or HTML comment can steer an agent; read the raw text before you tag @codex on it.
  • In the GitHub Action, leave safety-strategy at its default drop-sudo (or run Codex as an unprivileged-user), and use the narrowest permission-profile or sandbox that still finishes the job. read-only alone doesn't protect secrets.
  • Only users with write access can trigger the action by default. Add accounts with allow-users or allow-bots one by one rather than opening it up, and never run it on untrusted pull request code with secrets available.
  • If two agents can comment on the same repository, make sure one can't trigger the other. See running multiple coding agents in the same repository.

When @codex doesn't respond

SymptomCheck
No 👀 reaction, no reviewCode review is on for the repository in chatgpt.com/settings/code-review, the repository is connected to Codex, and the comment says exactly @codex review
Reply asks you to create a Codex account and connect GitHubThe commenter's GitHub account isn't linked to a Codex account. Each person who tags @codex connects their own
Automatic reviews don't runAutomatic review is on for the repository and under Personal preferences, and the pull request event matches the Review trigger setting
Review works, but other @codex requests failThe repository has a working cloud environment; start a task against it directly in Codex to see the error
Action fails with both prompt inputs setUse either prompt or prompt-file, not both
Action can't reach the APIThe OPENAI_API_KEY secret exists and is valid; the proxy only starts when openai-api-key is set

What it costs

The GitHub integration runs on your ChatGPT plan's Codex usage. OpenAI counts reviews run through GitHub (a @codex review comment or an automatic review) as Code Review usage, separate from reviews you run locally, which count toward general usage. The GitHub Action bills your API key at API rates and spends your Actions minutes. Limits and prices change, so check OpenAI's Codex pricing page and GitHub's Actions billing documentation rather than a figure copied into a guide.

Sources

  1. Review GitHub pull requests with Codex - OpenAI Developers
  2. Cloud environments - Codex docs
  3. Codex Cloud (Legacy) - Codex docs
  4. Codex Cloud (Legacy): internet access - Codex docs
  5. Codex GitHub Action - OpenAI Developers
  6. openai/codex-action on GitHub
  7. ChatGPT Codex Connector - GitHub Apps
  8. Codex pricing - OpenAI Developers

← All guides