OSC 52 clipboard writes should include PRIMARY selection (`p`) on Linux

Status Closed — not planned
Maintainer reply None cached
Activity 9 comments · opened Apr 14, 2026 · closed Jun 26, 2026

Problem

When mouse capture is active (e.g., flicker mode), Claude Code handles text selection and sends the selected text to the system clipboard via OSC 52. However, it only writes to the standard clipboard (c target), not the PRIMARY selection (p target).

On Linux, users rely heavily on middle-click paste, which reads from the PRIMARY selection buffer — a separate buffer from the standard clipboard. Because Claude Code only writes to c, middle-click paste doesn't work with text selected inside Claude Code's terminal UI.

Current behavior

  1. User selects text in Claude Code (mouse capture active)
  2. Claude Code sends ESC ] 52 ; c ; <base64> ESC \
  3. Text is available via Ctrl+Shift+V (clipboard) but not via middle-click (PRIMARY)
  4. User sees: sent N chars via OSC 52 · check terminal clipboard settings if paste fails

Expected behavior

On Linux, Claude Code should also write to the PRIMARY selection so middle-click paste works:

ESC ] 52 ; p ; <base64> ESC \

Or ideally write to both c and p targets (two OSC 52 sequences), since users may paste with either method.

Environment

  • OS: Fedora Linux (Wayland/Xwayland)
  • Terminals tested: Tilix (VTE-based, no OSC 52 support), Ghostty (full OSC 52 support including p target)
  • Ghostty docs confirm p (primary) is a supported OSC 52 target: https://ghostty.org/docs/vt/osc/52

Workaround

Using Shift+click-drag to select and Shift+Middle-click to paste bypasses mouse capture and lets the terminal handle selection natively (writes to PRIMARY). This works but requires changing muscle memory.

Suggestion

  • Write to both c and p OSC 52 targets on Linux
  • Or make the OSC 52 target configurable (e.g., a setting for clipboard, primary, or both)

View original on GitHub ↗

9 Comments

rogpeppe · 4 months ago

I came here to raise this issue.

I'd also add that many UI apps (I tried Chrome, Discord, Telegram, Spotify) do write to both selections, so it seems like that would indeed be a good choice of behavior here.

Hydrocephalic · 3 months ago

I have the same issue:

Environment

  • OS: Ubuntu 24.04 LTS Linux (X11)
  • Terminals tested: Tilix (VTE-based, no OSC 52 support)
yorik · 3 months ago

It would be good to fix. Currently I use this workaround for X11:

#!/usr/bin/env bash
# Mirror X11 CLIPBOARD into PRIMARY so middle-click / Shift+Insert
# can paste content that OSC 52 emitters (e.g. Claude Code TUI) only
# write to CLIPBOARD.

exec 9>"${XDG_RUNTIME_DIR:-/tmp}/clipboard_to_primary.lock"
flock -n 9 || exit 0

prev=""
while sleep 0.3; do
  cur=$(xclip -selection clipboard -o 2>/dev/null 9>&-) || continue
  if [ -n "$cur" ] && [ "$cur" != "$prev" ]; then
    printf %s "$cur" | xclip -selection primary -i 9>&-
    prev=$cur
  fi
done
Ksld154 · 3 months ago

Same issue
In Agent view when i select text, it will show "send xxx chars via OSC 52", but nothing copied to my host clipboard.
Also /copy wont work either.

  • Host OS: MacOS 26.5
  • Terminal: Iterm2
  • Remote: Ubuntu 24.04 + tmux
  • Claude Code: 2.1.144
kthhrv · 3 months ago

Adding a more specific trigger on Linux: this manifests after pressing << to enter agent view (FleetView). At first start, terminal-native selection works and middle-click paste works. Once in agent view, selecting text (e.g. double-click) prints the same sent N chars via OSC 52 · check terminal clipboard settings if paste fails message quoted in the OP, and middle-click paste no longer reflects the latest selection.

Workaround from the OP (Shift+drag select, Shift+middle-click paste) confirmed still working.

justinclift-prvidr · 3 months ago

In Gnome Terminal (ie default for my distro), copying the text in Claude Code selected with the mouse seems impossible unless using the shift-select workaround approach mentioned by @lfarkas above.

That's pretty far from ideal. 😓

caina-barbosa · 3 months ago

This exact same issue broke my regular copy-pasting workflow. As a workaround, I've been using CopyQ clipboard manager with the "Clipboard Manipulation" options (2) and (3) (store text selected using mouse, paste clipboard with mouse) activated.

github-actions[bot] · 2 months ago

Closing for now — inactive for too long. Please open a new issue if this is still relevant.

rogpeppe · 1 month ago

This issue seems to be fixed anyway now as of v2.1.205