A publication for engineering teams on delegating real software work to cloud-based AI agents, at scale, across existing workflows.
Agent SetupLong read

Codex CLI Configuration for Automated Pull Request Workflows

Organize agent responsibilities through configuration files, not individual prompts.

· 9 min read
Cover illustration for “Codex CLI Configuration for Automated Pull Request Workflows”
Agent Setup · October 19, 2026 · 9 min read · 2,007 words

Automated pull request workflows with Codex CLI depend on configuration more than on individual prompts. This guide explains how repository instructions, execution policy, review gates, and GitHub events connect the work from branch creation to merge readiness. The central requirement is a shared contract that tells every agent what to do, what it may change, and what evidence must exist before the work is complete.

Why the PR lifecycle is a configuration problem, not a prompting problem

Most teams use Codex for implementation but return to manual work after pushing a branch. That leaves local review, CI gating, and GitHub-native review comments out of the automated workflow, though agents can work on each of those surfaces. The practical gap is the configuration that connects those surfaces and gives each a defined responsibility.

The workflow has six stages, namely context intake, isolated implementation, local review, CI review, feedback and repair, and merge readiness. Each stage needs its own mix of instructions, permissions, and rules for when the work is done. A review agent should inspect changes without editing them, while a repair agent needs permission to write and instructions that limit the fix. Treating both as the same task either restricts useful work or grants unnecessary access.

The repository provides the common contract through AGENTS.md and .codex/config.toml. These files travel with the code, so worktrees, CI runners, and cloud agents inherit the same project rules. Prompts still define the immediate task, but they do not have to reconstruct the team's standards on every invocation.

Diagram: Six Stages of the Automated PR Lifecycle. Visualizes: Visualize the six sequential stages of the automated pull request workflow as a linear pipeline: 1) Context Intake, 2) Isolated Implementation, 3) Local Review, 4) CI Review, 5)…

Isolating agent work with git worktrees before any config is written

A dedicated git worktree per feature branch separates agent work from overlapping human edits and other agent sessions. Running everything in the main working tree can cause conflicts that configuration cannot fix. Each worktree instead gives a Codex session its own branch and file state.

Create the worktree with git worktree add ../feature-auth-refactor -b feature/auth-refactor. Then start the session with cd ../feature-auth-refactor && codex. The repository's project configuration and instructions are already present, so no separate per-session setup is required.

When a task needs a shared package outside that root, codex --cd ../feature-auth-refactor --add-dir ../shared-types extends access to the additional directory. The --add-dir flag grants write access beyond the main workspace without requiring unrestricted filesystem access. This preserves a defined working boundary while allowing the agent to reach the files its task actually needs.

What belongs in AGENTS.md and why it must be written before implementation begins

Write AGENTS.md before implementation because its rules apply to both code generation and review. If review standards are added afterward, the implementation agent may have already written code that the review agent must reject. The same file is read automatically by local /review, CI codex exec, and GitHub cloud review.

The ## Review guidelines section carries concrete review policy. Example rules include “All public API endpoints must have integration tests” and “Every database migration must be reversible”. Security rules can state “Do not log PII — flag as P0 if detected” and “Reject direct SQL string concatenation; require parameterized queries”. A severity rule can also say “Flag any function that grows too long as P1”. These instructions give implementation and review a common standard.

Commit conventions belong in the same file so generated messages follow Conventional Commits format, scope naming, and imperative mood. More specific rules can live deeper in the repository. A payments/AGENTS.md with payment-security requirements overrides the root instructions for files under payments/ but leaves other directories unchanged. The closest instruction file to a changed file wins, making directory scope part of the review contract.

Configuring.codex/config.toml for model routing, sandbox policy, and review profiles

Sandbox policy is the first execution decision because it determines what an agent can change. Use read-only for review and analysis, and workspace-write for code changes within the repository. Reserve danger-full-access for Docker or CI containers where the container itself supplies the isolation boundary. A shared runner is not equivalent to an isolated container.

Codex uses Seatbelt on macOS and Bubblewrap on Linux for native sandboxing. Select the mode through --sandbox or sandbox_mode in .codex/config.toml. Enterprise requirements can further constrain execution through /etc/codex/requirements.toml or macOS MDM using the com.openai.codex preference key requirements_toml_base64. Those policies can set rules for approval behavior, limit web search, and require an MCP server allowlist.

Named profiles separate task routing from interactive defaults. A [profiles.review] profile can target a high-reasoning model with approval_policy = "on-request" and run through codex -p review. Reserving that profile for a PR-level review rather than every edit concentrates the higher model cost at the quality gate. The review_model key in the [model] block separately pins the model for /review.

Project configuration can also declare the Atlassian Rovo MCP Server and Linear MCP server. For Atlassian, the transport endpoint is /v1/mcp, replacing the deprecated /v1/sse. This makes access to ticket context a project-level setting.

Running the local /review command as a pre-push quality gate

Local /review checks changes against the repository's standards before they take up CI time or need a person's attention. It is read-only and does not touch the working tree. Findings remain in the session transcript for comparison across iterations. Because it reads AGENTS.md automatically, the rules written before implementation now become the first quality gate.

The review scope can match the point reached in development. Branch comparison checks the diff against a chosen base and finds the merge base on its own. Uncommitted-change review covers staged, unstaged, and untracked modifications, while commit review targets a SHA or a recent commit. Custom instructions can narrow any of these scopes, for example to “focus on accessibility regressions”.

Findings use P0 for critical issues, P1 for important issues, and lower priorities through P3 for suggestions. The repository's guidelines say how to classify each kind of violation. The pre-commit hook pattern uses codex exec --sandbox=read-only --approval-mode=full-auto and blocks the commit when a P0 finding is reported.

For a programmatic gate, --output-schema requires parseable findings containing fields such as title, body, confidence_score, and code_location. The hook still needs logic that evaluates those findings. A schema used to gate on priority must include priority, since some review schemas leave it out.

Configuring openai/codex-action to gate PRs inside CI

openai/codex-action@v1 is an agent execution environment, so access control is a security boundary. By default, only users with write access can trigger it, while allow-users and allow-bots provide explicit allowlists. PR bodies, commit messages, and issue bodies are still untrusted prompt inputs and must be sanitized. Without that boundary, an author could inject instructions through material the agent reads.

The action installs Codex CLI, starts the Responses API proxy when given an API key, and runs codex exec under the specified permissions. Use read-only for review and workspace-write for fixes. The default drop-sudo safety strategy suits GitHub-hosted runners and revokes sudo for the rest of the job. Self-hosted runners that already have an unprivileged account use unprivileged-user, while self-hosted runners that are thrown away after use can also use drop-sudo. Windows needs unsafe, which must never be left on for multi-tenant runners.

Production prompts belong in a version-controlled prompt-file, such as .github/codex/prompts/review.md. Pin codex-version so CLI changes do not come as a surprise, and use output-file to keep the final message. Pass --output-schema through codex-args so logic that runs later can block on priority == 0.

Run Codex last in its job so unexpected changes to state cannot affect later steps. A later job can read the mapped final-message output and post findings through actions/github-script. Rotate keys immediately if proxy logs or action output may have exposed secrets.

Mapping GitHub event triggers to specific stages of the PR lifecycle

The action is event-agnostic, so GitHub Actions triggers determine when each task runs. The pull_request event with opened, synchronize, and reopened maps to diff review. That task needs a read-only sandbox and a prompt pointing to AGENTS.md.

A completed workflow_run with a failure check maps to build repair instead. This task needs workspace-write and a prompt to diagnose the failure, apply a minimal fix, verify tests pass, and avoid unrelated refactoring. Its output can feed peter-evans/create-pull-request to open a fix PR.

An issues event with opened maps to triage and an initial fix attempt, with prompt scope kept tight to avoid runaway changes. A pull_request_review_comment event with created maps to implementing specific reviewer feedback and needs workspace-write. An issue_comment event with created supports on-demand tasks through an authorized @codex mention. For that last surface, the requested task determines the permissions.

These events are not interchangeable. Wiring each to a distinct responsibility avoids redundant review work and leaves fewer gaps between a finding and its resolution.

Diagram: GitHub Events Mapped to PR Lifecycle Stages. Visualizes: Show five GitHub event triggers mapped to their corresponding PR stage, sandbox permission, and output action: (1) pull_request [opened/synchronize/reopened] → diff review →…

Automating the full ticket-to-PR pipeline with Jira and Linear context

Automation that starts with a ticket takes in context before implementation. The Jira pipeline coordinates MCP configuration, a Jira automation rule that fires GitHub Actions workflow_dispatch, and a prompt that tells codex exec to read ticket context. The prompt must use the issue's requirements. MCP access gives the agent the supporting material it needs to understand those requirements.

The label-triggered sequence begins when a developer adds codex-auto to a Jira Cloud issue. Jira automation POSTs the ticket key, summary, and description to workflow_dispatch. The workflow checks out the repository, transitions the ticket to In Progress, and runs codex exec --approval-mode full-auto with that context. Codex creates a branch and commits, after which the workflow opens a PR, transitions the ticket to In Review, and posts the PR URL as a Jira comment.

For Codex CLI v0.120+, native HTTP MCP transport uses /v1/mcp without a Node.js dependency. The Atlassian Rovo MCP Server reached GA in February 2026 and exposes getConfluenceContent and searchConfluence for architecture documents, API specifications, and design decisions.

Linear follows the same principle through issue assignment to Codex or an @Codex comment. Local CLI access uses codex mcp add linear --url with the server URL, after which a task can reference “fix Linear issue FE-234”.

Using /goal and memory configuration for PRs that span multiple sessions

Long-running implementation needs a clear completion contract as well as a remembered task description. The /goal command supports work that continues across active turns and sessions. It distinguishes between tests that pass and a goal that has been fully met. Structured audit requirements in the goal prompt make that distinction explicit before the agent closes the work.

Mid-turn compaction drift can cause the work to fail. When context limits trigger compaction, the goal continuation prompt and audit requirements can be stripped, leaving only the immediate task context. The agent may then interpret passing tests as completion and close the goal prematurely. An explicit audit requirement and smaller PR scope are mitigations.

Memory also needs the correct scope. Personal preferences stored through /m_update persist across projects, while context supplied directly in conversation is not persisted as shared team memory. Team requirements belong in AGENTS.md, where agents doing the team's work can read them. Keeping those layers separate prevents a workflow from depending on instructions held only by one person's sessions.

What the configuration gets wrong when agentic PRs fail at scale

At scale, CI failures, runaway token spend, and premature completion point back to gaps in scope, execution policy, and completion criteria. Analysis across tens of thousands of repositories found that nearly one in three agentic PRs fails, with each CI failure adding compounding cost. Smaller PRs consistently outperform larger ones. The configuration response is to place prompt scope and PR size limits in AGENTS.md or the prompt file.

Reviewability also requires a handoff record. Every Codex-assisted PR must carry three linked artifacts, namely the initiating goal command, the exact AGENTS.md scope file by commit SHA, and the pass/fail specification with its current outcome. A PR template captures that record, and a pre-merge hook blocks work that lacks it. This ties the proposed change to both its governing instructions and its completion evidence.

Shared agent environments create interference, unreliable results, and attribution gaps, just as unrestricted access on a shared runner differs from unrestricted access inside an isolated container. Better prompts can refine a task, but configuration makes the whole PR lifecycle repeatable.

Sources

  1. Codex GitHub Action
Filed underAgent Setup

More in Agent Setup