Skip to content

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

Closed

Description

@Mushoz

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!

Activity

  1. github-actions commented on Nov 27, 2025

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if your specific case about automatic tool output truncation differs from these context management discussions.

  2. Mushoz commented on Nov 27, 2025

    @Mushoz
    Author

    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

  3. nikhilmaddirala commented on Nov 27, 2025

    @nikhilmaddirala

    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.

  4. rekram1-node commented on Nov 27, 2025

    @rekram1-node
    Collaborator

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

  5. Mushoz commented on Dec 9, 2025

    @Mushoz
    Author

    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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions