Skip to Content
IDEsOpenCode

Tokenminning in OpenCode

OpenCode is a terminal-first AI coding agent. Every turn resends your prompt, AGENTS.md, instruction files, MCP tool schemas, and the full session history—including large tool outputs from read, grep, and bash. Most spend comes from long sessions, heavy MCP, and frontier models on routine work—not from one verbose reply.

This page is the hub for the OpenCode cluster. Use the guides below for the query you actually have (opencode stats, disable MCP, context percentage, reasoning effort, custom providers). For the general technique stack, see Where to start.

Quick checklist

  1. Run opencode stats --models --days 7 — add --tools to see tool overhead.
  2. Watch context fill in the TUI sidebar — OpenCode context usage.
  3. Use Plan for analysis; switch to Build only when ready to edit — agents guide.
  4. Keep AGENTS.md short — rules guide. Disable MCP servers you are not using.
  5. Set agent.*.steps on looping agents. Change reasoning effort in OpenCode on Plan.

Typical impact: 40–70% savings routing Plan/Explore to cheaper models; 20–50% on input trimming rules and MCP; 30–60% less context growth from compaction and new sessions per task. Benchmark on your own opencode stats output.

How OpenCode bills a request

OpenCode talks to LLM providers through your API keys (or OpenCode Zen ). Many teams use OpenRouter for one key across tools. There is no bundled subscription pool like Cursor’s Auto allowance—you pay provider rates directly.

Each agent turn sends:

  • Your prompt and @ file references
  • Rules from AGENTS.md, CLAUDE.md, and instructions in opencode.json
  • Skill metadata (full skill body loads only when the skill tool runs)
  • MCP tool schemas for every enabled server
  • The full session transcript, including prior tool outputs

Unlike Cursor’s cache-read tiers, OpenCode does not discount re-sent context unless your provider offers prefix caching (Providers). Hidden agents (compaction, summary, title) also call the model when triggered.

Guides

GuideWhat you’ll learn
Token usageopencode stats, input vs output diagnosis, reconcile with provider bills
AgentsPlan/Build, subagents, steps, default_agent, permission.task
RulesAGENTS.md, /init, instructions, skills metadata
OpenCode context usageContext percentage in the TUI, compaction, prune, /compact, new sessions
MCPDisable MCP, schema overhead, per-agent tool toggles
Change reasoning effort in OpenCodereasoningEffort, budgetTokens, variants, per-agent overrides
ProvidersCustom providers, context limits, OpenCode Zen vs BYOK

Model routing (Plan vs Build)

Default cheap, escalate only on failure — OpenCode’s version of Model routing:

AgentTypical model tier
PlanHaiku / mid-tier — analysis without full edit loop
ExploreRead-only search (@explore)
BuildSonnet-class — implementation and refactors
{ "$schema": "https://opencode.ai/config.json", "default_agent": "plan", "model": "anthropic/claude-sonnet-4-5", "small_model": "anthropic/claude-haiku-4-5", "agent": { "plan": { "model": "anthropic/claude-haiku-4-20250514" }, "build": { "model": "anthropic/claude-sonnet-4-5", "steps": 25 } } }

Use Tab to cycle Plan ↔ Build. Details: Agents, change reasoning effort in OpenCode.

Trim configuration bloat

SourceFix
AGENTS.md / instructionsShort rules; lazy read — see Rules
SkillsMetadata only until invoked; disable on Plan if unused
Custom agentsShort prompts; set steps; restrict permission.task
@ mentionsOne file, not whole trees — Context hygiene

Anti-patterns

Anti-patternWhy it fails
Frontier model on Plan and Build for every questionPaying Build’s tool loop on analysis
Five MCP servers enabled by defaultSchemas on every turn — MCP
One session for a week’s workInput tokens compound; compaction is not free
Reasoning model as global defaultThinking tokens on every grep — Reasoning
@general subagents for simple searchChild sessions with fresh context — use @explore
Last updated on