Click-to-copy affordance on agent-designated content
Summary
Add a clickable [copy] affordance that Claude Code renders inline after content the
agent marks as copy-worthy (shell commands, code blocks, file paths, identifiers).
Clicking it copies the original text verbatim to the system clipboard. This replaces
both manual text selection and the current request-driven clipboard workflow.
Problem
Two recurring frictions make it hard to get text out of a Claude Code session and into
another terminal or editor:
- Selecting rendered output is unreliable. Text in the TUI has been reflowed for
display — line wrapping inserts newlines, list and code indentation adds leading
whitespace, and markdown styling is baked into the rendered glyphs. Copying a
command by mouse selection therefore captures wrapping artifacts and indentation
that must be cleaned up by hand before the command will run.
- The current clipboard workflow is request-driven and fragile. Putting text on
the clipboard today requires explicitly asking the agent to do so. The clipboard is
a single shared slot, so any later write clobbers the previous contents before the
user is ready to paste. A dedicated turn is often spent solely to place one command
on the clipboard, which is an expensive use of context for a trivial result.
The underlying mismatch is that clipboard population is currently push-on-request
(the agent writes eagerly when asked), when what the user wants is pull-on-demand
(the content is offered, and the user takes it at the moment of use).
Proposed solution
A two-part mechanism:
- Agent-facing primitive. A way for the agent to designate a span of text as
copy-worthy — for example, a tool call or an inline markup marker that wraps the
exact bytes to be copied. The agent supplies the canonical text once; rendering and
clipboard handling are left to the client.
- Client-side affordance. Claude Code renders a small
[copy]control next to any
designated span. The user clicks it when ready, and the original bytes are written to
the system clipboard. Because the copied text comes from the agent-supplied source
rather than the rendered buffer, it is free of wrapping, indentation, and styling
artifacts.
This makes the workflow pull-on-demand: the content is offered without committing the
clipboard, the user takes it at the moment of use, and no conversational turn is spent
managing the clipboard.
Feasibility
Both required terminal capabilities are standard and widely deployed:
- Click detection via the SGR mouse protocol (xterm 1006). A full-screen TUI that
owns the input loop — which Claude Code is — can enable mouse tracking, render the
affordance, hit-test click coordinates against it, and act. Every mainstream TUI
framework (Textual, Bubble Tea, ratatui) implements clickable widgets this way.
- Clipboard write via OSC 52 (
ESC ] 52 ; c ; <base64> ESC \). The application
emits the escape sequence and the terminal places the decoded text into the system
clipboard verbatim. This needs no external helper (wl-copy, xclip), works over
SSH, and never touches the rendered text, so no wrapping or markdown mangling is
possible.
Why this belongs in Claude Code
The TUI owns the input loop and the render buffer. Mouse hit-testing and OSC 52
emission both require that ownership, so the feature cannot be supplied from inside a
conversation or by an external skill — it has to be implemented in the client itself.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗