Skip to content

Conversation

@cgwalters
Copy link

@cgwalters cgwalters commented Jan 16, 2026

What does this PR do?

Stream command output directly to a temp file when it exceeds 50KB,
avoiding memory bloat for commands with huge output. Inspired by
block/goose#2817.

New feature:

  • output_filter param: pass a regex (e.g. "^(warning|error):") to
    capture only matching lines inline while full output goes to file

The agent is informed that Grep and Read can be used to analyze the
temp files.

UI now shows filtered output stats (e.g. "Filtered: 7 matches from
2.1 KB (1.9 KB omitted)") so users can see how much output was
filtered and the total size.

Assisted-by: OpenCode (Opus 4.5)

How did you verify your code works?

Unit tests, and also by trying it out directly. (Though I only lightly tested it interactively)

@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found:

PR #6048 - "feat('bash'): Bash tool output saves the stdout/stderr to a file if it exceeds the limit"
#6048

This PR appears to be directly related to the current PR #8953. Both address:

  • Saving command output to a file when it exceeds a size limit
  • Preventing memory bloat from large command outputs
  • File-based output streaming

There's also a tangentially related PR:

PR #7049 - "fix: clear tool output and attachments when pruning to prevent memory leak"
#7049

This PR addresses memory management in tool output, which relates to the memory optimization goal of the current PR.

The most likely duplicate is PR #6048, which implements very similar functionality. You may want to check if it was closed, merged, or if the current PR #8953 supersedes it with additional features (like the output_filter parameter and improved GC strategy).

Extract formatSize from uninstall.ts to src/util/format.ts for reuse.

Assisted-by: OpenCode (Claude Sonnet 4)
Stream command output directly to a temp file when it exceeds 50KB,
avoiding memory bloat for commands with huge output. Inspired by
block/goose#2817.

New feature:
- output_filter param: pass a regex (e.g. "^(warning|error):") to
  capture only matching lines inline while full output goes to file

Both filtered and non-filtered modes buffer in memory until the
threshold is exceeded, avoiding unnecessary filesystem I/O for
small output.

The agent is informed that Grep and Read can be used to analyze the
temp files.

UI now shows filtered output stats (e.g. "Filtered: 7 matches from
2.1 KB (1.9 KB omitted)") so users can see how much output was
filtered and the total size.

Assisted-by: OpenCode (Claude Sonnet 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant