Integration Workflows

50 min advanced Lesson 9

Learning Outcomes

  • Integrate Codex CLI into git workflows for commit messages, PR descriptions, and code review
  • Set up Codex CLI in CI/CD pipelines for automated tasks
  • Combine Codex CLI with IDE-based tools for a unified development experience
  • Share Codex configurations and practices across a development team
  • Build custom workflow scripts that chain Codex operations with other tools

Lesson Plan

Segment Duration Topic
Intro 3 min Codex as part of a larger development ecosystem
Demo 1 10 min Git integration — commits, PRs, and reviews
Demo 2 9 min CI/CD pipeline integration
Demo 3 8 min IDE + terminal workflows
Explain 5 min Team sharing patterns
Demo 4 8 min Building custom workflow scripts
Explain 4 min Security considerations for integrations
Wrap-up 3 min Designing your integrated workflow

Before You Begin

Pre-work:

Shopping List:

  • Codex CLI installed and configured
  • A git repository with multiple commits and branches
  • GitHub or GitLab account for CI/CD exercises
  • Familiarity with shell scripting basics
  • IDE of choice (VS Code, Cursor, Vim, etc.)

1 Git Integration

Codex CLI works naturally alongside git. You can use it to generate commit messages, create PR descriptions, review changes, and manage branches.

Generating commit messages:

After making changes, ask Codex to write a meaningful commit message:

> Look at the current git diff (staged changes) and write a
> conventional commit message. Follow the format:
> type(scope): description

Codex reads the diff and suggests:

feat(auth): add password reset flow with email verification

- Add sendPasswordReset utility with token generation
- Create POST /forgot-password and POST /reset-password endpoints
- Add resetToken field to User model
- Include integration tests for both endpoints

One-shot commit message generation:

# Stage changes first
git add -A

# Ask Codex to generate a commit message
codex --quiet "Read the staged git diff and write a conventional commit message. Output only the message, nothing else." | git commit -F -
# Stage changes first
git add -A

# Ask Codex to generate a commit message
codex --quiet "Read the staged git diff and write a conventional commit message. Output only the message, nothing else." > commit-msg.txt && git commit -F commit-msg.txt && del commit-msg.txt

PR description generation:

> Look at all commits on this branch since it diverged from main
> (git log main..HEAD). Write a pull request description with:
> - A one-line summary
> - A bullet list of changes
> - Testing instructions
> - Any breaking changes noted

Code review assistance:

> Run `git diff main..HEAD` and review the changes. Point out:
> - Potential bugs or edge cases
> - Missing error handling
> - Inconsistencies with the rest of the codebase
> - Suggestions for improvement

Branch management:

> I have 5 stale branches. List all branches with `git branch`,
> check which are merged into main, and tell me which ones are
> safe to delete.

Resolving merge conflicts:

> I have merge conflicts in src/routes/users.js. Show me the
> conflict markers and suggest a resolution that keeps both
> sets of changes.
TIP
Tip
Codex-generated commit messages are a starting point. Always read them before committing. A human should own the narrative of what was changed and why.
NOTE
How It Works
Codex reads git output (diffs, logs, status) as regular text. It doesn't have special git integration — it simply runs git commands and interprets the results, just like a developer would.

2 CI/CD Pipeline Integration

Codex CLI can be integrated into CI/CD pipelines for automated code tasks. Since it runs in a terminal, it works anywhere you can run commands.

GitHub Actions example — automated test generation:

# .github/workflows/codex-tests.yml
name: Generate Missing Tests

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  generate-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

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

      - name: Generate tests for changed files
        env:
          CODEX_API_KEY: $
        run: |
          # Get changed files
          CHANGED=$(git diff --name-only origin/main...HEAD -- '*.py')

          # Ask Codex to identify untested files
          codex --quiet --approval-policy never \
            "These files changed: $CHANGED. Check which ones lack tests and generate test files."

      - name: Run tests
        run: pytest tests/ -v

      - name: Commit generated tests
        run: |
          git add tests/
          git diff --staged --quiet || git commit -m "test: auto-generate tests for changed modules"
          git push

Automated code review in CI:

# .github/workflows/codex-review.yml
name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize]

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

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

      - name: Review changes
        env:
          CODEX_API_KEY: $
        run: |
          REVIEW=$(codex --quiet "Review the changes in this PR (git diff origin/main...HEAD). Report any bugs, security issues, or style violations. Be concise.")
          echo "$REVIEW" >> $GITHUB_STEP_SUMMARY

Automated documentation updates:

- name: Update API docs
  run: |
    codex --quiet --approval-policy never \
      "Read all route files in src/routes/ and update docs/API.md with the current endpoints, methods, and parameters."

Key considerations for CI/CD:

Concern Solution
API key security Use GitHub Secrets / CI environment variables
Costs per run Use gpt-5.4-mini for CI tasks, limit scope
Flaky results Pin model version, use clear prompts
Network in sandbox Use never policy in CI (controlled environment)
Determinism Results may vary between runs — design for this
WARNING
Watch Out
CI/CD integration means Codex runs automatically on every PR. This costs API tokens for every run. Set up conditions to only trigger on specific file changes or labels to control costs.
TIP
Tip
Start with CI tasks that are review-only (no file changes). Once you trust the output, graduate to tasks that create commits. Always test the workflow on a non-critical repo first.

3 IDE and Terminal Workflow

Codex CLI lives in the terminal, but you can combine it with your IDE for a powerful dual-pane workflow.

Split-pane setup:

The most effective setup runs your IDE and Codex side by side:

Terminal multiplexer (tmux):

# Split your terminal: IDE on left, Codex on right
tmux new-session -s dev
# Ctrl+B then % to split vertically
# Left pane: vim or your editor
# Right pane: codex

VS Code integrated terminal:

  1. Open VS Code with your project
  2. Open the integrated terminal (Cmd+`)
  3. Run codex in the terminal
  4. Use the editor for navigation, Codex for AI operations

iTerm2 split panes:

  • Cmd+D to split vertically
  • Run codex in one pane, use the other for git/testing

Windows Terminal split panes:

  1. Open Windows Terminal with your project
  2. Alt+Shift+D to split the pane
  3. Run codex in one pane, use the other for navigation

VS Code integrated terminal:

  1. Open VS Code with your project
  2. Open the integrated terminal (Ctrl+`)
  3. Run codex in the terminal
  4. Use the editor for navigation, Codex for AI operations

Workflow pattern — IDE + Codex:

  1. Navigate in your IDE — find the file and function you want to change
  2. Ask Codex — describe the change referencing the file path
  3. Review — Codex shows the diff, you approve or reject
  4. Verify — Your IDE auto-reloads the changed file, you see the result
  5. Test — Run tests from either the IDE or ask Codex

VS Code tasks integration:

Create VS Code tasks that invoke Codex:

// .vscode/tasks.json
{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Codex: Explain Current File",
      "type": "shell",
      "command": "codex --quiet 'Explain ${file} in plain English'",
      "presentation": { "reveal": "always" }
    },
    {
      "label": "Codex: Generate Tests",
      "type": "shell",
      "command": "codex --quiet --approval-policy on-request 'Generate tests for ${file}'",
      "presentation": { "reveal": "always" }
    }
  ]
}

Vim/Neovim integration:

" Add to .vimrc or init.vim
command! -nargs=1 Codex :terminal codex --quiet <args>

" Usage: :Codex "Add error handling to this file"
NOTE
How It Works
Codex modifies files on disk. Any IDE that watches for file changes (VS Code, Cursor, JetBrains, Vim with autoread) will immediately reflect Codex's edits. No plugin needed — just file system events.
TIP
Tip
The IDE provides what Codex lacks: visual navigation, syntax highlighting, and multi-cursor editing. Codex provides what the IDE lacks: AI reasoning, cross-file understanding, and natural language operations. Use both.

4 Team Workflows and Sharing

When a whole team uses Codex CLI, consistency and shared practices become important.

Shared project configuration:

Commit these to your repo:

.codex/
  config.toml          # Team-wide Codex settings
  instructions.md      # Detailed coding guidelines (referenced in config)
# .codex/config.toml
model = "gpt-5.4-mini"
approval_policy = "untrusted"

[instructions]
content = """
Follow the guidelines in .codex/instructions.md.
All new code must have tests.
Use conventional commits.
Never modify files in vendor/ or generated/.
"""

Team conventions document:

Create .codex/instructions.md for detailed guidelines:

# Codex Instructions for PaymentService

## Architecture
- This is a microservice using Express + TypeScript
- Follow hexagonal architecture (ports and adapters)
- Business logic goes in src/domain/, never in routes

## Testing
- Unit tests colocated with source (*.test.ts)
- Integration tests in tests/integration/
- Minimum 80% coverage for new code

## Style
- Use functional patterns, avoid classes
- Named exports only
- Error handling with Result types, not exceptions

Onboarding new developers:

Add Codex to your onboarding documentation:

> Read the project README, CONTRIBUTING.md, and .codex/instructions.md.
> Summarize the project architecture and key conventions I should follow.

Sharing useful prompts:

Keep a team prompt library:

# .codex/prompts.md (for reference, not machine-read)

## Generate migration
"Create a database migration for [describe schema change]. Follow the
naming convention in migrations/ and include both up and down."

## Pre-PR review
"Review all changes since main (git diff main..HEAD). Check for:
security issues, missing tests, style violations, and performance concerns."

## Dependency update
"Check package.json for outdated dependencies. List which ones have
major version bumps and what breaking changes to expect."

Team communication about Codex usage:

  • Mention in PR descriptions when Codex generated code
  • Note which parts were AI-generated vs hand-written
  • Flag any Codex-generated code that needs extra review
TIP
Tip
Consider adding a PR template checkbox: '[ ] AI-generated code has been reviewed for correctness and security'. This creates accountability for Codex-generated changes.
WARNING
Watch Out
Team members may have different API keys with different rate limits or model access. Ensure your CI/CD uses a shared team API key, not individual developer keys.

5 Custom Workflow Scripts

Combine Codex CLI with shell scripting to create repeatable workflows for common tasks.

Script: Pre-commit hook with Codex review

#!/bin/bash
# .git/hooks/pre-commit (make executable: chmod +x)

# Get staged files
STAGED=$(git diff --cached --name-only --diff-filter=ACM)

if [ -z "$STAGED" ]; then
  exit 0
fi

echo "Running Codex review on staged files..."
REVIEW=$(codex --quiet "Review these staged changes for obvious bugs: $(git diff --cached)")

if echo "$REVIEW" | grep -qi "critical\|security\|bug"; then
  echo "⚠ Codex found potential issues:"
  echo "$REVIEW"
  echo ""
  read -p "Continue with commit? (y/n) " -n 1 -r
  echo
  if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    exit 1
  fi
fi

exit 0
#!/bin/bash
# .git/hooks/pre-commit (Git for Windows uses bash)

# Get staged files
STAGED=$(git diff --cached --name-only --diff-filter=ACM)

if [ -z "$STAGED" ]; then
  exit 0
fi

echo "Running Codex review on staged files..."
REVIEW=$(codex --quiet "Review these staged changes for obvious bugs: $(git diff --cached)")

if echo "$REVIEW" | grep -qi "critical\|security\|bug"; then
  echo "Codex found potential issues:"
  echo "$REVIEW"
  echo ""
  read -p "Continue with commit? (y/n) " -n 1 -r
  echo
  if [[ ! $REPLY =~ ^[Yy]$ ]]; then
    exit 1
  fi
fi

exit 0

Script: Batch test generation

#!/bin/bash
# scripts/generate-missing-tests.sh

echo "Finding source files without tests..."

for src_file in src/**/*.py; do
  test_file="tests/test_$(basename $src_file)"
  if [ ! -f "$test_file" ]; then
    echo "Generating tests for: $src_file"
    codex --quiet --approval-policy on-request \
      "Generate comprehensive tests for $src_file. Save to $test_file."
  fi
done

echo "Running all tests..."
pytest tests/ -v

Script: Documentation updater

#!/bin/bash
# scripts/update-docs.sh

codex --quiet --approval-policy on-request \
  "Read all source files in src/ and update docs/API.md with:
   - All public functions and their signatures
   - Brief descriptions from docstrings
   - Usage examples where available
   Format as a clean markdown reference."

echo "Documentation updated. Review with: git diff docs/API.md"

Script: Morning standup helper

#!/bin/bash
# scripts/standup.sh

echo "=== Your changes since yesterday ==="
codex --quiet "Summarize my git commits from the last 24 hours
(git log --since='24 hours ago' --oneline). Group by feature/area.
Format as standup bullet points: what was done, what's in progress."
TIP
Tip
Keep workflow scripts in a scripts/ directory in your repo. Make them executable and document them in your README. New team members can immediately use established patterns.
WARNING
Watch Out
Scripts that use never policy run without human review. Only use them for low-risk, well-tested operations. Add safeguards: dry-run modes, confirmation prompts, and git status checks before execution.

Questions & Answers

Q: Is it safe to put my OpenAI API key in CI/CD environment variables?
Yes, as long as you use your CI/CD platform's secrets management (GitHub Secrets, GitLab CI Variables marked as "masked"). Never hardcode keys in workflow files or scripts. Set spending limits on the API key used for CI to prevent runaway costs from misconfigured workflows.
Q: Can Codex CLI work alongside GitHub Copilot or Cursor?
Absolutely. They serve different purposes: Copilot/Cursor provide inline suggestions while you type in an editor. Codex CLI handles larger operations from the terminal (multi-file edits, test generation, scaffolding). They don't conflict — use Copilot for line-by-line coding and Codex for task-level operations.
Q: How do I prevent Codex from making unwanted changes in CI?
Use safeguards: run Codex-generated changes through your existing CI checks (linting, tests, type checking). Create changes in a separate branch and require PR review before merging. Add a `--dry-run` flag to scripts during development. Always run the test suite after any Codex modifications.
Q: What's the cost impact of running Codex in CI on every PR?
Cost depends on the task scope and model. A simple review of a small diff with gpt-5.4-mini costs fractions of a cent. Large codebase analysis with gpt-5.5 could cost $0.50-2.00 per run. Estimate by running manually first, then set API spending limits. Consider only triggering on specific labels or file changes.

Key Takeaways

  1. Git integration is natural: Use Codex for commit messages, PR descriptions, and code review — it reads git output like a developer would
  2. CI/CD extends Codex to automation: Run review, test generation, and documentation updates automatically on PRs
  3. IDE + terminal is the sweet spot: Navigate in your editor, operate with Codex in the terminal — they complement each other
  4. Team configs ensure consistency: Commit .codex/config.toml and instructions to share behavior across the team
  5. Custom scripts multiply value: Combine Codex with bash scripting for repeatable, team-specific workflows
  6. Security first in automation: Use secrets management, spending limits, and human review gates for CI/CD integration

Next Steps: In Lesson 10 — Advanced Automation, you'll learn how to script complex Codex operations, build batch processing pipelines, and orchestrate multi-tool workflows.