pickuma.
AI & Dev Tools

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.

6 min read

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 typeTypical costNotes
Single-file edit or explanation$0.05 - $0.20Low context, one or two turns
Multi-file refactor with tests$0.40 - $1.20Reads several files, runs tests, may retry
Complex architectural change$1.50 - $4.00Long 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

Try OpenCode

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:

  1. Which task types are worth automating?
  2. Which model should be your default?
  3. 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?
OpenCode itself does not bill you; the underlying provider does. Check your provider dashboard for input and output tokens per request, then divide by the number of tasks you completed in that session.
Is per-token billing cheaper than Cursor's subscription?
It depends on usage volume. Light users often spend less with per-token billing. Heavy users who run agents daily may find a subscription cheaper because it caps monthly cost.
What is the most common waste of tokens?
Vague prompts and overly broad context. Agents read files they do not need and iterate because the goal is unclear. A one-sentence, specific prompt usually costs less than a long, vague one.

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

See all AI & Dev Tools articles →

Get the best tools, weekly

One email every Friday. No spam, unsubscribe anytime.