mcpField
C
codex-review

codex-review

github.com/alinaqiテスト・品質710326 回インストール2 週間前に更新
リポジトリ

codex-review について

codex-review は、OpenAI Codex CLI でバグやセキュリティ上の問題、コード品質を確認するスキルです。対話型レビュー、構造化出力、CI での自動化を扱います。

主な機能

  1. 01対話型レビューのプリセット
  2. 02非対話型 CLI レビュー
  3. 03JSON とスキーマ形式の結果
  4. 04GitHub PR レビュー連携
  5. 05CI/CD 自動化の手順

活用シーン

  1. 01コミット前の未コミット変更の確認
  2. 02プルリクエスト作成前の差分レビュー
  3. 03CI パイプラインでのレビュー自動化

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/alinaqi/maggy --skill codex-review

インストール後、Claude Code で/codex-reviewを入力して読み込まれたか確認します。

詳細

OpenAI Codex コードレビュー スキル

OpenAI の Codex CLI を使用して、GPT-5.2-Codex による専門的なコードレビューを行います。GPT-5.2-Codex は、バグ、セキュリティ上の欠陥、コード品質の問題を検出するために特化してトレーニングされています。

ソース: Codex CLI | GitHub | コードレビューレシピ


コードレビューに Codex を使う理由

特徴メリット
GPT-5.2-Codexコードレビューに特化したトレーニング
検出率 88%バグ、セキュリティ上の欠陥、スタイルの問題(LiveCodeBench)
構造化出力一貫した指摘を得るための JSON スキーマ
GitHub ネイティブ対応PR のコメントで @codex review
ヘッドレスモードTUI を使わずに CI/CD を自動化

インストール

前提条件
# Check Node.js version (requires 22+)
node --version

# Install Node.js 22 if needed
# macOS
brew install node@22

# Or via nvm
nvm install 22
nvm use 22
Codex CLI のインストール
# Via npm (recommended)
npm install -g @openai/codex

# Via Homebrew (macOS)
brew install --cask codex

# Verify installation
codex --version
認証

オプション 1:ChatGPT サブスクリプション(Plus、Pro、Team、Edu、Enterprise)

codex
# Follow prompts to sign in with ChatGPT account

オプション 2:OpenAI API キー

# Set environment variable
export OPENAI_API_KEY=sk-proj-...

# Or add to shell profile
echo 'export OPENAI_API_KEY=sk-proj-...' >> ~/.zshrc

# Run Codex
codex
シェル補完(任意)
# Bash
codex completion bash >> ~/.bashrc

# Zsh
codex completion zsh >> ~/.zshrc

# Fish
codex completion fish > ~/.config/fish/completions/codex.fish

対話型コードレビュー

レビューモードの起動
# Start Codex
codex

# In the TUI, type:
/review
レビュープリセット
プリセット用途
ベースブランチと比較してレビューPR を作成する前に、アップストリームとの差分を確認
未コミットの変更をレビューコミットする前に、ステージ済み・未ステージ・未追跡の変更を確認
コミットをレビュー履歴から特定の SHA を分析
カスタム指示例:「セキュリティ上の脆弱性に重点を置く」
セッション例
$ codex
> /review

Select review type:
❯ Review against a base branch
  Review uncommitted changes
  Review a commit
  Custom review instructions

Select base branch: main

Reviewing changes...

┌─────────────────────────────────────────────────────────────┐
│ CODE REVIEW FINDINGS                                        │
├─────────────────────────────────────────────────────────────┤
│ 🔴 CRITICAL: SQL Injection vulnerability                    │
│    File: src/api/users.ts:45                                │
│    Issue: User input directly interpolated in query         │
│    Fix: Use parameterized queries                           │
├─────────────────────────────────────────────────────────────┤
│ 🟠 HIGH: Missing authentication check                       │
│    File: src/api/admin.ts:23                                │
│    Issue: Admin endpoint accessible without auth            │
│    Fix: Add requireAuth middleware                          │
├─────────────────────────────────────────────────────────────┤
│ 🟡 MEDIUM: Inefficient database query                       │
│    File: src/services/orders.ts:89                          │
│    Issue: N+1 query pattern in loop                         │
│    Fix: Use batch query or JOIN                             │
└─────────────────────────────────────────────────────────────┘

ヘッドレスモード(自動化)

基本的な使い方
# Simple review
codex exec "review the code for bugs and security issues"

# Review with JSON output
codex exec --json "review uncommitted changes" > review.json

# Save final message to file
codex exec --output-last-message review.txt "review the diff against main"
完全な自動化(CI/CD)
# Full auto mode (use only in isolated runners!)
codex exec \
  --full-auto \
  --json \
  --output-last-message findings.txt \
  --sandbox read-only \
  -m gpt-5.2-codex \
  "Review this code for bugs, security issues, and performance problems"
スキーマを使用した構造化出力
# Define output schema
cat > review-schema.json << 'EOF'
{
  "type": "object",
  "properties": {
    "findings": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "severity": { "enum": ["critical", "high", "medium", "low"] },
          "title": { "type": "string" },
          "file": { "type": "string" },
          "line": { "type": "integer" },
          "description": { "type": "string" },
          "suggestion": { "type": "string" }
        },
        "required": ["severity", "title", "file", "description"]
      }
    },
    "summary": { "type": "string" },
    "approved": { "type": "boolean" }
  },
  "required": ["findings", "summary", "approved"]
}
EOF

# Run with schema validation
codex exec \
  --output-schema review-schema.json \
  --output-last-message review.json \
  "Review the staged changes and output findings"

GitHub との統合

オプション 1:PR コメントによる起動

任意のプルリクエストにコメントを追加します。

@codex review

Codex は標準的な GitHub コードレビューを返します。

オプション 2:GitHub Action
# .github/workflows/codex-review.yml
name: Codex Code Review

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Codex Review
        uses: openai/codex-action@main
        with:
          openai_api_key: ${{ secrets.OPENAI_API_KEY }}
          model: gpt-5.2-codex
          safety_strategy: drop-sudo
オプション 3:CI で手動実行するヘッドレスモード
# .github/workflows/codex-review.yml
name: Codex Code Review

on:
  pull_request:

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - uses: actions/setup-node@v4
        with:
          node-version: '22'

      - name: Install Codex CLI
        run: npm install -g @openai/codex

      - name: Run Review
        env:
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
        run: |
          # Get diff
          git diff origin/${{ github.base_ref }}...HEAD > diff.txt

          # Run Codex review
          codex exec \
            --full-auto \
            --sandbox read-only \
            --output-last-message review.md \
            "Review this git diff for bugs, security issues, and code quality: $(cat diff.txt)"

      - name: Post Review Comment
        uses: actions/github-script@v7
        with:
          script: |
            const fs = require('fs');
            const review = fs.readFileSync('review.md', 'utf8');
            github.rest.issues.createComment({
              owner: context.repo.owner,
              repo: context.repo.repo,
              issue_number: context.issue.number,
              body: `## 🤖 Codex Code Review\n\n${review}`
            });

GitLab CI/CD

# .gitlab-ci.yml
codex-review:
  image: node:22
  stage: review
  script:
    - npm install -g @openai/codex
    - |
      codex exec \
        --full-auto \
        --sandbox read-only \
        --output-last-message review.md \
        "Review the merge request changes for bugs and security issues"
    - cat review.md
  artifacts:
    paths:
      - review.md
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"

Jenkins パイプライン

pipeline {
    agent any

    environment {
        OPENAI_API_KEY = credentials('openai-api-key')
    }

    stages {
        stage('Install Codex') {
            steps {
                sh 'npm install -g @openai/codex'
            }
        }

        stage('Code Review') {
            steps {
                sh '''
                    codex exec \
                      --full-auto \
                      --sandbox read-only \
                      --output-last-message review.md \
                      "Review the code changes for bugs and security issues"
                '''
            }
        }

        stage('Publish Results') {
            steps {
                archiveArtifacts artifacts: 'review.md'
                script {
                    def review = readFile('review.md')
                    echo "Code Review Results:\n${review}"
                }
            }
        }
    }
}

設定

設定ファイル
# ~/.codex/config.toml

[model]
default = "gpt-5.2-codex"  # Best for code review

[sandbox]
default = "read-only"  # Safe for reviews

[review]
# Custom review instructions applied to all reviews
instructions = """
Focus on:
1. Security vulnerabilities (OWASP Top 10)
2. Performance issues (N+1 queries, memory leaks)
3. Error handling gaps
4. Type safety issues
"""
プロジェクトごとの設定
# .codex/config.toml (in project root)

[review]
instructions = """
This is a Python FastAPI project. Focus on:
- Async/await correctness
- Pydantic model validation
- SQL injection via SQLAlchemy
- Authentication/authorization gaps
"""

CLI クイックリファレンス

# Interactive
codex                          # Start TUI
/review                        # Open review presets

# Headless
codex exec "prompt"            # Non-interactive execution
codex exec --json "prompt"     # JSON output
codex exec --full-auto "prompt"  # No approval prompts

# Key Flags
--output-last-message FILE     # Save response to file
--output-schema FILE           # Validate against JSON schema
--sandbox read-only            # Restrict file access
-m gpt-5.2-codex              # Use best review model
--json                         # Machine-readable output

# Resume
codex exec resume SESSION_ID   # Continue previous session

比較:Claude と Codex によるレビュー

項目Claude(組み込み)Codex CLI
セットアップ不要(すでに Claude Code に組み込み済み)CLI のインストールと認証
モデルClaudeGPT-5.2-Codex(特化型)
コンテキスト会話全体のコンテキストレビューごとに新しいコンテキスト
統合ネイティブGitHub、GitLab、Jenkins
出力MarkdownJSON スキーマに対応
最適な用途手早いレビュー、作業中のレビューCI/CD、重要な PR

セキュリティに関する考慮事項

CI/CD の安全性
# Always use these flags in CI/CD:
--sandbox read-only           # Prevent file modifications
--safety-strategy drop-sudo   # Revoke elevated permissions
API キーの保護
# GitHub Actions - use secrets
env:
  OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

# Never hardcode keys
# Never echo keys in logs
パブリックリポジトリ

パブリックリポジトリでは、実行中に Codex が自身の API キーを読み取ることを防ぐために、drop-sudo 安全戦略を使用してください。


トラブルシューティング

問題解決策
codex: command not foundnpm install -g @openai/codex を実行します
Node.js version errorNode.js 22 以降にアップグレードします
Authentication failedcodex を再実行して、もう一度サインインします
API key invalidOPENAI_API_KEY 環境変数を確認します
Timeout in CI--timeout 300 フラグを追加します
Rate limited実行頻度を下げるか、プランをアップグレードします

アンチパターン

  • --dangerously-bypass-approvals-and-sandbox を安易に使う - 隔離された CI ランナー内でのみ使用します
  • ログに API キーを露出させる - シークレット管理を使用します
  • CI でサンドボックスを省略する - 常に --sandbox read-only を使用します
  • 指摘を無視する - レビューして対応するか、例外として記録します
  • コミットのたびに実行する - コストを抑えるため、PR のみで使用します

コメント