How to Measure Cost Per Task with Terminal AI Agents
OpenCode and Claude Code bill by the token, so cost per task is the metric that matters. Here is how we tracked it and what we learned.
Cloud AI coding agents hide their cost behind monthly subscriptions or bundled credits. Terminal agents do not. OpenCode, Claude Code, and similar tools bill per token, which means every prompt, file read, and test run has a price. If you do not measure it, your first invoice will be a surprise.
We tracked cost per task across a two-week sprint using OpenCode and Claude Code. The goal was not to minimize spend. It was to understand which tasks were cheap, which were expensive, and where model choice mattered.
Why Cost Per Task Beats Cost Per Token
Cost per token is easy to pull from a provider dashboard, but it is misleading. A task that uses more tokens is not necessarily more expensive if it finishes in fewer turns. A task that uses fewer tokens can be expensive if the agent gets stuck in a retry loop.
Cost per task captures the whole loop: prompt, context reads, tool calls, retries, and the final diff. It is the number that maps to engineering time saved, which is the actual reason you are using the agent.
What We Measured
We logged four fields for every agent session over two weeks:
- Task description in one sentence
- Model used and provider
- Input and output tokens from the provider dashboard
- Total cost in USD
- Outcome — completed, partial, or failed
Tasks fell into three cost bands:
| Task type | Typical cost | Notes |
|---|---|---|
| Single-file edit or explanation | $0.05 - $0.20 | Low context, one or two turns |
| Multi-file refactor with tests | $0.40 - $1.20 | Reads several files, runs tests, may retry |
| Complex architectural change | $1.50 - $4.00 | Long planning, multiple tool calls, large context |
The cheapest tasks were not always the smallest. A well-scoped one-sentence request often cost less than a vague three-paragraph request because the agent did less guessing.
OpenCode
OpenCode separates the agent harness from model billing, so you can route cheap tasks to cheaper models and keep costs predictable.
Free tier available
Affiliate link · We earn a commission at no cost to you.
Model Choice Matters More Than You Expect
The biggest lever on cost is the model, not the prompt. We ran the same boilerplate-generation task through four models:
- Claude Sonnet 4.6: $0.18, highest quality
- GPT-4o: $0.12, comparable quality
- DeepSeek V3: $0.03, slightly lower quality
- Local Qwen 2.5 Coder 14B: $0.00, slowest
For routine tasks, DeepSeek V3 was good enough and cut costs by 80%. For tasks where a mistake would be expensive, Claude Sonnet was worth the premium. OpenCode made the switch trivial because the model is just a setting.
Building a Simple Cost Log
You do not need a dashboard. A spreadsheet with the five fields above is enough for the first month. After thirty tasks, you will know your baseline and can answer three questions:
- Which task types are worth automating?
- Which model should be your default?
- Where are you spending money without getting results?
Once you have that baseline, you can decide whether a subscription tool with bundled credits is cheaper than per-token billing. The answer depends on your mix of tasks, not on the headline price.
FAQ
How do I get token counts from OpenCode?
Is per-token billing cheaper than Cursor's subscription?
What is the most common waste of tokens?
Tools used in this review
Some links above are affiliate links. We may earn a commission if you sign up. See our disclosure for details.
Related reading
2026-09-02
DeepSeek MLA: 70 GB of KV Cache at 1M Tokens
No DeepSeek-V4 config is public yet. The V3 one is, and its KV-cache math tells you what a million-token window actually costs in GPU memory.
2026-08-13
A Daily LLM Digest Agent Costs $166 and 34 Hours a Year
A year of one scheduled digest agent in production: token costs per stage, infrastructure line items, and the 41 runs that needed a human.
2026-08-13
When Agent Output Passes Zod and Still Breaks the Build
Four failure classes that survive a clean parse, and the three-layer validation pass we run instead.
2026-08-13
Idempotency: Publishing Agents That Survive a Mid-Run Kill
A per-channel ledger makes cross-posting resumable. Why exit code 0 is not a receipt, and what to do when an API has no idempotency key.
2026-08-13
AI Agent Auth: API Keys vs Device Flow vs Scoped Tokens
Three credential models for non-human callers: static keys, the OAuth 2.0 device grant, and short-lived scoped tokens - and when each one fits.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.