Running Tasks in Parallel
Learn how to batch-process multiple files simultaneously — parallel workers, branch isolation, and intelligent auto-merging for rapid codebase transformations.
Parallel Processing Overview
While cloud delegation handles large, complex projects, parallel batch processing is designed for applying the same transformation across many files simultaneously. This turns weeks of manual refactoring into minutes.
Preparing a Batch Job
Use the batch flag to target multiple files with the same prompt:
# Convert all React components to TypeScript
codex batch --files "src/components/**/*.tsx" --prompt "Convert to TypeScript strictly"
# Add error handling to all API routes
codex batch --files "src/api/**/*.ts" --prompt "Add try-catch error handling"
# Generate unit tests for all utilities
codex batch --files "src/utils/**/*.ts" --prompt "Write comprehensive unit tests"
How It Works
1. Concurrent Workers
Codex spawns multiple worker processes — locally or in the cloud. Each worker grabs a file from the queue and processes the changes asynchronously:
🔄 Batch job started: 24 files matched
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Worker 1: Processing Button.tsx [████░░] 60%
Worker 2: Processing Card.tsx [██████] 100% ✅
Worker 3: Processing Modal.tsx [██░░░░] 30%
Worker 4: Processing Table.tsx [████░░] 70%
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Progress: 8/24 files complete
2. Branch Isolation
To prevent chaos, each worker operates on its own separate Git branch. This ensures that:
- Workers don't interfere with each other's changes
- If one worker fails, it doesn't affect the others
- You can review each branch independently before merging
# Branches created automatically:
codex/batch/button-tsx
codex/batch/card-tsx
codex/batch/modal-tsx
codex/batch/table-tsx
...
3. Intelligent Auto-Merge
After all workers complete, Codex attempts to intelligently merge all branches back into your working tree:
# Codex auto-merges the branches
✅ Merged 22/24 branches successfully
⚠️ 2 branches have conflicts — manual resolution needed
4. Manual Conflict Resolution
If merge conflicts occur, Codex presents a unified Git diff view in your IDE so you can resolve them manually:
# View conflicts
codex batch conflicts
# Resolve a specific file
codex batch resolve src/components/Header.tsx
# Accept all changes from a specific branch
codex batch accept codex/batch/header-tsx
Batch Processing Options
| Flag | Description | Default |
|---|---|---|
--files | Glob pattern for target files | Required |
--prompt | Instruction to apply to each file | Required |
--workers | Number of concurrent workers | 4 |
--cloud | Run workers in the cloud | false |
--dry-run | Preview changes without applying | false |
--auto-merge | Automatically merge branches | true |
Real-World Example
Here's a complete workflow for converting a React codebase to strict TypeScript:
# Step 1: Preview the changes
codex batch --files "src/**/*.jsx" --prompt "Convert to TypeScript with strict types" --dry-run
# Step 2: Run the conversion with 8 workers
codex batch --files "src/**/*.jsx" --prompt "Convert to TypeScript with strict types" --workers 8
# Step 3: Check for conflicts
codex batch conflicts
# Step 4: Verify the build
npm run build
# Step 5: Run the test suite
npm test
Series Complete! 🎉
Congratulations — you've covered the full OpenAI Codex toolkit! Here's a quick summary of what you learned:
- Setup — Installation and API key configuration
- Cloud Tasks — Offloading work to secure containers
- Code Review — Automated security, performance, and style analysis
- CLI Mastery — Interactive chat, direct commands, and piping
- Session Management — Resuming work and dry-run testing
- AGENTS.md — Keeping AI aligned with your standards
- IDE Extension — Ghost text, inline chat, and sidebar
- Reasoning — How Codex plans and tracks its work
- MCP Servers — Connecting to GitHub, databases, and APIs
- Cloud Delegation — Master/sub-agent orchestration
- Parallel Processing — Batch transformations at scale
Happy coding with Codex! 🚀