copying to clipboard doesn't work in a remote session (like a devcontainer) #5360

Open
opened 2026-02-16 17:51:46 -05:00 by yindo · 0 comments
Owner

Originally created by @bretthoerner on GitHub (Jan 13, 2026).

Originally assigned to: @rekram1-node on GitHub.

Description

For example: /share is great but it appears to only support copying directly to the clipboard. It'd be nice to print the actual URL so people can copy it from a terminal themselves, or even better it'd be nice to support copying out to the host automatically.

The wrapper helped me in a vscode devcontainer:

diff --git a/.devcontainer/osc52-clipboard b/.devcontainer/osc52-clipboard
new file mode 100644
index 00000000..0f350c2b
--- /dev/null
+++ b/.devcontainer/osc52-clipboard
@@ -0,0 +1,17 @@
+#!/bin/bash
+# OSC 52 clipboard wrapper for devcontainers
+# Sends clipboard data to the host terminal via OSC 52 escape sequences
+# This works in VS Code terminal and most modern terminal emulators
+
+# Read from stdin and base64 encode
+data=$(cat | base64 | tr -d '\n')
+
+# Write directly to the controlling terminal, bypassing any TUI that might
+# be capturing stdout. This ensures the escape sequence reaches VS Code.
+if [ -n "$TTY" ]; then
+    printf "\e]52;c;%s\a" "$data" > "$TTY"
+elif [ -e /dev/tty ]; then
+    printf "\e]52;c;%s\a" "$data" > /dev/tty
+else
+    printf "\e]52;c;%s\a" "$data"
+fi
diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh
index 8118ff3e..0a708fbe 100644
--- a/.devcontainer/setup.sh
+++ b/.devcontainer/setup.sh
@@ -1,5 +1,12 @@
 #!/bin/bash -ex

+# Install OSC 52 clipboard wrapper (enables clipboard in devcontainer -> host)
+cp .devcontainer/osc52-clipboard /usr/local/bin/
+chmod +x /usr/local/bin/osc52-clipboard
+# Create symlinks so tools that call xclip/xsel use our OSC 52 wrapper
+ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xclip
+ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xsel

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Originally created by @bretthoerner on GitHub (Jan 13, 2026). Originally assigned to: @rekram1-node on GitHub. ### Description For example: `/share` is great but it appears to only support copying directly to the clipboard. It'd be nice to print the actual URL so people can copy it from a terminal themselves, or even better it'd be nice to support copying out to the host automatically. The wrapper helped me in a vscode devcontainer: ```diff diff --git a/.devcontainer/osc52-clipboard b/.devcontainer/osc52-clipboard new file mode 100644 index 00000000..0f350c2b --- /dev/null +++ b/.devcontainer/osc52-clipboard @@ -0,0 +1,17 @@ +#!/bin/bash +# OSC 52 clipboard wrapper for devcontainers +# Sends clipboard data to the host terminal via OSC 52 escape sequences +# This works in VS Code terminal and most modern terminal emulators + +# Read from stdin and base64 encode +data=$(cat | base64 | tr -d '\n') + +# Write directly to the controlling terminal, bypassing any TUI that might +# be capturing stdout. This ensures the escape sequence reaches VS Code. +if [ -n "$TTY" ]; then + printf "\e]52;c;%s\a" "$data" > "$TTY" +elif [ -e /dev/tty ]; then + printf "\e]52;c;%s\a" "$data" > /dev/tty +else + printf "\e]52;c;%s\a" "$data" +fi diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 8118ff3e..0a708fbe 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -1,5 +1,12 @@ #!/bin/bash -ex +# Install OSC 52 clipboard wrapper (enables clipboard in devcontainer -> host) +cp .devcontainer/osc52-clipboard /usr/local/bin/ +chmod +x /usr/local/bin/osc52-clipboard +# Create symlinks so tools that call xclip/xsel use our OSC 52 wrapper +ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xclip +ln -sf /usr/local/bin/osc52-clipboard /usr/local/bin/xsel ``` ### Plugins _No response_ ### OpenCode version _No response_ ### Steps to reproduce _No response_ ### Screenshot and/or share link _No response_ ### Operating System _No response_ ### Terminal _No response_
yindo added the bug label 2026-02-16 17:51:46 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#5360