Optimizing Token Costs with Parallel Agents
Running 10 agents in parallel costs 10x per hour. Here's how to maximize what you get for that spend.
The Token Cost Model
Claude API pricing is per token: input tokens (what the agent reads) and output tokens (what the agent generates). For coding agents, input typically dominates: reading source files, reading error messages, reading test output. The goal of cost optimization is getting maximum useful output per token spent.
Biggest Cost Wins
1. Right-size the model
This is the single biggest lever. Haiku is ~10-20x cheaper than Opus per token. Most coding tasks don't require Opus-level reasoning. Use Sonnet for the bulk of your work, Opus only for complex architecture decisions.
| Task type | Recommended model |
|---|---|
| Documentation generation | Haiku |
| Test writing (standard patterns) | Haiku or Sonnet |
| Feature implementation | Sonnet |
| Complex refactoring | Sonnet |
| Architecture design + hard bugs | Opus |
2. Write precise task descriptions
A vague task ("fix the auth stuff") leads to an agent reading many files speculatively before finding the right one. A precise task ("Fix the JWT expiration bug in src/auth/middleware.ts line 47 — the token TTL should use seconds not milliseconds") goes straight to the problem. The precise task uses 5-10x fewer tokens to complete.
3. Set explicit file scope
Instruct agents to read only the files relevant to their task. "Only read files in src/api/users/ and src/models/user.ts" prevents agents from scanning the whole codebase for context they don't need.
4. Use short-horizon tasks
A 4-hour task consumes a large context window and may require compaction (losing context quality). Four 1-hour tasks on four agents cost the same in wall-clock time, but each agent operates at full context efficiency. Shorter tasks = better quality per token.
5. Don't run agents that are stuck
A stuck agent in a loop can burn thousands of tokens making no progress. Set up monitoring — check the dashboard every hour, kill sessions that haven't committed any code in 2 hours, redirect them with clearer instructions.
Measuring Your Cost
amux tracks per-session token spend in the dashboard. Check it daily. If one session is consuming 5x the tokens of others, it's either working on a legitimately harder task or it's stuck in a loop. Investigate.
Get started with amux
Run dozens of Claude Code agents in parallel. Python 3 + tmux. Open source.
git clone https://github.com/mixpeek/amux && cd amux && ./install.sh
amux register myproject --dir ~/Dev/myproject --yolo
amux start myproject
amux serve # → https://localhost:8822View on GitHub