claude-code - 💡(How to fix) Fix Paste drops newlines when running inside tmux (content joins in input box) [1 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#52126Fetched 2026-04-23 07:35:56
View on GitHub
Comments
0
Participants
1
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×4

When Claude Code runs inside a tmux session, pasting multi-line text via the terminal's normal paste gesture (e.g., Ctrl+Shift+V) produces single-line output in the input box — newlines between lines are silently stripped. The same paste works correctly when Claude Code is run directly in the terminal (no tmux).

Root Cause

When Claude Code runs inside a tmux session, pasting multi-line text via the terminal's normal paste gesture (e.g., Ctrl+Shift+V) produces single-line output in the input box — newlines between lines are silently stripped. The same paste works correctly when Claude Code is run directly in the terminal (no tmux).

Code Example

printf 'AAA\nBBB\nCCC' | wl-copy

---

printf '\e[?2004h' > /dev/tty
cat > /tmp/paste3.bin
# Ctrl+Shift+V paste of AAA\nBBB\nCCC, Ctrl+D
printf '\e[?2004l' > /dev/tty
od -c /tmp/paste3.bin

---

0000000 033   [   2   0   0   ~   A   A   A  \n   B   B   B  \n   C   C
0000020   C 033   [   2   0   1   ~  \n
RAW_BUFFERClick to expand / collapse

Summary

When Claude Code runs inside a tmux session, pasting multi-line text via the terminal's normal paste gesture (e.g., Ctrl+Shift+V) produces single-line output in the input box — newlines between lines are silently stripped. The same paste works correctly when Claude Code is run directly in the terminal (no tmux).

Environment

  • Claude Code: 2.1.117
  • tmux: 3.5a
  • Terminal: Ghostty (snap)
  • OS: Ubuntu 22.04 on Wayland

Reproduction

  1. Load a known multi-line clipboard:
    printf 'AAA\nBBB\nCCC' | wl-copy
  2. Start a fresh claude session inside tmux.
  3. Click into the input box, press Ctrl+Shift+V, do not press Enter.
  4. Observed: input box displays a single line AAABBBCCC.
  5. Expected: input box displays three lines AAA / BBB / CCC.

If submitted, the message arrives as \"AAABBBCCC\" in the session transcript (verified by inspecting ~/.claude/projects/<proj>/<session>.jsonl).

Isolation (the bug is in Claude Code's BP handler under tmux)

| Path | Result | |===|===| | Outside tmux: Ctrl+Shift+V paste into Claude Code | Newlines preserved | | Inside tmux: Ctrl+Shift+V paste into Claude Code | Newlines stripped, content joined | | Inside tmux: typed Shift+Enter into Claude Code | Newlines preserved | | Inside tmux: paste into cat with BP mode enabled | Bytes arrive as \e[200~AAA\nBBB\nCCC\e[201~ — correct | | Inside tmux: tmux paste-buffer -p of identical BP-wrapped bytes into Claude Code's pane | Newlines preserved |

So the terminal and tmux deliver a correct bracketed-paste sequence to Claude Code's pty — the BP start/end markers are intact and the \n bytes between them are intact — but Claude Code's BP handler collapses the content when this specific delivery path (user Ctrl+Shift+V → terminal → tmux → Claude Code) is used.

Byte-level capture

Captured inside tmux by enabling bracketed paste on a test tty and running cat:

printf '\e[?2004h' > /dev/tty
cat > /tmp/paste3.bin
# Ctrl+Shift+V paste of AAA\nBBB\nCCC, Ctrl+D
printf '\e[?2004l' > /dev/tty
od -c /tmp/paste3.bin

Output:

0000000 033   [   2   0   0   ~   A   A   A  \n   B   B   B  \n   C   C
0000020   C 033   [   2   0   1   ~  \n

i.e. \e[200~AAA\nBBB\nCCC\e[201~ — the exact standard BP-wrapped sequence.

Note on the apparent discrepancy with tmux paste-buffer

Feeding that same byte sequence to the pane via tmux send-keys -H (literal bytes) or tmux paste-buffer -p preserves newlines correctly in Claude Code. Only the user-initiated paste path produces the join. This suggests the handler may be sensitive to pty read chunking or timing characteristic of real paste delivery that tmux's synthetic paste does not reproduce.

extent analysis

TL;DR

The issue can be resolved by modifying Claude Code's bracketed paste (BP) handler to correctly handle newline characters when pasting multi-line text inside a tmux session.

Guidance

  • Investigate Claude Code's BP handler to identify why it collapses newline characters when receiving the paste sequence \e[200~AAA\nBBB\nCCC\e[201~ from tmux.
  • Verify that the issue is not with the terminal or tmux by checking the byte-level capture of the paste sequence, which shows that the correct sequence is being sent.
  • Consider the difference in behavior between user-initiated paste and tmux paste-buffer -p or tmux send-keys -H, which may indicate a timing or chunking issue in the BP handler.
  • Review the code that handles the BP sequence and newline characters to ensure it correctly preserves the original formatting.

Example

No code snippet is provided as the issue is specific to the internal implementation of Claude Code's BP handler.

Notes

The issue appears to be specific to the interaction between Claude Code and tmux, and may not be reproducible in other environments. The fact that tmux paste-buffer -p and tmux send-keys -H work correctly suggests that the issue is with the BP handler in Claude Code.

Recommendation

Apply a workaround or fix to Claude Code's BP handler to correctly handle newline characters when pasting multi-line text inside a tmux session, as the root cause of the issue appears to be within Claude Code's internal implementation.

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