Skip to content

Conversation

@Son0fSun
Copy link

@Son0fSun Son0fSun commented Jan 17, 2026

Summary

  • Fix OSC 52 clipboard not working over SSH
  • Fix GNU Screen passthrough using wrong format
  • Add nested tmux session support
  • Use ST terminator instead of BEL for better compatibility

Problem

Clipboard copy operations fail when running OpenCode over SSH. The existing OSC 52 implementation had several issues:

  1. Used BEL (\x07) terminator which some terminals don't handle correctly inside DCS sequences
  2. Applied tmux-style passthrough (tmux; prefix) to GNU Screen, which uses a different format
  3. No support for nested tmux sessions

Fixes #6111
Fixes #2773

Solution

1. BEL → ST Terminator

- const osc52 = `\x1b]52;c;${base64}\x07`
+ const osc52 = `\x1b]52;c;${base64}\x1b\\`

ST (String Terminator) is more reliably handled inside DCS passthrough sequences.

2. Correct GNU Screen Format

// GNU Screen: DCS without tmux; prefix
const wrapped = osc52.replace(/\x1b/g, "\x1b\x1b")
sequence = `\x1bP${wrapped}\x1b\\`

3. Nested tmux Support

Detect nesting level from TMUX environment variable (comma-separated) and double escapes for each level:

const tmuxLevel = (process.env["TMUX"]?.match(/,/g) || []).length + 1
for (let i = 0; i < tmuxLevel; i++) {
  wrapped = wrapped.replace(/\x1b/g, "\x1b\x1b")
  wrapped = `\x1bPtmux;${wrapped}\x1b\\`
}

Supported Environments

Environment Status
iTerm2
Kitty
Alacritty
Windows Terminal
tmux
Nested tmux
GNU Screen

Test plan

  • Tested copy operation over SSH session
  • Verified paste works on local machine
  • Test inside tmux
  • Test inside GNU Screen
  • Test nested tmux (tmux inside tmux)

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Fix clipboard operations not working over SSH by improving the OSC 52
escape sequence implementation with proper terminal multiplexer support.

## Problems Fixed

1. **BEL vs ST terminator**: Changed from BEL (\x07) to ST (\x1b\\)
   for better compatibility. Some terminals don't handle BEL correctly
   inside DCS passthrough sequences.

2. **GNU Screen passthrough**: Fixed incorrect format - Screen uses
   DCS without the `tmux;` prefix that was being applied to both.
   - Before: `\x1bPtmux;\x1b<seq>\x1b\\` (wrong for Screen)
   - After: `\x1bP<seq>\x1b\\` (correct for Screen)

3. **Nested tmux sessions**: Added detection of tmux nesting level
   via comma count in TMUX env var, doubling escapes for each level.

## Technical Details

OSC 52 format: ESC ] 52 ; c ; <base64> ST

Passthrough wrapping:
- tmux: `ESC P tmux; ESC ESC <seq> ESC \`
- screen: `ESC P ESC ESC <seq> ESC \`

The escape characters must be doubled inside DCS sequences so they
pass through to the outer terminal emulator.

## Supported Terminals

- iTerm2, Kitty, Alacritty, Windows Terminal
- tmux (including nested sessions)
- GNU Screen
- Most modern terminal emulators

Fixes: anomalyco#6111
Fixes: anomalyco#2773

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found one potentially related PR:

PR #7028: fix(clipboard): add OSC 52 fallback for SSH/tmux environments
#7028

This PR appears to address similar issues with OSC 52 clipboard functionality in SSH and tmux environments. You should check if this PR was already merged or if it's still open, as it may cover some or all of the same fixes being proposed in PR #9008.

@b3nw
Copy link
Contributor

b3nw commented Jan 17, 2026

this should be resolved in by #8974

@fcimeson
Copy link

Can we just get an option to disable the clipboard outright so that we can use the normal right click copy and paste?

@b3nw
Copy link
Contributor

b3nw commented Jan 17, 2026

that was built -> OPENCODE_EXPERIMENTAL_DISABLE_COPY_ON_SELECT
#4751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

clipboard copy not works in remote SSH console. Copy to clipboard broken over SSH (MobaXterm & Windows Terminal)

3 participants