Batch Processing: Automating Many Similar Tasks
Hundreds of similar tasks run automatically: via claude -p in a loop, or through batch APIs at half price (as of July 2026).
The idea
Some tasks are really many identical tasks: migrate 500 files, classify 2,000 texts, translate every product description. You don't need to chat 500 times for that โ batch processing handles them automatically.
Path 1: headless fan-out
Claude Code also runs without an interactive session via claude -p "task". Inside a script loop over a file list, this becomes a fan-out: one invocation per file. The official docs recommend three steps: generate a task list, build the loop, test on 2โ3 files first and sharpen the prompt โ then run it on everything. --allowedTools limits what the agent may do unattended.
Path 2: provider batch APIs
For pure model requests without tools there are batch APIs: you submit many requests together and they are processed asynchronously. Anthropic (Message Batches API) and OpenAI (Batch API) charge 50% of the standard prices for this (as of July 2026). At Anthropic, most batches finish in under an hour; at OpenAI a 24-hour window applies (as of July 2026).
Batch or interactive?
Batch pays off when the tasks are independent and uniform and the result is not needed immediately. Stay interactive when you want to steer, review, or correct along the way โ or when the task only becomes clear while working.
EXAMPLE
A team needs to classify 1,200 support tickets by topic. Instead of 1,200 individual requests, it submits one batch to the Message Batches API โ half price (as of July 2026), results collected together after the run.
QUICK QUIZ
When is a batch API the right choice instead of individual interactive requests?
SOURCES
- Anthropic Docs: Batch Processing (Message Batches API) โ platform.claude.com
- OpenAI Docs: Batch API โ developers.openai.com
- Claude Code Docs: Non-interactive Mode (claude -p) โ code.claude.com
- Claude Code Docs: Best Practices (Fan out across files) โ code.claude.com