CDX-201b · Module 2
Batch Operations & Best-of-N
3 min read
Batch operations let you submit structured sets of tasks — migrating dozens of files, updating tests across modules, or applying a convention change across the codebase. The pattern: define the scope (which files or modules), define the transformation (what to do), and let Codex Cloud execute each unit as a parallel task.
Best-of-N is a cloud feature where Codex runs the same task multiple times with different approaches and lets you pick the best result. This is valuable for open-ended tasks where quality varies between runs — UI implementation from a mockup, algorithm optimization, or architecture proposals. You get N candidates, review each, and select the one that best meets your criteria. The cost is N times a single run, but the quality improvement can be substantial.
# Batch: migrate all API routes to new error handling
for module in auth payments users orders; do
codex cloud "migrate src/routes/${module}.ts to use \
the new ErrorEnvelope pattern from src/utils/errors.ts" &
done
# Best-of-N: get 3 approaches to a complex task
codex cloud --attempts 3 \
"design and implement a caching layer for the product catalog API"
Do This
- Use batch operations for repetitive transformations across many files
- Use best-of-N for design decisions where multiple valid approaches exist
- Review all N candidates — sometimes the best solution combines elements from multiple runs
- Set a budget before running best-of-N on expensive tasks
Avoid This
- Batch tasks that depend on each other — process them sequentially instead
- Use best-of-N for deterministic tasks like "rename variable X to Y" — one run is sufficient
- Submit unbounded batches — start with 3-5 parallel tasks and scale up after validating the pattern
- Forget to aggregate and compare results — the value is in the comparison, not just the execution