[Question] Is automatic tool calling output truncation supported? #3159

Open
opened 2026-02-16 17:38:54 -05:00 by yindo · 5 comments
Owner

Originally created by @Mushoz on GitHub (Nov 27, 2025).

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!

Originally created by @Mushoz on GitHub (Nov 27, 2025). ### 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!
Author
Owner

@github-actions[bot] commented on GitHub (Nov 27, 2025):

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.

@github-actions[bot] commented on GitHub (Nov 27, 2025): 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.
Author
Owner

@Mushoz commented on GitHub (Nov 27, 2025):

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

@Mushoz commented on GitHub (Nov 27, 2025): 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
Author
Owner

@nikhilmaddirala commented on GitHub (Nov 27, 2025):

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.

@nikhilmaddirala commented on GitHub (Nov 27, 2025): 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.
Author
Owner

@rekram1-node commented on GitHub (Nov 27, 2025):

we can be fancier here but rn we do automatically prune sufficiently old tool calls from context to free up space

@rekram1-node commented on GitHub (Nov 27, 2025): we can be fancier here but rn we do automatically prune sufficiently old tool calls from context to free up space
Author
Owner

@Mushoz commented on GitHub (Dec 9, 2025):

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".

@Mushoz commented on GitHub (Dec 9, 2025): > 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".
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#3159