Copying a command from an assistant code block includes Markdown fences#23930

opened12d agobyMMCKevmeister

What happened

"Copying commands also copies the markdown." Copying a command from an assistant message in chat puts the Markdown code fences (```bash … ```) on the clipboard along with the command.

Diagnosis

Copying a selection in chat goes through serializeRenderedMarkdownFragment (apps/web/src/markdown-clipboard.ts). It returns plain text only when soleCodeBlock() finds that the selection holds exactly one <pre> and nothing else. Any other content in the range turns the whole selection into Markdown, and the code block gets fences via serializeCodeBlockToMarkdown. Other content includes non-whitespace text from the paragraph before or after, a list item, or a second block. A small overshoot past the block's edges is enough, so copying a command by selecting it often yields fenced text. #4741 and #8042 fixed specific edge cases (partial selection, triple-click on the final line), but the underlying behaviour remains: a selection that touches a code block and anything else copies the code wrapped in fences.

Steps to reproduce

  1. Ask the agent for a shell command so it replies with a fenced bash block.
  2. Select the command, letting the selection run slightly past the block into the surrounding message text.
  3. Copy (Cmd+C) and paste into a terminal.
  4. The paste includes ```bash and the closing fence.

Expected: selecting part of an assistant message and copying it gives the text as shown on screen, without Markdown fences being added around code. Copy-as-Markdown could be opt-in (e.g. a setting or a modifier key) rather than the default.

Version

0.1.2 (desktop app, "T3 Code (Beta)", local server)

Environment

macOS 27.0 (arm64), Node v26.12.1, desktop app against local server

Evidence

No logs relevant; behaviour is in apps/web/src/markdown-clipboard.ts at v0.1.2 (soleCodeBlock, serializeRenderedMarkdownFragment).

#4741, #8042: earlier edge cases of the same symptom, both closed as fixed. This one is still present on 0.1.2 and covers the general case rather than a single edge case.

Fix applied or workaround

None. The code block's Copy button copies the whole block, which doesn't help when selectively copying part of an answer (e.g. one command, or a command plus some surrounding text). No practical workaround.

Filed by

Claude Code (claude-opus-5-5) via t3 triage

Synced from GitHub

Note, a painful experience to use triage. Did so much that it didn't need to. NEVER going to do this again unless the triage feature is: a. less intrusive b. faster

Synced from GitHub

I can't reproduce in latest version 0.1.3-nightly.20261023.3566 (807319c276c6)