How to Measure Cost Per Task with Terminal AI Agents
Terminal AI agents like OpenCode and Claude Code bill by the token, which makes cost per task 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-07-16
Multi-Agent Terminal Workflows: Combining OpenCode, Claude Code, and Aider
Running more than one AI coding agent in your terminal is becoming a real workflow. Here is how we split work between OpenCode, Claude Code, and Aider without losing track of the changes.
2026-07-16
OpenCode First Project Setup: From Install to First Passing Test
A practical setup guide for OpenCode on an existing project. Configure providers, context files, and project conventions so the agent produces useful output on day one.
2026-07-16
Running OpenCode with Local LLMs for Private AI Coding
You do not need to send source code to a cloud API to use an AI coding agent. Here is how we ran OpenCode against a local Ollama model for a proprietary codebase.
2026-07-16
OpenCode Review: A Terminal-Native AI Coding Agent That Keeps Your Editor
We tested OpenCode as a daily driver for two weeks. It is a terminal-based AI coding agent that edits files, runs tests, and supports multiple models without replacing your IDE.
2026-05-28
Aider Review: The Open-Source AI Pair Programmer That Works With Any LLM
I tested Aider across 9 projects with 6 different LLMs over six weeks, spending $47.30 total in API costs. Here's why git-native pair programming is better than accept/reject buttons — and where Aider's terminal-only approach falls short.
Get the best tools, weekly
One email every Friday. No spam, unsubscribe anytime.