Saving tokens in opencode: a checklist of settings and habits

opencode spend comes from habits and a few lines of config. A checklist you can verify: what to turn on, what to remove, and how to see the result in the dashboard.

6 min · · экономия · агенты

Token spend in opencode is almost never about one request. On every step the agent sends the model the whole accumulated conversation, so what gets expensive is not hard tasks but long sessions with extra context. Below is a checklist for opencode token savings: each item explains why it matters and how to verify the effect. Prices are as of October 18, 2026; the current list is GET https://api.zukko.pro/v1/models or the Models page in the dashboard.

Why spend grows: a short calculation

Say the session context has grown to 120,000 tokens and the agent makes 30 steps in a row on claude-sonnet-5-5 (input $0.4, cache read $0.05 per 1M tokens). We count only the incoming context, without output and cache writes:

  • without cache: 120,000 × 0.4 / 1,000,000 = $0.048 per step, 30 steps = $1.44;
  • with cache reads: 120,000 × 0.05 / 1,000,000 = $0.006 per step, 30 steps = $0.18.

This is an upper bound for illustration, not a forecast: a real cache does not hit on every step. But the conclusion holds: every extra token in the context is paid for again on each following step, so everything below comes down to two things. Less context, and a cheaper model wherever the strong one is not needed.

The checklist

1. One session, one task

When a task is done, start a new session (in the TUI it is /new, by default ctrl+x n). Old file reads and test logs are not needed for the next task but keep riding along in every request. This is the cheapest habit on the list: nothing to configure.

2. Compact the context by hand at stage boundaries

The /compact command (also /summarize, ctrl+x c) replaces history with a short summary. Do it after a finished stage rather than when the window is nearly full: automatic compaction will fire at an awkward moment and may lose something you needed.

3. Enable prune and check the compaction block

According to the opencode documentation, compaction is configured in opencode.json:

bash
{
  "$schema": "https://opencode.ai/config.json",
  "compaction": {
    "auto": true,
    "prune": true,
    "reserved": 10000
  }
}

auto (on by default) compacts the session when the context fills up, prune removes old tool outputs (off by default), and reserved keeps a window buffer for the compaction itself. Command output and file contents are the main ballast in an agent session, so prune: true is worth trying. Defaults may change between versions, so check the opencode documentation.

4. Keep AGENTS.md short

The rules file goes into the context of every session. The /init command creates a starting version, but trim it to what the agent really needs: build and test commands, project layout, non-obvious conventions. If you pull in whole directories through the instructions field with a glob (for example .cursor/rules/*.md), remember that every matched file also rides along in each request.

5. Give small tasks to a cheap model

opencode has a small_model field for lightweight operations such as generating a session title. If it is not set, opencode tries to pick a cheaper model from your provider and otherwise uses the main one. Through Zukko it may look like this: Claude goes through the Anthropic provider (connection setup is in the Zukko docs for opencode), and a separate OpenAI-compatible provider with a cheap model is added for small tasks:

bash
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "anthropic": {
      "options": {
        "baseURL": "https://api.zukko.pro/v1",
        "apiKey": "fetch_..."
      },
      "models": {
        "claude-sonnet-5-5": {},
        "claude-opus-5-5": {}
      }
    },
    "zukko-openai": {

The /v1 suffix is needed here specifically for opencode: without it requests go to the wrong path and return 404. The Anthropic provider serves Claude models, while deepseek-v4.1-flash is connected through the @ai-sdk/openai-compatible package and referenced as <provider-id>/<model-id>. The zukko-openai ID is arbitrary. Check the provider format against the Providers section of the opencode docs.

6. Split agents by role

opencode has the primary agents Build and Plan and the built-in subagents General, Explore and Scout, and the config lets you define your own agent with its own model:

bash
{
  "agent": {
    "review": {
      "description": "Diff review without edits",
      "mode": "subagent",
      "model": "anthropic/claude-sonnet-5-5",
      "permission": { "edit": "deny", "bash": "deny" }
    }
  }
}

The idea is simple: exploration and review do not need the most expensive model, and by forbidding edits you also cut pointless steps. For planning, the built-in Plan agent is convenient; per the docs it is restricted in what it can change.

7. Model price versus the intelligence index

Comparison as of October 18, 2026, $ per 1M tokens (input / output), Artificial Analysis intelligence index:

ModelInput / outputIndex
claude-opus-5-50.8 / 458
claude-sonnet-5-50.4 / 248
gpt-6.1-sol0.27 / 1.3252
deepseek-v4.1-flash0.013 / 0.03839
glm-5.3-flash0.04 / 0.0442

The index does not replace testing: take two or three typical tasks from your project and run them on different models. Then the decision about where a cheap one is enough is yours, not someone else's.

8. Do not switch models mid-session

Prompt caching has its own logic: it is tied to the request prefix and, as a rule, to the model. Switching models in the middle of a long session usually means the whole accumulated context is billed again as fresh input (and, for Claude, as a cache write). Change models at task boundaries.

9. Watch the cache

For Claude, the gateway sees the cache discount in the Anthropic format: cache reads and writes are billed at their own prices (for claude-sonnet-5-5 read $0.05, write $0.5 versus input $0.4). In opencode the Anthropic provider uses exactly that format, so the cache is accounted for. You can verify it in practice on the Usage page of the dashboard: compare the cost of two similar sessions.

10. Limit tools and MCP servers

The description of every connected MCP server and tool is, as a rule, added to the request. Turn off what you do not use in this project. And the permission section lets you require confirmation for risky actions:

bash
{
  "permission": { "edit": "ask", "bash": "ask" }
}

According to the opencode docs, most permissions default to allow, so they run without approval; only external_directory and doom_loop (triggered when the same tool call repeats three times with identical input) default to ask. Confirming edits and commands also interrupts useless loops: you see the agent running the same command for the third time.

11. Give precise assignments

"Fix everything" makes the agent read half the project. "In src/api/client.ts the retry function ignores 429, fix it and run npm test" reads two files. Name the file, the symptom and the way to check.

12. Put a limit on the key

A separate key for opencode with a daily and monthly limit in $ protects you from an agent stuck in a loop. Limits are soft: a request started before the ceiling is reached will complete, so leave a margin. You can also restrict the list of allowed models (allowed_models). Details are in the key limits documentation. If the agent hits the limit, you get a 429 with the code key_daily_limit_reached or key_monthly_limit_reached.

How to confirm it got cheaper

  1. Note your spend for a normal working day on the Usage page of the dashboard.
  2. Apply one change from the checklist at a time (for example prune and a cheaper model for review).
  3. A few days later, compare spend on similar tasks.

Do not expect a universal result: it depends on the project, session length and chosen models. You create a key in the Zukko dashboard, and the same key works in both API formats.

FAQ

Is enabling prune and compaction enough?

They remove ballast but do not replace habits. If a session covers five different tasks, compaction will preserve a summary of all five. Start a new session for each new task.

Can I use a non-Claude model for small tasks?

Yes, but through a separate OpenAI-compatible provider in the opencode config with the address https://api.zukko.pro/v1. Keep in mind that in the OpenAI format Claude gets no cache discount while GPT does, so keep the Anthropic provider for Claude.

How much does one working day cost?

It depends on the model and session length. Use the formula: fresh input × input price + cache read × read price + cache write × write price + output × output price. Plug in numbers from the response usage or from the dashboard.

What if the agent hits the key limit?

Raise the limit in the dashboard or create a new key for the task. Other account keys keep working, because the limit applies to the key, not to the balance.

zukko

Pay 25×
less

for Claude Code & ChatGPT

One fetch_* key and base URL api.zukko.pro — for Cursor, Claude Code, Codex, and any SDK.

Get API keyDocumentation

api.zukko.pro · fetch_*

opencode token savings: a settings checklist · Zukko