Codex Team Workflow: worktrees, reviews, and CI integration
How to use Codex CLI in a team without breaking things: independent git worktrees, diff review, CODEOWNERS, CI integration, sensitive-path whitelist, and PR review checklist.
How to
Create an independent worktree for each Codex task
git worktree add -b codex-feature ../codex-feature main; Codex works in ../codex-feature/, your main branch work continues uninterrupted.
Add a hook to protect sensitive paths
A .githooks/pre-push script: detect pushes that touch lockfiles / CI config / db migrations, alert and abort; or require CODEOWNERS approval.
Enforce CODEOWNERS review
.github/CODEOWNERS lists the owner for each directory; Codex changes trigger PRs that auto-request review; nothing merges without owner approval.
CI: lint + test + typecheck
Codex changes trigger a PR, CI runs pnpm lint && pnpm test && pnpm typecheck automatically; nothing merges if CI fails.
PR template lets Codex auto-fill the description
.github/pull_request_template.md requires changelog, linked issue, test environment; Codex writes the PR by following the template.
Using Codex CLI well in a team comes down to workflow design — not just "let Codex write code", but "let Codex write code without breaking team flow". This article gives a copyable team practice, from single-task workflow to CI integration.
1. Single-task workflow: independent worktree
Run each Codex task in its own git worktree:
# Create a worktree from main (-b names the new branch explicitly)
git worktree add -b codex-fix-bug ../codex-fix-bug main
# Let Codex work inside the worktree
cd ../codex-fix-bug
codex "Fix the NPE in src/foo.ts"
Benefits:
- Main branch work continues uninterrupted
- Codex running commands in the worktree doesn't affect you
- After diff review, merge directly back to main
- Multiple Codex tasks can run concurrently without interference
2. Sensitive-path protection (two layers)
Layer 1: hooks block automated writes
Sample .githooks/pre-push script:
#!/bin/bash
# Block pushes that touch sensitive paths
SENSITIVE='package-lock\.json|pnpm-lock\.yaml|yarn\.lock|\.github/|migrations/|Dockerfile|docker-compose'
DIFF_FILES=$(git diff --name-only HEAD~1)
if echo "$DIFF_FILES" | grep -qE "$SENSITIVE"; then
echo "✗ Sensitive-path changes detected, please review manually:"
echo "$DIFF_FILES" | grep -E "$SENSITIVE"
exit 1
fi
Layer 2: CODEOWNERS gating
.github/CODEOWNERS:
# Default owner
* @team-lead
# Sensitive paths must be approved by their owners
package-lock.json @team-lead
pnpm-lock.yaml @team-lead
.github/ @team-lead
migrations/ @db-team
Dockerfile @infra-team
src/auth/ @security-team
Once Codex changes trigger a PR, GitHub auto-requests review; nothing merges without owner approval.
3. Who reviews Codex changes
After CODEOWNERS triggers, owners look at Codex diffs through this lens:
| Focus | Why |
|---|---|
| Any unrelated changes ("drive-by fixes") | Codex easily touches unrelated code; demand strict scope |
| Tests covering new logic | Codex often "forgets" to add tests |
| Naming aligned with team conventions | Codex doesn't know your team's naming preferences |
| Comments explain why, not just what | Codex defaults to "what"; teams need "why" |
| Edge cases handled | Codex defaults to happy path |
Tip: require Codex to self-check in the prompt:
After writing the code, self-check:
1. Any unrelated changes? If so, revert them.
2. Is new logic covered by tests? If not, add them.
3. Do comments explain "why" instead of just "what"?
4. Are there any unnecessary console.log / debugger statements?
5. Does the diff scope match the task description exactly?
4. Run multiple Codex tasks concurrently
Yes — give each its own worktree + branch:
git worktree add -b codex-fix-bug ../codex-fix-bug main
git worktree add -b codex-add-feature ../codex-add-feature main
git worktree add -b codex-update-deps ../codex-update-deps main
Caveats:
- Concurrency burns through Codex quota fast (billed per token / call)
- Tasks must not modify overlapping files (avoid merge conflicts)
- Plan the merge order — usually bug fixes first, then features, then deps
5. CI integration
Must run: lint + unit tests + type check
# .github/workflows/ci.yml
on: pull_request
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: pnpm install
- run: pnpm lint
- run: pnpm test
- run: pnpm typecheck
CI must pass to merge. If Codex changes fail lint or tests, the PR is auto-flagged red.
Optional: let Codex write the PR description
.github/pull_request_template.md:
## Summary of changes
<!-- Codex auto-fills -->
## Related issue
<!-- link issue -->
## Test environment
<!-- which Node version, which browser -->
## Test coverage
<!-- tests added for new logic -->
## Screenshots / recordings
<!-- required for UI changes -->
When Codex writes a PR, it follows the template — changelog, linked issue, and test environment are immediately visible to the reviewer.
6. Security checklist
| Risk | Defense |
|---|---|
| Codex changes lockfiles / CI config | Hooks + CODEOWNERS |
| Codex touches secrets | Never commit .env / secrets; prompt forbids Codex from emitting secrets |
| Codex auto-pushes | By default Codex operates locally; for auto-PR use codex --ci mode |
| Codex introduces security bugs | CODEOWNERS forces security-team review (src/auth/, src/api/) |
7. Team rollout pace
- Week 1: One developer starts, establishes the workflow
- Week 2: 2-3 more developers join, iterate the flow
- Week 3: CODEOWNERS + CI running, full team onboarded
- Monthly: review Codex change quality, tune prompt templates and CODEOWNERS
8. What's Next
- Getting started with OpenAI Codex CLI: from install to daily use
- Function Calling with the OpenAI API: A Complete Guide to Tool Use in the Responses API
- Build Your Own MCP Server: From Zero to Published
Key points
- Each Codex task runs in an independent git worktree; keeps the main branch clean and makes diff review easy
- Sensitive paths (lockfiles / CI config / DB migrations) are protected by hooks + CODEOWNERS, blocking automated writes
- Enforced CODEOWNERS review: any file Codex touches must be approved by its owner
- CI must run: lint + unit tests + type check; Codex changes that fail CI do not merge
- Prompt Codex to self-check: drop debug comments, keep tests, don't 'drive-by optimize' unrelated code
Frequently asked questions
Official references
Related articles
Subscribe to GPTMap Weekly
One email every Monday: curated OpenAI updates, deep dives, and best practices. No ads, unsubscribe anytime.