[Question] Is automatic tool calling output truncation supported?
Question
I am trying out Opencode as a potential replacement for Codex. One thing I have noticed, that sometimes the model attempts to read a huge file or runs a "glob" tool call with wildcards which result in results north of 100k tokens in a single tool call output. This negatively impacts the performance of the model, as well as cause cost issues.
Is there some configuration that I can use to automatically truncate the output of tool calls, and let the model know it's been truncated so it can adjust its tool calls to find the relevant information? It's the one thing that Codex seems to do a lot better, but other than that I am really liking opencode so far.
Thanks!
This issue might be a duplicate of existing issues. Please check:
- #4659: [FEATURE] Sliding window context management for long-running sessions - Addresses token consumption and performance in long sessions
- #3031: Model in BUILD mode does not have enough context to continue after compaction - Related context and token management issue
- #4733: exclude node_modules - Related concern about large outputs consuming tokens unnecessarily
Feel free to ignore if your specific case about automatic tool output truncation differs from these context management discussions.
This one is a little bit extreme, but maybe it explains the issue I am having:
{"error":{"code":400,"message":"the request exceeds the available context size, try increasing it","type":"exceed_context_size_error","n_prompt_tokens":1463244,"n_ctx":262144}}
It was caused by the model trying to grep something with way too many results
Claude Code handles this quite well by delegating such tasks to the "explore" subagent so the tool calls don't pollute the main agent's context window. I wonder if you try defining such an agent for yourself. Or even just instructing the model to use Opencode's "general" subagent to delegate such tasks.
we can be fancier here but rn we do automatically prune sufficiently old tool calls from context to free up space
Claude Code handles this quite well by delegating such tasks to the "explore" subagent so the tool calls don't pollute the main agent's context window.
That wouldn't fix this particular case though. This single tool call returned over a million token. A subagent would fail to run with such a big tool call result as well. Sure, it won't pollute the main agent's context window, but it's not retrieving the right answer either.
we can be fancier here but rn we do automatically prune sufficiently old tool calls from context to free up space
This is only helpful if the tool call itself did not result in the context window overflowing. And even if it didn't, it's still a lot of trash in the context. Would it be a bit think to just truncate the output after 500 lines or so (maybe make it configurable). And if it is truncated, let the model know with some text like "Truncated, only showing first 500 lines out of 21416".