Skip to content

Pull Request Automation Workflow

Your team’s PR process has become a bottleneck. PRs sit for two days waiting for review. When reviews finally happen, they catch issues that require a second round. Follow-up commits break CI, which requires another review cycle. A single feature takes a week to go from “ready for review” to “merged.” With Codex, you can automate every step: create PRs from worktrees, get instant AI review, fix CI failures without leaving GitHub, and prepare PRs for final human review with all issues pre-resolved.

  • A worktree-to-PR pipeline that creates PRs directly from the Codex App
  • @codex patterns for fixing CI failures and requesting reviews on GitHub
  • A GitHub Action workflow for automated review on every PR
  • Techniques for combining automated and human review effectively

When a Codex worktree thread completes its task, you can go from diff to open PR without leaving the App. This is the fastest path from implementation to review.

In the Codex App, after a worktree thread finishes:

  1. Review the diff in the review pane. Stage the changes you want, revert what you do not.
  2. Click Create branch here to turn the worktree into a named branch.
  3. Commit the staged changes with a descriptive message.
  4. Push the branch to the remote using the push button.
  5. Open a pull request directly from the App.

For automated PR creation, you can also instruct Codex to handle it:

Once the PR is open on GitHub, get immediate feedback without waiting for a human reviewer.

Comment on the PR:

@codex review

Codex reacts with eyes emoji, analyzes the entire diff, and posts a standard GitHub code review with inline comments. The review covers correctness, security, and maintainability based on your AGENTS.md review guidelines.

For focused reviews, add instructions:

@codex review with focus on:
- Database query performance (check for missing indexes and N+1 patterns)
- Error handling completeness
- API backward compatibility

Step 3: Fix CI Failures Without Leaving GitHub

Section titled “Step 3: Fix CI Failures Without Leaving GitHub”

When CI fails on your PR, you do not need to pull the branch locally, figure out what broke, fix it, and push again. Comment on the PR:

Codex creates a cloud task that:

  1. Reads the PR diff and CI failure logs
  2. Identifies the root cause
  3. Proposes a fix
  4. Posts the results back to the PR with a link to the cloud task

If the fix involves code changes, you can create a new PR from the cloud task that targets your feature branch. Or open the cloud task, review the diff, and apply the changes manually.

For specific CI failures:

@codex The TypeScript type check fails because the new NotificationPreference interface is missing the updatedAt field that the migration added. Fix the type definition and any related code.

Before requesting human review, use the Codex App to clean up common issues. Open a Local thread with your feature branch checked out:

Review all changes on this branch compared to main. Check for:
1. Any TODO comments that should be resolved before merging
2. Console.log or debugging statements left in production code
3. Missing or incomplete test coverage for new functions
4. Unused imports or dead code
5. Inconsistent error handling patterns
Fix any issues you find. Run the test suite after each fix.

Then use /review in the CLI to verify the cleanup:

/review Focus on merge readiness. Is this PR ready for human review? Flag anything a reviewer would send back for changes.

Combine the GitHub Action with @codex review for a fully automated PR pipeline:

name: PR Pipeline
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
# Step 1: Standard CI checks
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- run: npm ci
- run: npm run type-check
- run: npm run lint
- run: npm test
# Step 2: Codex review (runs in parallel with CI)
codex-review:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/checkout@v5
with:
ref: refs/pull/${{ github.event.pull_request.number }}/merge
- name: Fetch refs
run: |
git fetch --no-tags origin \
${{ github.event.pull_request.base.ref }} \
+refs/pull/${{ github.event.pull_request.number }}/head
- uses: openai/codex-action@v1
with:
openai-api-key: ${{ secrets.OPENAI_API_KEY }}
prompt-file: .github/codex/prompts/review.md
sandbox: read-only
safety-strategy: drop-sudo
# Step 3: Post combined results
summary:
needs: [ci, codex-review]
if: always()
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Post status summary
uses: actions/github-script@v7
with:
script: |
const ci = '${{ needs.ci.result }}';
const review = '${{ needs.codex-review.result }}';
const body = `## PR Pipeline Summary\n\n` +
`| Check | Status |\n|---|---|\n` +
`| CI (lint, types, tests) | ${ci} |\n` +
`| Codex Review | ${review} |\n`;
await github.rest.issues.createComment({
...context.repo,
issue_number: context.payload.pull_request.number,
body
});

For teams that want review on every PR without manual @codex review comments, enable Automatic reviews in Codex settings at chatgpt.com/codex/settings/code-review. When enabled, Codex posts a review on every PR opened for review, behaving like a dedicated team reviewer.

Codex review and human review conflict. If Codex says “this is fine” and a human reviewer says “change it,” the human wins. Make this explicit in your team’s process: Codex review catches obvious issues early; human review handles architectural judgment and business logic correctness.

PR creation from worktree fails due to branch conflicts. If your worktree was created from a branch that has since received new commits, the PR may have conflicts. Before creating the PR, sync the worktree with the latest base branch using the integrated terminal: git fetch origin main && git rebase origin/main.

@codex fix creates a fix on the wrong branch. Cloud tasks default to the repository’s default branch. When you comment @codex fix on a PR, Codex should work against the PR branch, but verify the resulting changes target the correct branch.

Too many automated comments on a single PR. If both the GitHub Action and @codex review run, plus Codex posts fix proposals, the PR can get noisy. Choose one review mechanism: either the GitHub Action for CI-integrated review, or @codex review (or automatic reviews) for on-demand review. Do not run both.