Support writing to the local clipboard from Dev Containers and Remote SSH sessions
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Use Case / Problem Description
I have a Python script running inside a remote Linux Dev Container (connected via Remote - SSH / Dev Containers from a Windows host). The script is executed by a Git pre-commit hook and generates a short string.
I would like this string to be automatically copied to the local Windows clipboard so that the developer can immediately paste it (`Ctrl+V`) in the next step, without manually selecting and copying text from the terminal.
## What I Tried
### 1. OSC 52 Escape Sequences
I enabled:
```json
"terminal.integrated.enableOsc52": true
```
and emitted:
```text
\033]52;c;\a
```
from the Python script.
While this occasionally works in an interactive terminal session, it does not work reliably when executed from a Git pre-commit hook or another non-interactive process launched through VS Code's Source Control workflow. The OSC 52 sequence appears to be swallowed or never forwarded to the local Windows client.
### 2. `vscode.env.clipboard.writeText()`
This API is only available inside the VS Code extension runtime and therefore cannot be used by standalone CLI scripts or Git hooks running inside the container.
### 3. Standard Linux Utilities (`xclip`, `xsel`, `clip.exe`)
- `xclip` and `xsel` require an active X server, which is unavailable in a headless Dev Container.
- `clip.exe` is a Windows executable and is not accessible from within the remote Linux container.
## Proposed Solution
It would be helpful to support one of the following mechanisms:
### Option A: VS Code CLI Clipboard Command
Provide a command such as:
```bash
code --clipboard-write "text"
```
that securely bridges clipboard operations from the remote environment to the local host, similar to how `code .` can interact with the local VS Code instance.
### Option B: Reliable OSC 52 Forwarding
Ensure that OSC 52 sequences emitted by Git hooks, subprocesses, and other background processes running in the integrated terminal are consistently intercepted and forwarded to the host clipboard.
### Option C: IPC or Environment-Based Bridge
Provide a documented IPC mechanism (socket, command, or environment variable) that allows scripts running inside Dev Containers or Remote SSH sessions to send simple payloads, such as clipboard content, back to the local VS Code client.
## Environment
- **Host OS:** Windows 10/11
- **Remote Environment:** Linux (Ubuntu) in a Dev Container / Remote SSH session
- **VS Code Setting:**
```json
"terminal.integrated.enableOsc52": true
```
## Additional Context
Clipboard access from scripts and Git hooks is a common requirement for developer workflows that generate tokens, IDs, migration names, commit metadata, or other short values that need to be pasted immediately into another tool. Currently, there is no supported and reliable mechanism for transferring clipboard data from a remote container back to the local host.
Contributor guide
Assessment
This issue has not been assessed yet.