Skip to content

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

Closed

Description

@bretthoerner

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

Activity

  1. github-actions commented on Jan 13, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Feel free to ignore if your specific case isn't addressed by these issues.

  2. bretthoerner commented on Jan 13, 2026

    @bretthoerner
    Author

    This issue might be a duplicate of existing issues. Please check:

    * [opencode mcp auth fails silently in remote/headless sessions (SSH, devcontainer) #7887](https://github.com/anomalyco/opencode/issues/7887): opencode mcp auth fails silently in remote/headless sessions (SSH, devcontainer) - Similar issue where clipboard/browser operations don't work in remote environments and the solution involves showing the URL instead of relying on browser opening
    

    Feel free to ignore if your specific case isn't addressed by these issues.

    It's similar, but this has to do with clipboard and not xdg-open. I've also replied there with my own attempts to fix that (unrelated, IMO) issue.

  3. leighmcculloch commented on Jan 19, 2026

    @leighmcculloch

    I run opencode in a Docker container and have the same issue - the share URL is only copied to clipboard and not displayed anywhere on screen. In a containerized environment, the clipboard operation doesn't work, so there's no way to retrieve the URL.

    Simply printing the URL to the screen (in addition to copying to clipboard) would solve this for Docker/container users too.

  4. kvokka commented on Jan 21, 2026

    @kvokka

    #4283 (comment)

    this helped

  5. github-actions commented on Mar 28, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

  6. l-astslice commented on Jun 1, 2026

    @l-astslice

    /tui default fixes this immediately in claude code!!

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions