Send selected code or file references from VS Code to the OpenCode terminal with a single shortcut.
A lightweight VS Code extension that bridges your editor to the OpenCode terminal. Select code (or place your cursor on a line), press Cmd+L (Mac) or Ctrl+L (Windows/Linux), and the context is sent to the OpenCode prompt — no copy-paste needed.
Built by Sunstone Apps.
The extension inspects your current selection and decides what to send:
| Scenario | What gets sent |
|---|---|
| File in workspace + selection | @path#Lstart-end (compact reference) |
| File in workspace + no selection | @path (file reference) |
| Untitled or out-of-workspace file | Sanitized text (tabs and newlines collapsed, wrapped in backticks if multiline) |
Workspace files become references — the OpenCode agent reads the file directly, so your prompt stays clean. Unsaved or external files fall back to sanitized text since there's no path to reference.
The official OpenCode VS Code extension only sends file references for files inside the workspace folder. This extension adds the missing piece: send any selection to the OpenCode prompt, including unsaved files or files outside the project — and sends workspace selections as compact @path#L references instead of raw text.
- OpenCode installed and available in your PATH
- The official OpenCode VS Code extension (provides
Cmd+Escto open the OpenCode terminal)
Install directly from the Marketplace page or via the command line:
code --install-extension sunstoneapps.opencode-selectiongit clone https://github.com/JonathanReisCom/opencode-selection.git
cd opencode-selectionThen in VS Code:
- Open the
opencode-selectionfolder - Press
F5to launch an Extension Development Host - Open the OpenCode terminal with
Cmd+Esc(Mac) orCtrl+Esc(Windows/Linux) - Select code in any file and press
Cmd+L/Ctrl+L
Copy the extension folder into your VS Code extensions directory:
cp -r . ~/.vscode/extensions/sunstoneapps.opencode-selection-0.1.2Restart VS Code.
- Open the OpenCode terminal with
Cmd+Esc(this creates a terminal named "opencode") - Select code in any editor (or place your cursor on a line)
- Press
Cmd+L(Mac) orCtrl+L(Windows/Linux) - The reference or sanitized text appears in the OpenCode prompt, ready for you to type your question
When the OpenCode terminal is created via the official extension, it registers a local HTTP port in the terminal's environment variables. This extension reads that port and sends the payload via POST http://localhost:<port>/tui/append-prompt.
If the port is not available (e.g., the terminal was opened manually), it falls back to terminal.sendText() which types the text directly into the terminal.
- Depends on the OpenCode terminal being created via
Cmd+Esc(the official extension's command). A manually openedopencodeterminal won't have the HTTP port registered. - The
/tui/append-promptendpoint and_EXTENSION_OPENCODE_PORTenvironment variable are internal APIs of the OpenCode VS Code extension — they may change between releases.
MIT — © Sunstone Apps
