claude-code - 💡(How to fix) Fix [BUG] Code block copy-paste injects formatting characters that break bash [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#45096Fetched 2026-04-09 08:13:22
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Error Message

-bash: syntax error near unexpected token `|' 4. Bash throws syntax error due to invisible formatting characters

Error Messages/Logs

-bash: syntax error near unexpected token `|' 4. Bash throws syntax error due to invisible formatting characters

Code Example

-bash: syntax error near unexpected token `|'
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

When copying code blocks from Claude Code output (web, desktop app, or mobile), invisible or visible formatting characters (angle brackets, special quotes, etc.) get included in the clipboard. Pasting into a terminal causes:

-bash: syntax error near unexpected token `|'

This happens consistently across:

  • Claude Code web (claude.ai/code)
  • Claude Code desktop app (Mac)
  • Mobile browser

Steps to reproduce:

  1. Claude outputs a bash command like: docker compose -f file.yml up -d
  2. Copy the command from the output (url gets characters < and > around it)
  3. Paste into terminal
  4. Bash throws syntax error due to invisible formatting characters

Expected: Clean plaintext copy with no formatting artifacts Actual: Formatting characters included in clipboard

This is particularly painful for users running commands on remote servers via SSH on mobile.

What Should Happen?

When copy pasting from the code section of Claude, characters breaking the commands, should not happen in the code block.

curl http://www.dsffedsrf.com/ Not curl http://www.dsffedsrf.com/

Expected: Clean plaintext copy with no formatting artifacts Actual: Formatting characters included in clipboard

Error Messages/Logs

-bash: syntax error near unexpected token `|'

Steps to Reproduce

Steps to reproduce:

  1. Claude outputs a bash command like: docker compose -f file.yml up -d
  2. Copy the command from the output (url gets characters < and > around it)
  3. Paste into terminal
  4. Bash throws syntax error due to invisible formatting characters

Claude Model

Opus

Is this a regression?

I don't know

Last Working Version

No response

Claude Code Version

Claude Code 2.1.96

Platform

Anthropic API

Operating System

Windows

Terminal/Shell

Other

Additional Information

No response

extent analysis

TL;DR

Remove invisible formatting characters from the copied code block before pasting into the terminal.

Guidance

  • Identify the source of the invisible formatting characters in the Claude Code output.
  • Use a text editor or a command-line tool to remove the formatting characters before pasting into the terminal.
  • Consider using a clipboard manager or a browser extension that can remove formatting characters from copied text.
  • If the issue persists, try copying the code block using a different method, such as selecting the text and then copying it using the context menu.

Example

# Remove angle brackets from the copied command
command="docker compose -f file.yml up -d"
command=${command//</}
command=${command//>/}
echo "$command" | pbcopy  # or use xclip on Linux

Notes

The root cause of the issue is likely due to the way Claude Code formats the output, which includes invisible characters that are not visible in the web or desktop app but are included in the clipboard. The provided example is a workaround and may not be a permanent solution.

Recommendation

Apply workaround: Remove invisible formatting characters from the copied code block before pasting into the terminal, as this is a more feasible solution given the current information.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING