Skip to content

[FEATURE]: Configurable tool output truncation limits #22565

Closed

Description

@lingeasy

Describe the enhancement you want to request

Currently, tool output truncation limits are hardcoded in packages/opencode/src/tool/truncate.ts:

export const MAX_LINES = 2000
export const MAX_BYTES = 50 * 1024  // 50KB

When MCP servers return large tool outputs (e.g., code search results, file listings, or API responses), the content is truncated to 2000 lines or 50KB before being sent to the LLM. This limits the model's ability to process large contexts that modern models can easily handle (many models support 128K-200K context windows).

Proposed Solution:

Add configurable truncation limits to the .opencode/opencode.json config file:

{
  "experimental": {
    "tool_output_max_lines": 5000,
    "tool_output_max_bytes": 204800,
    "tool_output_truncation_direction": "head"
  }
}

Why This Matters:

  1. Modern LLMs have large context windows (128K-200K tokens), making 50KB limits overly restrictive
  2. MCP tools often return large outputs (e.g., grep results across large codebases, API responses)
  3. Users with powerful models should be able to leverage their full context capacity
  4. Backward compatible - existing behavior remains when config is not specified

Implementation:

The Truncate.Options interface already supports customization:

export interface Options {
  maxLines?: number
  maxBytes?: number
  direction?: "head" | "tail"
}

The missing piece is reading these values from config and passing them to truncate.output().

Suggested Changes:

  1. Add config schema fields in packages/opencode/src/config/config.ts
  2. Read config values in packages/opencode/src/session/prompt.ts
  3. Pass config to truncate.output() call

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 15, 2026
  2. github-actions commented on Apr 15, 2026

    @github-actions
    Contributor

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

    Please review that issue and consider whether your request is already covered there. If there's meaningful differentiation (e.g., your focus on MCP tool outputs specifically), please clarify the distinction.

  3. lingeasy commented on Apr 15, 2026

    @lingeasy
    Author

    Thanks for the duplicate check. I see #13770 covers the configurability aspect (point #2), but that issue is broader and focuses on multiple truncation problems.

  4. Sogl commented on Apr 21, 2026

    @Sogl

    I also need this feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions