TUI selection spams clipboard on every render during streaming

Open 💬 5 comments Opened Apr 1, 2026 by dewierwan

Description

Claude Code's TUI writes selected text to the system clipboard on every re-render during streaming, flooding clipboard managers (e.g. CopyClip, Maccy, Paste) with hundreds of partial text fragments.

Reproduction

  1. Open Claude Code CLI in a terminal (tested in Warp on macOS)
  2. Have a clipboard history manager running (e.g. CopyClip)
  3. Select some text in the Claude Code TUI (mouse click-drag)
  4. Ask Claude something that produces a streaming text response
  5. Check clipboard history — it will contain dozens/hundreds of entries with partial text fragments, space-padded to terminal width

Root cause (from binary analysis)

The clipboard write function (BM in the minified bundle) fires during TUI re-renders when a text selection is active. Each streaming chunk triggers a re-render, which re-syncs the selection to clipboard.

Additionally, the function writes to clipboard via two mechanisms simultaneously:

  • OSC 52 escape sequence (terminal clipboard protocol)
  • pbcopy subprocess (macOS) / xclip/xsel (Linux)

This means each re-render may produce 2 clipboard writes.

Evidence

Pasteboard monitoring with a Swift script showed:

  • Zero clipboard writes at idle (no Claude streaming)
  • Zero clipboard writes during tool calls (no visible text output)
  • 5+ writes per 20 seconds during text streaming, containing fragments of the streamed response
  • Zero clipboard writes during non-Claude terminal output in the same terminal (Warp)

The macOS pasteboard change count reached 4996+ during a single session.

Expected behavior

  • Clipboard should only be written on explicit user action: /copy command, Cmd+C, or equivalent
  • TUI re-renders should not re-sync selection to clipboard
  • If selection-to-clipboard is intentional, it should be debounced during streaming (e.g. only write on selection end, not on every frame)
  • Consider not using both OSC 52 and pbcopy simultaneously (double-writes)

Environment

  • Claude Code CLI (Bun binary, installed via ~/.local/bin/claude)
  • macOS (Darwin 25.3.0, arm64)
  • Terminal: Warp
  • Clipboard manager: CopyClip

🤖 Generated with Claude Code

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗