Episode 11 of 11

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

FlagDescriptionDefault
--filesGlob pattern for target filesRequired
--promptInstruction to apply to each fileRequired
--workersNumber of concurrent workers4
--cloudRun workers in the cloudfalse
--dry-runPreview changes without applyingfalse
--auto-mergeAutomatically merge branchestrue

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:

  1. Setup — Installation and API key configuration
  2. Cloud Tasks — Offloading work to secure containers
  3. Code Review — Automated security, performance, and style analysis
  4. CLI Mastery — Interactive chat, direct commands, and piping
  5. Session Management — Resuming work and dry-run testing
  6. AGENTS.md — Keeping AI aligned with your standards
  7. IDE Extension — Ghost text, inline chat, and sidebar
  8. Reasoning — How Codex plans and tracks its work
  9. MCP Servers — Connecting to GitHub, databases, and APIs
  10. Cloud Delegation — Master/sub-agent orchestration
  11. Parallel Processing — Batch transformations at scale

Happy coding with Codex! 🚀