[BUG] Copied multi-line commands from Claude Code output contain formatting artifacts — still unfixed after 6+ months
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
When Claude Code outputs a multi-line command for the user to copy and run in their terminal, the copied text contains formatting artifacts — extra spaces, line breaks in wrong places, or line-number prefixes — that cause the command to fail when pasted.
Example: Claude outputs a command like:
python3 km.py add posthog-project-key --service posthog --tier 3 --owner david --secret "phc_abc123" --notes "PostHog project API key (public, client-side). Use as NEXT_PUBLIC_POSTHOG_KEY. Cloud US instance."
When the user copies this from the Claude Code terminal and pastes it into their shell, the text gets split across lines with formatting artifacts inserted, causing zsh: command not found errors on the fragments.
This is a real workflow problem. Claude Code frequently needs to give users commands to run (especially when the command requires interactive input like a password prompt that Claude can't handle itself). The user's only option is to copy from Claude's output, but the copy is corrupted.
What Should Happen?
Text copied from Claude Code's output should be identical to the source text — no added spaces, no line-number prefixes, no formatting artifacts. Multi-line code blocks and commands should be copy-safe.
Issue History — This Has Been Reported Repeatedly and Mishandled
This bug has been reported at least 6 times over the past 6+ months. Every report gets auto-closed by bots as a "duplicate" — but the duplicates point to each other in a circle, and none of them were ever actually fixed:
- #5097 — Original report (closed as duplicate)
- #4686 — Closed as duplicate
- #10969 — Reopened as v2 of the bug, tagged
has repro, had active discussion. Auto-closed by inactivity bot despite human comments asking for a dev response. Now locked. - #18798 — Closed as duplicate of #10969 (which was already closed)
- #23014 — Closed as duplicate
- #33223 — Closed as duplicate of #18798 (which was closed as duplicate of #10969)
The auto-close bot (#16497) and the circular-duplicate problem (#19267) have themselves been reported as issues.
The result: A bug that affects every user who copies multi-line output from Claude Code has been in the product for 6+ months with zero developer engagement, bounced between closed issues by automation, and is now locked so the original reporters can't even comment.
Steps to Reproduce
- Ask Claude Code to output a long single-line command (e.g., a
curlorpython3command with many flags) - The terminal wraps it visually across multiple lines
- Select and copy the command from the terminal output
- Paste into a separate terminal window
- Observe: the pasted text contains extra whitespace, line breaks, or other artifacts that were not in the original command
Claude Model
Opus (Claude Opus 4.6)
Is this a regression?
No, this never worked
Claude Code Version
v2.1.81
Platform
Anthropic API (Max subscription)
Operating System
macOS Darwin 25.4.0
Terminal/Shell
zsh (macOS Terminal)
Additional Information
Previous issue chain: #5097 → #4686 → #10969 → #18798 → #23014 → #33223. All closed, most locked. No fix delivered.
Related meta-issues about the auto-close/circular-duplicate problem: #16497, #19267.
8 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
This is not a duplicate — this is a report about an issue that has been bounced between 6+ closed/locked issues over 6 months with zero developer engagement. The duplicate chain is documented in the issue body.
Regarding the technical fix: a simple approach would be a raw output mode toggle in the terminal. When enabled, Claude Code output renders as plain text without any TUI formatting — no line-number prefixes, no rich wrapping, no invisible characters. Users could toggle it on when they need to copy a command, copy clean text, and toggle it back off.
This would be a minimal, non-breaking feature that solves the problem without requiring a rewrite of the TUI rendering layer. Even a per-block "Copy" button on code blocks (as suggested in the now-closed #35446) would address the most common use case.
Please do not auto-close this as a duplicate. Every prior report of this issue has been closed without resolution.
This is NOT a duplicate of #18798, #23014, or #15199. Those issues describe related but distinct problems:
This issue is specifically about multi-line command blocks that, when copied from Claude Code output, contain invisible formatting characters (zero-width spaces, non-breaking spaces, or similar) that cause the pasted command to fail silently in the terminal. The command looks correct but doesn't execute properly.
A straightforward fix would be a "raw mode" toggle or a copy-to-clipboard button on code blocks that strips all non-ASCII formatting before copying. This is a distinct UX problem from the rendering issues in the linked duplicates.
Please don't auto-close this — it's been reported repeatedly under different symptoms for 6+ months precisely because the root cause hasn't been addressed.
Workaround: Temp File + External Editor
Until this is fixed, here's the workaround we're using in our daily workflow:
/tmp/message.txt)open -a "Sublime Text" /tmp/message.txt)This bypasses the TUI rendering layer entirely. Works for any text you need to copy — commands, messages, code blocks, etc.
It's effective but highlights how broken the copy experience is — we shouldn't need to round-trip through the filesystem to get clean text out of a terminal tool.
Another concrete reproducer, different environment (Linux, bash on a TACC HPC login via SSH from Windows).
Claude Code renders fenced code blocks with two leading spaces injected in front of every line inside the
block. The spaces survive copy + paste into the terminal.
For python -c "..." snippets this is a hard failure — Python raises IndentationError on the first non-blank
line:
(env) $ python -c "
> import psycopg2
> conn = psycopg2.connect(...)
> ...
> "
File "<string>", line 2
import psycopg2
IndentationError: unexpected indent
Claude's source output has zero leading indent on those lines; the two spaces are injected at render time, so
the user has no way to work around it via prompting — asking Claude to "please don't indent" doesn't help,
because the model is already outputting flush-left.
Distinct from the earlier ANSI/wrap/markdown reports in this chain: the inserted character is a plain U+0020
space, there's no wrapping involved, and the failure happens even on short blocks that fit in one terminal
line. Any python -c, heredoc, or other indent-sensitive multi-line snippet becomes unrunnable.
Workarounds we've landed on:
A zero-indent-in → zero-indent-out rendering mode (or a per-block "copy raw" affordance) would fix this class
of failure for every indentation-sensitive language, not just the command-line-flag case originally
reported.
Closing for now — inactive for too long. Please open a new issue if this is still relevant.
Please fix this :)
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.