Integration Workflows
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:
- Complete Lesson 8 — Configuration & Customization
- Have a project with git history (multiple branches, prior commits)
- Access to a CI/CD system (GitHub Actions, GitLab CI, or equivalent)
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.)
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.
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 |
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:
- Open VS Code with your project
- Open the integrated terminal (Cmd+`)
- Run
codexin the terminal - Use the editor for navigation, Codex for AI operations
iTerm2 split panes:
- Cmd+D to split vertically
- Run
codexin one pane, use the other for git/testing
Windows Terminal split panes:
- Open Windows Terminal with your project
- Alt+Shift+D to split the pane
- Run
codexin one pane, use the other for navigation
VS Code integrated terminal:
- Open VS Code with your project
- Open the integrated terminal (Ctrl+`)
- Run
codexin the terminal - Use the editor for navigation, Codex for AI operations
Workflow pattern — IDE + Codex:
- Navigate in your IDE — find the file and function you want to change
- Ask Codex — describe the change referencing the file path
- Review — Codex shows the diff, you approve or reject
- Verify — Your IDE auto-reloads the changed file, you see the result
- 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"
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
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."
Questions & Answers
Key Takeaways
- Git integration is natural: Use Codex for commit messages, PR descriptions, and code review — it reads git output like a developer would
- CI/CD extends Codex to automation: Run review, test generation, and documentation updates automatically on PRs
- IDE + terminal is the sweet spot: Navigate in your editor, operate with Codex in the terminal — they complement each other
- Team configs ensure consistency: Commit .codex/config.toml and instructions to share behavior across the team
- Custom scripts multiply value: Combine Codex with bash scripting for repeatable, team-specific workflows
- 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.