claude-code - 💡(How to fix) Fix OSC 52 clipboard writes should include PRIMARY selection (`p`) on Linux [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#48033Fetched 2026-04-15 06:35:14
View on GitHub
Comments
0
Participants
1
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
labeled ×3

Root Cause

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.

Fix Action

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.

Code Example

ESC ] 52 ; p ; <base64> ESC \
RAW_BUFFERClick to expand / collapse

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)

extent analysis

TL;DR

Modify Claude Code to send OSC 52 sequences to both the standard clipboard (c target) and the PRIMARY selection (p target) on Linux.

Guidance

  • Investigate the current implementation of OSC 52 in Claude Code to determine how to add support for the p target.
  • Update the code to send two separate OSC 52 sequences, one for the c target and one for the p target, when text is selected.
  • Consider adding a configuration option to allow users to choose which target(s) to write to, such as clipboard, primary, or both.
  • Test the updated implementation in different terminals, including those with and without OSC 52 support, to ensure compatibility.

Example

# Pseudocode example of sending OSC 52 sequences to both targets
def send_osc_52(text):
    # Send to standard clipboard (c target)
    print(f"ESC ] 52 ; c ; {base64_encode(text)} ESC \\")
    # Send to PRIMARY selection (p target)
    print(f"ESC ] 52 ; p ; {base64_encode(text)} ESC \\")

Notes

The exact implementation details may vary depending on the programming language and framework used by Claude Code. Additionally, it's essential to ensure that the updated implementation works correctly in different environments and terminals.

Recommendation

Apply a workaround by modifying Claude Code to write to both c and p OSC 52 targets on Linux, as this will provide the most seamless experience for users. This approach allows for middle-click paste to work as expected while also supporting Ctrl+Shift+V paste.

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…

FAQ

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.

Still need to ship something?

×6

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

Back to top recommendations

TRENDING