Why Saying ‘Hi’ to Our OpenCode Agent Used 177,000 Tokens
At Bold.org, people use our internal company agent to investigate production issues, look up information, and put together reports. It runs on OpenCode, connected to the systems where that information lives. I have gradually added more integrations as people found useful things to do with them, and for the most part that has worked well. Over the last few days, though, we started reaching our AI…
At Bold.org, users utilize an internal company agent to investigate production issues, search for information, and create reports. This agent operates on OpenCode and is connected to the systems where the relevant information is stored. Initially, adding more integrations proved beneficial; however, token consumption suddenly surged, causing the AI usage limits to be reached earlier than anticipated.
Astra, the AI model, proved more expensive and showed a steadier growth in usage. Despite knowing that Astra was expected to utilize fewer tokens, the token consumption pattern was still alarming.
The investigation began by examining the database, which was running OpenCode 1.18.31. By querying the database for September 14 and 15, the agent identified that one Astra conversation had consumed 50.4 million tokens across 121 model calls, with 49.9 million tokens in cache reads. This data suggested that long conversations were likely the cause of the high token consumption.
Further analysis revealed that the agent's sessions started with a large context of approximately 177K input tokens, long before any results were gathered. The agent's instructions and skills were also scrutinized, but the input tokens remained substantial. The agent's tool inventory, which included Meta Ads, accounted for about 72% of the measured MCP definition text. Disabling Meta Ads led to a significant reduction in token consumption from 177,444 to 54,181.
The issue stemmed from the availability of all tools at all times, rather than just when needed. Enabling OpenCode's experimental Code Mode allowed the agent to look up tool usage only when necessary, thus reducing the starting context by roughly 92%. This modification improved the agent's performance, with a significantly smaller token usage for a simple "hi" greeting. The default setting in OpenCode 2 now includes Code Mode for MCP servers, addressing the initial concern and improving overall efficiency.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.