Skip to content

OpenAI Codex /review Command Implementation: Integrating Automated Code Review into CI/CD

Codex CLI Complete Guide

This article is a follow-up to the morning article

Morning article: OpenAI Codex 0.39.0 Update

Goals

  • Build a system to automatically execute /review command via GitHub Actions
  • Implement workflow to auto-post review results as PR comments
  • Understand configuration parameters to maximize review quality

Architecture Overview

The /review command can be controlled programmatically through API mode, not just standalone execution. This enables integration into CI/CD pipelines.

graph LR
    PR[Pull Request] --> GHA[GitHub Actions]
    GHA --> CODEX[Codex /review API]
    CODEX --> RESULT[Review Results]
    RESULT --> COMMENT[PR Comment]

Implementation Steps

Step 1: Setup Codex API Mode

# Execute review in API mode (JSON output)
codex review --api-mode \
  --format json \
  --files "src/**/*.ts" \
  --severity "warning,error"

Step 2: GitHub Actions Workflow Implementation

name: AI Code Review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run Codex Review
        id: review
        run: |
          OUTPUT=$(codex review --api-mode --format json)
          echo "result<<EOF" >> ${{ github.output }}
          echo "$OUTPUT" >> ${{ github.output }}
          echo "EOF" >> ${{ github.output }}

Step 3: Parse and Format Review Results

// parse-review.js
const reviewData = JSON.parse(process.env.REVIEW_OUTPUT);
const issues = reviewData.issues.filter(i => 
  i.severity === 'error' || i.severity === 'warning'
);

const markdown = issues.map(issue => 
  `- **${issue.file}:${issue.line}** - ${issue.message}`
).join('\n');

console.log(markdown);

Performance Comparison

Execution ModeProcessing TimeMemory UsageAccuracy
Standard Mode45s512MBStandard
API Mode28s256MBStandard
Batch Mode15s/file128MBHigh
StreamingInstant start64MBStandard

Failure Patterns and Avoidance Strategies

SymptomCauseAvoidance Strategy
timeout after 60sLarge file processingSplit with --batch-size 10
context window exceededHuge filesLimit with --max-lines 500
authentication failedToken expirationAuto-update via Secrets
rate limit exceededToo many parallel runsControl with concurrency: 1

Advanced Configuration Patterns

Custom Rule Definitions (click to expand)
{
  "review_rules": {
    "security": {
      "enabled": true,
      "patterns": ["eval\\(", "exec\\("],
      "severity": "error"
    },
    "performance": {
      "enabled": true,
      "max_complexity": 10
    }
  }
}

Automation Extension Ideas

  • Configure /review as mandatory check before PR merge
  • Dashboard aggregation of review results
  • Auto-notify critical findings to Slack
  • Generate custom rules through past review learning
  • Visualize technical debt via scheduled execution

Next Steps