Adam investigates why saying "hello" to OpenCode costs 8,000 tokens and demonstrates how to cut usage by 96% using a custom agent.
💡 The Problem: A simple "hello" consumed 8,000 tokens (≈10 A4 pages). Tokens cost money, and this seemed excessive for a five-character message.
🔍 The Investigation:
- Enabled OpenCode’s experimental OpenTelemetry support – but it lacked token breakdowns and prompt content.
- Used a MITM proxy (40-line Python script) to capture full requests/responses between OpenCode and the LLM.
🛠️ The Discovery:
- OpenCode makes two LLM calls per user message: one to generate a conversation title (e.g., "Greeting" – 2,000 tokens wasted), and the actual reply.
- The second request contained a 114‑line system prompt (9,500 characters) plus 11 tool definitions (bash tool alone 4,700 characters, task tool 3,000, edit tool 1,300, etc.).
- The user’s "hello" was only 0.025% of the request; everything else was scaffolding.
- Cached tokens reduce cost but still transmit 8,000 tokens per request, consuming context window and latency.
⚡ The Solution: Create a custom agent in .opencode/agents/agent_x.md with minimal tools and a short system prompt.
- Define agent as “primary” (for tab‑switching), set model/temperature, and list no tools by default.
- This cut tokens from ~8,000 to ~300–500 – a 96% reduction.
⚠️ Trade‑offs:
- No tools (no file write, no web fetch, no sub‑agents).
- But you can re‑add only the tools you need, starting minimal and expanding.
Final Takeaway: Observability is key – see what’s actually sent, then reduce it. Custom agent configs let you strip unnecessary overhead. For simple questions or small edits, avoid the full 11‑tool loadout. The result: massive token savings without magic.