Blank white background with no objects or features visible.

Hello, EMEA! TrueFoundry is growing our footprint across Europe, the Middle East, and Africa. Read more. →

OpenCode Token Usage: How It Works, Limits and How to Optimize It

By Sahajmeet Kaur

Updated: November 16, 2026

Published: January 11, 2026

‍

⚡ TL;DR
  • Most OpenCode tokens go to re-sent history and tool output, not your prompt. Compaction, pruning and output filtering cut the most.
  • Check usage with opencode stats. On Go, limits are monthly dollar budgets per model, spent at token prices.
  • Teams need per-user attribution and budgets, which means routing OpenCode through a gateway.

OpenCode is easy to start and hard to budget. A single agent session can read dozens of files, run shell commands and loop through a fix, and every one of those steps is billed in tokens. The bill that arrives later rarely tells you which session, repo or developer caused it.

This guide explains how OpenCode token usage works, how to check it, what the Zen and Go limits mean, and which settings and plugins cut usage the most. It ends with how platform teams keep it under control across many developers. If you also run other coding agents, our guide to tracking Claude Code costs covers the same problem.

How Token Usage Works in OpenCode

OpenCode counts tokens the way every LLM tool does, in two buckets. Prompt tokens are everything sent to the model: your instruction, the files and diffs it pulled in, the system prompt and tool definitions, the conversation so far, and the output of every tool call. Completion tokens are what the model writes back, including code, explanations and the arguments it passes to tools.

For coding agents, the prompt side dominates, and the reason is the loop. OpenCode re-sends the growing conversation on every step, so a long session pays for its early file reads again and again. Providers that support prompt caching bill the repeated part at a lower rate, but it still counts toward your context window and, on Go, toward your limit.

Three things inflate the prompt more than anything else:

  • Tool output. A test run or build log can add thousands of tokens in one step, most of it noise.
  • Source code density. Syntax, indentation and symbols all tokenize, so code costs more than the same amount of prose.
  • Agent loops. Planning, editing, validating and retrying each add a full round trip with the whole context attached.

How to Check OpenCode Token Usage

The built-in way is the stats command, which reports sessions, tokens and cost, with a per-model breakdown in recent versions. The session view in the terminal UI also shows how full the context window is, which is the number to watch during a long task.

If you install the plugins covered below, /dcp stats and rtk gain show what each one saved. These tools only see your own machine, though. Once several people use OpenCode, you need request-level logs to answer who spent what. We cover that in the platform section below and in our guide to user-level LLM usage analytics.

OpenCode Usage Limits: Zen, Go and Free Models

There are three ways to pay for models in OpenCode, and they limit usage differently. At the time of writing, the Go documentation describes the plans below. Limits and model lists change often, so check the console before you plan around a number.

PlanPriceHow usage is limitedGood for
Zen (pay as you go)Prepaid credits at model token prices, plus a 4.6% + $0.31 top-up feeNo fixed cap. Optional monthly spend limit and auto top-upVariable usage and premium models
Go$10 per monthMonthly dollar limit per model ($15 to $100). Each model allows 20% in any 5 hours and 50% per weekSolo developers on lower-cost models
Go Plus$40 per monthHigher per-model limits, from 2x to 8x depending on the model (third-party estimate)Heavy individual use
Go Teams$20 per member per monthOwn limits per member, $5 per month higher than Go on each modelSmall teams
Free modelsFree for a limited timeShared rate limits that can return rate-limit errors. Some may use prompts to improve the modelLight experiments, not sensitive code

On Go, limits are dollar budgets, not request counts. A cheap model stretches the same budget much further than a premium one, so choosing the model is itself a limit-management decision. When you hit a limit, requests are blocked unless you turn on Extra Usage, which falls back to your pay-as-you-go balance. Free models also stay available, but treat them as experiments: they share rate limits and, depending on the model, your prompts may be used for training during the free period.

Common Scenarios That Drive High OpenCode Token Usage

Broad context. Pulling in whole directories to be safe, when one file would do, raises the cost of every later step.

Long-running sessions. Each turn re-sends history. A session that has drifted across three different tasks carries all three.

Noisy tool output. Verbose test, lint and build output is the biggest hidden cost in most sessions.

Unbounded agents and subagents. Without a step or retry limit, an agent can re-read a large context dozens of times.

CI and background jobs. A modest run multiplied across every pull request adds up, and nobody is watching it live.

No attribution. When you cannot see who or what is expensive, the usual response is a blunt limit that slows everyone down.

Who is spending your OpenCode tokens?

Your invoice shows a total. TrueFoundry shows the user, repo and workflow behind it. Book a short demo and we will set up per-user attribution on your own OpenCode traffic.

Book a 30-min demo →

Best Practices to Optimize OpenCode Token Usage

1. Tune compaction

Compaction replaces older conversation with a summary once the session nears the context limit. According to the OpenCode docs, you control it with three settings: whether it runs automatically, how many recent tokens stay verbatim, and how much of the window to keep free. A smaller keep value and an earlier buffer trade some recent detail for lower per-turn cost.

{
  "$schema": "https://opencode.ai/config.json",
  "compaction": {
    "auto": true,
    "keep": { "tokens": 15000 },
    "buffer": "15%"
  }
}

You can also assign a cheaper model to write summaries through agents.compaction.model. Compaction is lossy, so raise the keep value if exact recent details matter to your task.

2. Prune stale context with DCP

Dynamic Context Pruning is a plugin that removes duplicate tool calls and the inputs of old failed calls, and lets the model compress finished work into summaries. Its authors note a trade-off: pruning can lower prompt cache hit rates, so savings are largest in long sessions on providers that do not discount cached tokens. The project says development has slowed, so test it on your setup first.

3. Filter shell output with RTK

RTK, the Rust Token Killer, sits in front of shell commands and strips noise from their output before it reaches the model. One community write-up claims 60 to 90 percent reductions on common commands, but it shows no methodology, so treat that as an upper bound and measure with rtk gain.

# See totals, tokens and cost per model
opencode stats

# Prune stale context (Dynamic Context Pruning plugin)
opencode plugin @tarquinen/opencode-dcp@latest --global

# Filter noisy shell output (RTK), then check savings
rtk init -g --opencode
rtk gain

4. Match the model to the task

Price gaps between models are large. In an October 2026 snapshot of Zen prices, Claude Opus 5.5 was $4 input and $20 output per million tokens, while DeepSeek V4.1 Flash was $0.30 and $1.20. Use premium models for planning and hard debugging, and cheap ones for renames, boilerplate and summaries. Our LLM cost optimization guide covers routing patterns in more depth.

5. Scope sessions and prompts

Start a fresh session for each task so old context does not ride along. Ask for diffs instead of full files, name the file or function you want changed, and keep your AGENTS.md short, because it is sent on every request.

6. Bound agents and CI runs

Set clear step and retry limits for automated runs, and give CI jobs a stricter budget than interactive use. A loop that is capped at ten steps cannot cost a hundred.

Why OpenCode Token Usage Gets Hard to Control at Scale

Everything above works for one developer. Across a team, usage splits across laptops, CI jobs and background agents, each with its own settings. Plugins and config files help locally but do not give you a shared view or shared limits, and a stats command on one machine cannot tell you which team is over budget.

That is the point where token usage starts to look like any other shared infrastructure cost. It needs central logging, ownership, and limits that apply no matter which editor or script made the call.

Managing OpenCode Token Usage with TrueFoundry

TrueFoundry's AI Gateway sits between OpenCode and the model providers. You add it as a custom provider, so no agent code changes. The configuration below follows our OpenCode setup guide:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "tfy-gateway": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "truefoundry",
      "options": {
        "baseURL": "{GATEWAY_BASE_URL}",
        "apiKey": "<your-truefoundry-api-key>",
        "headers": { "application": "opencode" }
      },
      "models": {
        "anthropic-main/claude-sonnet-4-5": { "name": "tfy-claude-4-5" }
      }
    }
  }
}

The application header tags every OpenCode request, so the dashboard can break down tokens, cost, latency and time to first token by model, user and team. The gateway also lets you set budgets and rate limits centrally, route simple requests to cheaper models, and keep logs in your own cloud account instead of a vendor's. OpenCode needs a model with at least a 128K context window to work reliably, so check that when you pick gateway models.

TrueFoundry AI Gateway architecture showing how OpenCode traffic is routed

For fleet-wide control, OpenCode also reads a managed config layer that users cannot override. Teams use it to pin the gateway as the only allowed provider, and to point agents at an MCP Gateway so tool access is governed the same way. For the policy side, see our guide to coding agent governance.

TrueFoundry metrics dashboard showing token usage, costs and performance by model and user

See OpenCode usage per developer, today

Point OpenCode at the gateway, then watch tokens, cost and latency by user and team in one dashboard.

Book a 20-min demo →Read the OpenCode setup guide

Conclusion

OpenCode token usage is mostly a context problem. Tune compaction, prune stale output, filter noisy commands and pick the right model, and you will cut a large share of waste without changing how you work. Once more than a few people rely on it, add request-level visibility and shared limits so cost has an owner.

For platform teams

Put a budget on every coding agent

OpenCode, Claude Code and your own agents, all behind one gateway with budgets, rate limits and traces.

Frequently Asked Questions

How to check token usage in OpenCode?

Run opencode stats to see session totals plus tokens and cost per model. If you use the DCP or RTK plugins, /dcp stats and rtk gain show what they saved. For per-user or per-team numbers, route OpenCode through an AI gateway that logs every request.

What is OpenCode token usage?

It is the number of tokens OpenCode sends to and receives from the model. Prompt tokens cover your instruction, files, conversation history, tool output and system prompts. Completion tokens cover what the model writes back. You pay for them per token on Zen or with your own provider key, or they count against your dollar limits on Go.

How to reduce token usage in OpenCode?

Tune compaction so long sessions get summarized earlier, prune stale tool output with Dynamic Context Pruning, filter noisy shell output with RTK, start fresh sessions for new tasks, and use cheaper models for simple work. Bound agent steps in CI so a loop cannot run unchecked.

What are OpenCode usage limits?

On the Go plan, each model has a monthly dollar limit. It allows 20% of that limit in any five-hour window and 50% in a week. Requests are blocked at the limit unless you turn on Extra Usage to fall back to your pay-as-you-go balance. Zen has no fixed cap, only the spend limit you set.

Can an AI gateway help reduce OpenCode token costs?

Yes. A gateway adds per-user attribution, budgets, rate limits and model routing in front of OpenCode, so you can see which workflows burn tokens and stop runaway loops. It does not shrink a single prompt, so pair it with the in-tool optimizations above.

‍

Try now.

One gateway for all your models, MCP servers, and agents. No credit card needed.

Start free
Table of Contents

One Gateway for Every LLM, Agent and MCP Server

Book a 30-min with our AI expert

Book a Demo

The fastest way to build, govern and scale your AI

Book Demo
Summarize with
ChatGPT logo by OpenAI
Perplexity AI logo
Blurry red snowflake on white background, symmetrical frosty design with soft edges and abstract shape.

Discover More

No items found.
November 18, 2026
|
5 min read

Claude Code Limits Explained: Pro, Max and Ultra

No items found.
Analyzing how Cloudflare detects MCP traffic
November 18, 2026
|
5 min read

How Cloudflare Detects MCP Traffic and Helps Secure It

No items found.
November 18, 2026
|
5 min read

What Is AI Search? How It Works, Architecture, and Enterprise Use Cases

No items found.
Explaining LLM fine-tuning for enterprise AI teams
November 18, 2026
|
5 min read

A Practical Guide to LLM Fine-Tuning: Methods, Data, Costs, and Deployment

No items found.
No items found.

Recent Blogs

Black left pointing arrow symbol on white background, directional indicator.
Black left pointing arrow symbol on white background, directional indicator.
Take a quick product tour
Start Product Tour
Product Tour