home / skills / willsigmon / sigstack / batch-processing
This skill helps you process many items efficiently using batch methods like agents, API batch, or loops across tasks.
npx playbooks add skill willsigmon/sigstack --skill batch-processingReview the files below or copy the command above to add this skill to your agents.
---
name: Batch Processing
description: Process multiple items efficiently using API batch, agents, or loops
allowed-tools: Read, Edit, Bash
model: sonnet
---
# Batch Processing
Process many items without proportional token growth.
## Batch Options
| Method | Best For | Cost | Speed |
|--------|----------|------|-------|
| Claude Code agents | 5-20 items | Pro plan | Fast (parallel) |
| API Batch | 100+ items | 50% off | Async (24h) |
| API streaming | Real-time needs | Full price | Immediate |
| Loop in conversation | Sequential deps | Pro plan | Slower |
## Claude Code: Agent Swarms
### Parallel Processing
```
Process 10 files simultaneously:
[Single message with 10 Task calls]
Each agent handles one file.
All run in parallel.
Results collected together.
```
### When to Use
- 5-20 independent items
- Need results quickly
- Interactive review needed
### Example
```
"Review these 10 modules for bugs"
→ Spawn 10 explore agents
→ Each searches one module
→ Collect findings
→ Prioritize and fix
```
## API Batch Processing
### Setup
```python
from anthropic import Anthropic
client = Anthropic()
# Create batch request
batch = client.batches.create(
requests=[
{
"custom_id": f"doc-{i}",
"params": {
"model": "claude-sonnet-4-20250514",
"max_tokens": 1024,
"messages": [{"role": "user", "content": doc}]
}
}
for i, doc in enumerate(documents)
]
)
```
### Check Status
```python
status = client.batches.retrieve(batch.id)
print(status.status) # "processing" or "completed"
```
### Get Results
```python
for result in client.batches.results(batch.id):
print(result.custom_id, result.result)
```
### When to Use
- 100+ items
- Can wait up to 24 hours
- Cost is primary concern
- Predictable, repeatable tasks
### Cost Savings
```
Regular API: $3/M input, $15/M output
Batch API: $1.50/M input, $7.50/M output
50% savings on everything.
```
## Conversation Loops
### Sequential in Claude Code
```
For items that depend on each other:
"Process these files in order:
1. Read config.json
2. Generate types from config
3. Update imports based on types
4. Run tests"
Claude handles the loop internally.
```
### When to Use
- Items have dependencies
- Order matters
- Need to adjust based on results
## Efficiency Comparison
### 100 Document Reviews
```
Method 1: One by one in conversation
= 100 round trips
= Hours of waiting
= Full context each time
Method 2: API Batch
= 1 submission
= Wait overnight
= 50% cost savings
= Results in morning
Method 3: Agent swarm (10 at a time)
= 10 rounds of parallel agents
= Minutes to complete
= Can review as they finish
```
## Batch Best Practices
### 1. Consistent Prompts
```
# Batch works best with identical structure
prompt_template = """
Review this code for bugs:
{code}
Return JSON: {"bugs": [...], "severity": "..."}
"""
```
### 2. Structured Output
```python
# Parse batch results automatically
results = []
for r in batch_results:
data = json.loads(r.result.content)
results.append(data)
```
### 3. Error Handling
```python
for result in batch_results:
if result.error:
failed.append(result.custom_id)
else:
success.append(result)
# Retry failed items
```
### 4. Progress Tracking
```python
# Batch status updates
while status.status != "completed":
print(f"Processed: {status.completed}/{status.total}")
time.sleep(60)
```
## Decision Tree
```
How many items?
├─ 1-5: Direct conversation
├─ 5-20: Agent swarm
├─ 20-100: API streaming or agents
└─ 100+: API Batch
Time sensitive?
├─ Yes: Agents or streaming
└─ No: Batch (50% savings)
Dependencies between items?
├─ Yes: Sequential loop
└─ No: Parallel processing
```
Use when: Multiple similar tasks, document processing, code review at scale
This skill explains practical approaches to process many items efficiently using agent swarms, API batch requests, streaming, or sequential loops. It helps you choose the right method based on scale, cost, and dependency requirements. The guidance focuses on setup patterns, cost trade-offs, and operational best practices for reliable large-scale processing.
Agent swarms spawn multiple concurrent agents to handle independent items in parallel, returning results as each finishes. API Batch submits hundreds or thousands of requests in one job for asynchronous processing and lower cost, with status polling and result retrieval. Streaming and conversational loops handle real-time needs or ordered dependencies respectively.
How do I choose between agent swarms and API Batch?
Use agent swarms for low-to-medium volumes with tight latency needs (5–20 items). Use API Batch for large volumes (100+) where cost and throughput matter and you can accept asynchronous results.
What should my output format be for reliable parsing?
Return strict JSON with a documented schema (e.g., {"bugs":[],"severity":""}) so you can automatically parse and aggregate batch results.
How do I handle failed items in a batch?
Record failed custom_id values, implement retries for transient errors, and surface failures in a dashboard or report for manual review.