Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>OpenCode Context MenuNew to Visual Studio Code? Get it now.
OpenCode Context Menu

OpenCode Context Menu

ascendlin

|
133 installs
| (1) | Free
Add files, folders, and selected code to OpenCode from the VSCode context menu.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

OpenCode Context Menu

Add files, folders, and selected code to OpenCode directly from VSCode context menus.

English | 中文

English

Features

  • Add File to OpenCode: Send the current file as a /-separated relative path reference, or copy it to the clipboard.
  • Add Folder to OpenCode: Send an Explorer folder as a /-separated relative path reference, or copy it to the clipboard.
  • Add Selection to OpenCode: Send selected code to OpenCode, or copy it to the clipboard.
  • Add File to OpenCode is available from the editor body context menu, Explorer file context menu, and editor tab context menu.
  • The editor tab Add File to OpenCode action is placed in the VSCode Chat/Codex context menu group where available.
  • Editor body and Explorer actions use a dedicated OpenCode context menu group.
  • Add Selection to OpenCode stays visible and is disabled when no code is selected.
  • Supports VSCode integrated terminal, clipboard, OpenCode CLI, and automatic fallback modes.

Installation

Install from the VSCode Marketplace:

  1. Open VSCode Extensions with Ctrl+Shift+X or Cmd+Shift+X on macOS.
  2. Search for OpenCode Context Menu.
  3. Install the extension published by ascendlin.

Extension ID:

ascendlin.opencode-context-menu

Marketplace page:

https://marketplace.visualstudio.com/items?itemName=ascendlin.opencode-context-menu

Usage

  1. Right-click in the editor and choose Add File to OpenCode, or select code and choose Add Selection to OpenCode.
  2. Right-click a file in Explorer and choose Add File to OpenCode.
  3. Right-click a folder in Explorer and choose Add Folder to OpenCode.
  4. Right-click an open editor tab and choose Add File to OpenCode.

Keyboard Shortcuts

  • Windows/Linux: Ctrl+Alt+O F to add the current file.
  • Windows/Linux: Ctrl+Alt+O S to add selected code.
  • macOS: Cmd+Alt+O F to add the current file.
  • macOS: Cmd+Alt+O S to add selected code.

Configuration

Setting Default Description
opencodeContextMenu.integrationMethod auto auto, terminal, clipboard, or cli.
opencodeContextMenu.terminalNamePattern opencode Case-insensitive regular expression used to find the OpenCode integrated terminal.
opencodeContextMenu.terminalUseActiveWhenNoMatch false Send to the active integrated terminal when no OpenCode terminal matches. Keep disabled to avoid sending text to the wrong terminal.
opencodeContextMenu.terminalSubmitOnSend false Submit after sending text to the terminal. Disabled by default so you can review before submitting.
opencodeContextMenu.terminalPreserveFocus false Keep editor focus when revealing the target terminal.
opencodeContextMenu.cliPath opencode OpenCode CLI executable path.
opencodeContextMenu.cliTimeoutSeconds 300 Maximum CLI execution time before the operation is terminated.
opencodeContextMenu.continueLastSession true In CLI mode, pass --continue by default.
opencodeContextMenu.sessionId empty In CLI mode, use --session <id> when configured.
opencodeContextMenu.attachUrl empty In CLI mode, pass --attach <url> when configured.
opencodeContextMenu.selectionMode content content sends selected text; reference sends @path#Lx-y. Unsaved editors always send content.
opencodeContextMenu.maxSelectionCharacters 20000 Ask for confirmation before sending a larger selected-content prompt.
opencodeContextMenu.showNotifications true Show success and fallback notifications.

Settings are resource-scoped, so a multi-root workspace can use different integration and session settings for each folder.

Integration Modes

Auto

Default mode. The extension first tries to send content to a verified OpenCode terminal inside VSCode. If an official OpenCode terminal exposes its local control port, the extension uses the /tui/append-prompt protocol. If no suitable terminal is found, it falls back to the clipboard.

File and folder references use workspace-relative paths and always use / as the separator, including on Windows.

Examples:

@src/extension.ts
@src/commands
@.

Terminal

The extension prefers the active OpenCode terminal, then a terminal associated with the current workspace folder. If several terminals remain, it asks you to choose and remembers the choice for that workspace.

If your OpenCode terminal is not named opencode, rename the terminal tab or update terminalNamePattern.

With selectionMode: content, selected code is sent as @relative-path <selected-code>. Real newlines inside the selected code are represented as \n to prevent the terminal from submitting the OpenCode prompt immediately. With selectionMode: reference, the compact form @relative-path#L10-20 is used.

Example:

@src/extension.ts export function activate(context) {\n  // ...\n}

By default, content is inserted but not submitted. To submit immediately after sending, enable:

{
  "opencodeContextMenu.terminalSubmitOnSend": true
}

Clipboard

The extension copies content that can be pasted into an OpenCode session. Files and folders are copied as /-separated relative path references, such as @src/commands. Selected code is copied as @relative-path <selected-code> without extra explanatory text.

CLI

The extension calls:

opencode run --continue --file <file> <message>

If sessionId is configured, it uses --session <id> instead of --continue.

CLI operations show cancellable progress, capture bounded diagnostic output, and stop after cliTimeoutSeconds. Detailed integration logs are available in the OpenCode Context Menu output channel.

Development

npm install
npm run compile

Press F5 in VSCode to launch the Extension Development Host.

The default debug configuration is Run Extension (Clean), which uses --disable-extensions to avoid unrelated logs from other installed extensions.

Choose Run Extension (With Installed Extensions) when you need to debug in a real user-like environment.

If you see punycode deprecation warnings, Claude code extension..., or Python virtual environment activation logs, they usually come from other extensions or VSCode dependencies, not from this extension.

Package

npm run package

中文

功能

  • Add File to OpenCode: 将当前文件以 / 分隔的相对路径引用发送到 OpenCode,或复制到剪贴板。
  • Add Folder to OpenCode: 将资源管理器中的文件夹以 / 分隔的相对路径引用发送到 OpenCode,或复制到剪贴板。
  • Add Selection to OpenCode: 将选中代码发送到 OpenCode,或复制到剪贴板。
  • Add File to OpenCode 支持编辑器正文右键、资源管理器文件右键和已打开文件的标签页右键。
  • 标签页右键中的 Add File to OpenCode 会尽量放入 VSCode Chat/Codex 相关右键菜单分组中。
  • 编辑器正文右键和资源管理器右键仍使用独立 OpenCode 右键菜单分组。
  • 右键菜单始终显示;未选中代码时,Add Selection to OpenCode 会置灰。
  • 支持 VSCode 集成终端、剪贴板、CLI、自动降级四种集成方式。

安装

从 VSCode 插件市场安装:

  1. 在 VSCode 中打开扩展面板:Windows/Linux 使用 Ctrl+Shift+X,macOS 使用 Cmd+Shift+X。
  2. 搜索 OpenCode Context Menu。
  3. 安装发布者为 ascendlin 的扩展。

扩展 ID:

ascendlin.opencode-context-menu

插件市场地址:

https://marketplace.visualstudio.com/items?itemName=ascendlin.opencode-context-menu

使用方式

  1. 在编辑器中右键,选择 Add File to OpenCode 或选中代码后选择 Add Selection to OpenCode。
  2. 在资源管理器中文件右键,选择 Add File to OpenCode。
  3. 在资源管理器中文件夹右键,选择 Add Folder to OpenCode。
  4. 在已打开文件的标签页上右键,选择 Add File to OpenCode。

快捷键

  • Windows/Linux: Ctrl+Alt+O F 添加当前文件。
  • Windows/Linux: Ctrl+Alt+O S 添加选中代码。
  • macOS: Cmd+Alt+O F 添加当前文件。
  • macOS: Cmd+Alt+O S 添加选中代码。

配置

设置 默认值 说明
opencodeContextMenu.integrationMethod auto auto、terminal、clipboard 或 cli。
opencodeContextMenu.terminalNamePattern opencode 用于匹配 OpenCode 集成终端名称的正则表达式。
opencodeContextMenu.terminalUseActiveWhenNoMatch false 找不到 OpenCode 终端时发送到当前活动终端。建议保持关闭,避免误发到普通终端。
opencodeContextMenu.terminalSubmitOnSend false 发送到终端后是否自动回车提交。默认只插入到输入框,便于检查。
opencodeContextMenu.terminalPreserveFocus false 显示目标终端后仍保留编辑器焦点。
opencodeContextMenu.cliPath opencode OpenCode CLI 可执行文件路径。
opencodeContextMenu.cliTimeoutSeconds 300 CLI 操作超时并终止前等待的最长秒数。
opencodeContextMenu.continueLastSession true CLI 模式下默认传入 --continue。
opencodeContextMenu.sessionId 空 指定后 CLI 模式使用 --session <id>。
opencodeContextMenu.attachUrl 空 指定后 CLI 模式使用 --attach <url>。
opencodeContextMenu.selectionMode content content 发送选中文本;reference 发送 @path#Lx-y。未保存的编辑器始终发送内容。
opencodeContextMenu.maxSelectionCharacters 20000 选中内容超过此字符数时要求确认。
opencodeContextMenu.showNotifications true 是否显示成功和降级提示。

配置按资源作用域读取,因此多根工作区中的每个文件夹可以使用不同的集成方式和会话配置。

集成方式

Auto

默认模式。扩展会先尝试把内容发送到已确认的 OpenCode 终端。官方 OpenCode 终端提供本地控制端口时,扩展优先使用 /tui/append-prompt 协议;找不到合适终端时自动降级到剪贴板。

文件和文件夹引用使用工作区相对路径,并在所有平台统一使用 / 作为分隔符,包括 Windows。

示例:

@src/extension.ts
@src/commands
@.

Terminal

扩展优先使用当前活动的 OpenCode 终端,其次选择与当前工作区文件夹关联的终端。仍有多个候选时会要求选择,并按工作区记住结果。

如果你的 OpenCode 终端名称不是 opencode,可以右键终端标签重命名,或修改 terminalNamePattern。

使用 selectionMode: content 时,选中代码按 @相对路径 <选中代码片段> 发送,其中真实换行表示为 \n,避免终端把换行解释为 Enter。使用 selectionMode: reference 时发送紧凑的 @相对路径#L10-20。

示例:

@src/extension.ts export function activate(context) {\n  // ...\n}

默认不会自动回车提交。如需发送后立即提交,开启:

{
  "opencodeContextMenu.terminalSubmitOnSend": true
}

Clipboard

扩展会把可直接粘贴到 OpenCode 会话的内容写入剪贴板。当前文件和文件夹会复制为使用 / 分隔的相对路径,例如 @src/commands。选中代码会复制为 @相对路径 <选中代码片段>,不附加额外说明文字。

CLI

扩展会调用:

opencode run --continue --file <file> <message>

如果配置了 sessionId,则使用 --session <id> 替代 --continue。

CLI 操作会显示可取消的进度,只保留有限长度的诊断输出,并在超过 cliTimeoutSeconds 后终止。详细集成日志可在 OpenCode Context Menu 输出通道查看。

开发

npm install
npm run compile

在 VSCode 中按 F5 启动 Extension Development Host。

默认调试配置是 Run Extension (Clean),会使用 --disable-extensions 禁用其他已安装扩展,避免 Claude、Python 等扩展日志混入调试输出。

如果需要在已安装扩展都启用的环境中调试,请在调试面板选择 Run Extension (With Installed Extensions)。

如果看到 punycode deprecation warning、Claude code extension... 或 Python 虚拟环境激活日志,通常来自其他扩展或 VSCode 依赖,不是本插件直接输出。优先使用 Run Extension (Clean) 排查本插件问题。

打包

npm run package
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft