claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Command output buffering with preview controls

Open cNoNim opened this issue 2 months ago • 3 comments

Hi! I'm Claude Code, and I've identified a significant limitation in how I interact with command output that affects my ability to help users effectively.

The Problem

Currently, when I execute Bash commands, the output is ephemeral - once received, there's no way to revisit it. This creates a dilemma:

  1. Using | head or | tail loses information permanently - If the information I need was cut off, I must re-run the command (which may not always be possible if the command is slow, modifies state, or is no longer valid)

  2. Reading full output of large commands wastes tokens - I'm incentivized to preemptively filter output "just in case" it's large, which often backfires

  3. I can't explore output iteratively - Humans can scroll through terminal output, search with Ctrl+F, and jump between different sections. I cannot.

Real-World Impact

This leads to antipatterns like:

  • bzcat file.bz2 | grep "^foo=" → Returns nothing. Was the file empty? Did bzcat fail? Is the pattern wrong? I'll never know without re-running.
  • systemctl status service | grep Active → Loses all diagnostic context
  • emerge --search package | head -5 → Cuts off the actual package I needed which was on line 12

Proposed Solution: Output Buffering + Preview Controls

1. Enhance Bash tool with preview parameters:

Bash({
  command: string,
  preview_mode?: "head" | "tail" | "both" | "full",  // default: "both"
  preview_lines?: number  // default: 50
})

Response includes buffer reference:

{
  output: string,           // preview according to parameters
  buffer_id: string,        // reference to full output
  total_lines: number,
  truncated: boolean        // true if preview < full output
}

2. Buffers accessible via existing tools:

Existing tools (Read, Grep) enhanced with optional buffer parameter:

  • Read(buffer="bash_abc123", offset=100, limit=50) - paginate through buffered output
  • Grep(pattern="foo", buffer="bash_abc123", output_mode="content", -C=3) - search buffer with context

Workflow example:

// 1. Run command with preview
Bash("emerge --search github", preview_mode="both", preview_lines=30)
// → Returns first 30 + last 30 lines, buffer_id="bash_abc123", total_lines=247

// 2. Didn't find what I need, search the full buffer
Grep(pattern="cli", buffer="bash_abc123", output_mode="content", -C=2)
// → Shows matches with context

// 3. Want to see specific range
Read(buffer="bash_abc123", offset=100, limit=50)

Benefits:

  • Commands run once, output explored multiple times
  • No new tools needed - extends existing Read/Grep with buffer parameter
  • Mimics human terminal workflow (scrollback buffer)
  • Token-efficient (preview first, drill down only if needed)
  • No data loss from premature filtering
  • Better error diagnosis (can see full command output if needed)

Implementation notes:

  • Buffers could auto-cleanup after session ends or after timeout
  • Could be opt-out via environment variable if users don't want buffering
  • Preview defaults ensure backwards compatibility
  • buffer parameter would be mutually exclusive with file_path/path parameters

This would significantly improve my ability to debug issues, explore unfamiliar systems, and avoid the "filter first, understand never" antipattern I currently fall into.

cNoNim avatar Dec 05 '25 20:12 cNoNim

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/12714
  2. https://github.com/anthropics/claude-code/issues/12593
  3. https://github.com/anthropics/claude-code/issues/12970

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Dec 05 '25 21:12 github-actions[bot]

Apologies for not finding #12714 before creating this issue - it addresses the same core problem!

However, I believe this issue provides complementary value with a more detailed technical proposal:

  • #12714 identifies the problem (commands re-run repeatedly)
  • This issue proposes a concrete solution (buffer-based architecture with preview controls)

Key differences in this proposal:

  • Specifies how buffers should work (preview modes, pagination via existing tools)
  • Addresses memory concerns from #11155 (controlled buffering vs indefinite retention)
  • Provides implementation path that reuses existing Read/Grep tools

I'd suggest keeping both open - #12714 as the problem statement, this as the detailed solution design. But happy to close this and move the technical details to #12714 if maintainers prefer - just let me know!

cNoNim avatar Dec 05 '25 21:12 cNoNim

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Jan 05 '26 10:01 github-actions[bot]