Video summary

I Cut My OpenCode Token Usage by 96% - Here's How

Main summary

Key takeaways

Technology

What the video explains (token cost problem)

  • Using OpenCode with an AI coding agent, the creator found that even a trivial message like “hello” triggered surprisingly high LLM usage: about 8,000 tokens.
  • Tokens are estimated as ~4 characters each; an English word is ~1.3 tokens. Roughly:
    • 1 A4 page ≈ 750 words ≈ ~1,000 tokens
    • so 8,000 tokens ≈ ~8 pages of text.
  • The creator’s point: the cost is not just the user message. A large portion is prompt “scaffolding” sent to the LLM every request.

Why “hello” costs so much (what’s being sent to the LLM)

OpenCode makes two LLM calls per interaction:

  1. A call to generate a conversation/title automatically (≈ 500 prompt tokens + 1,500 completion tokens), totaling ~2,000 tokens—even though the user didn’t ask for it.
  2. The actual message handling call for “hello”.

In the second call:

  • The user message (“hello”) is tiny (≈ 5 characters).
  • But the system prompt is enormous (≈ 9,500 characters / ~114 lines).
  • The system prompt contains extensive behavioral instructions (tool usage rules, formatting guidance, emoji rules, etc.).

Additionally, each request includes 11 tool definitions every time, each containing:

  • tool name
  • full descriptions
  • full JSON schemas for parameters

These tool schemas massively inflate prompt size, e.g.:

  • bash tool ~4,700 characters
  • task tool ~3,000 characters
  • plus others like edit (~1,300) and read (~1,100)

The creator’s quantification:

  • “hello” itself is only about 0.025% of the request
  • most tokens are the scaffolding/tool definitions.

Why provider-side caching doesn’t solve it for the user

OpenCode’s prompt parts may be cacheable, and the creator acknowledges providers cache system prompts.

However, even if caching reduces compute cost at the provider, the tokens still:

  • are transmitted
  • count toward context window usage
  • add latency

Net effect: caching can be a provider cost optimization, not a full user savings on bandwidth/processing/context.


The tutorial: how to cut token usage by ~90%+

Step 1: Use MITM to observe real request/response

The creator couldn’t get useful token-level visibility from OpenTelemetry traces (no prompt content or tool breakdown).

So they set up:

  • a MITM proxy
  • with a small ~40-line Python script

The script:

  • intercepts requests
  • looks for system role messages
  • dumps the full request and response to JSON

This revealed the two-call behavior and the huge system/tool payloads.

Step 2: Use custom “minimal agents” to reduce system prompt/tool scaffolding

Solution: agent engineering—start minimal instead of using OpenCode’s default agent configs.

OpenCode supports custom agents via filesystem configuration:

  1. Create a global (or local) folder:
    • .{opencode}/agents (in the described workflow)
  2. Add an agent markdown file (e.g., agentx.md)
  3. Fill it with basic agent description/config (copied from a GitHub repo template)

In the example, the custom agent (“Agent X”) is:

  • primary
  • configured with a minimal prompt
  • no tools by default (intentionally stripped down)

Step 3: Compare token usage results (new session)

Reported results:

  • Baseline: out-of-the-box OpenCode “build” agent
    • still ~8,000+ tokens for “hello”.
  • After switching to the custom minimal agent in a fresh session, the creator reports roughly:
    • ~300–500 tokens
    • i.e., ~90%+ reduction (orders of magnitude improvement)

Trade-offs / limitations

The minimal agent lacks capabilities like:

  • task tool (delegation)
  • web fetch tool
  • file-writing tools

The creator’s argument:

  • For many interactions (simple edits/questions), you don’t need the full tool universe and edge-case-heavy system prompt.
  • Recommendation: add tools back selectively only when needed.

Takeaway values given

  • “8,000 tokens → about 300” (approximate headline result)
  • No “magic”—just reducing what’s sent in the system prompt + tool schemas.

Where the repo/resources are mentioned

The creator states the following are in a GitHub repo:

  • the MITM proxy script
  • the agent config
  • the overall setup mentioned for reproducing the investigation

They also tease a follow-up video about building a website using multiple strategies and comparing token usage.

Main speakers / sources

  • Speaker/source: Adam (referred to as “Come on, Adam” and later “I’ll see you there,” implying the creator is Adam)
  • Product/service: OpenCode AI coding agent
  • Related tech referenced: LLM API calls; MITM proxy; a custom Python script; (attempted) OpenTelemetry support; GitHub repo with scripts/config templates

Original video