Copy for CLI Agent
A lightweight, zero-runtime-dependency VS Code extension that copies or sends standard file/line references (@/abs/path/file.ts#L10-L25) and optional Markdown code blocks to terminal coding agents such as Codex CLI, Claude Code, AGY, and OpenCode.
English | 中文说明
Features
- Standard Agent Reference Format: Outputs
@/abs/path/file.ts#L10-L25 (or #L10 for a single line), compatible with Codex CLI, Claude Code, AGY, and GitHub-style line anchors.
- Direct Send to Integrated Terminal: Injects references or code blocks into your active VS Code integrated terminal without pressing Enter, using Bracketed Paste Mode (
\x1b[200~...\x1b[201~) so multi-line snippets never trigger accidental submission in TUI agents.
- Reference-Only & Code-Block Modes:
- Use Reference Only for clean, token-efficient prompts when the agent can read local files directly.
- Use Selection with Code Block when sharing unsaved edits, small snippets, or pasting into external chat tools.
- Smart Selection Edge Cases:
- Trims trailing column-0 line endings from triple-click or
Shift+Down full-line selection.
- Falls back to the current line when nothing is selected.
- Sorts and merges overlapping multi-cursor selections.
- Quotes paths containing whitespace (
@"/path/with spaces/file.ts#L1-L5").
- Dynamically upgrades Markdown fence backticks when selected code contains
```.
Commands & Keybindings
Available in the Editor Context Menu (Copy for CLI Agent), Explorer Context Menu (Copy for CLI Agent), and Command Palette (Ctrl+Shift+P / Cmd+Shift+P):
| Command |
Output |
Default Shortcut (Win/Linux / macOS) |
Copy Reference (@path#L1-L2) |
@/abs/path/file.ts#L10-L25 |
Ctrl+Alt+C / Cmd+Alt+C |
| Send Reference to Terminal |
Sends reference to terminal (no Enter) |
Ctrl+Alt+S / Cmd+Alt+S |
| Copy Selection with Code Block |
@/abs/path/file.ts#L10-L25 + Markdown block |
Ctrl+Alt+Shift+C / Cmd+Alt+Shift+C |
| Send Selection with Code Block to Terminal |
Sends reference + code block to terminal |
Ctrl+Alt+Shift+S / Cmd+Alt+Shift+S |
Copy File Path (@path) |
@/abs/path/file.ts (supports multi-select) |
— |
| Send File Path to Terminal |
Sends @/abs/path/file.ts to terminal |
— |
Terminal Target Selection & Notes
This extension only targets VS Code integrated terminals, selected in the following order:
vscode.window.activeTerminal first: Sends to the currently active terminal tab or split pane (VS Code remembers it even after focus moves back to the editor).
- When
activeTerminal is unavailable:
- Exactly 1 open terminal → sends directly to that terminal.
- Multiple open terminals → opens a QuickPick list so you can choose.
- No open terminals → displays a warning instead of spawning an empty shell.
Notes:
- External terminals (Windows Terminal, iTerm2, tmux outside VS Code, etc.) cannot be controlled by VS Code extensions. Use
Ctrl+Alt+C (Cmd+Alt+C) and paste with Ctrl+V / Cmd+V.
- Multiple integrated terminals: When running several terminals side by side (e.g., an agent CLI and a dev server log), make sure the desired agent terminal tab is the active one before triggering Send to Terminal.
Configuration
| Setting |
Default |
Description |
copyForAgent.pathStyle |
"absolute" |
"absolute", "relative", or "workspaceFolderRelative" |
copyForAgent.lineRangeStyle |
"L1-L2" |
"L1-L2" (#L10-L25), "L1-2" (#L10-25), or ":1-2" (:10-25) |
copyForAgent.expandToFullLines |
true |
Expand partial-line selections to full lines so code matches line numbers |
copyForAgent.includeLineNumbers |
false |
Prefix each line in Markdown code blocks with its 1-based line number |
copyForAgent.terminalSendMode |
"bracketedPaste" |
"bracketedPaste", "paste" (workbench.action.terminal.paste), or "raw" (terminal.sendText) |
copyForAgent.alsoCopyOnSendToTerminal |
true |
Also copy the formatted text to the clipboard when sending to terminal |
copyForAgent.trailingSpaceOnSingleLineTerminalSend |
true |
Append a trailing space when sending a single-line reference to terminal |
中文说明
轻量级、零运行时依赖的 VS Code 插件:一键复制或发送标准文件/行号引用(@/绝对路径#L10-L25)及选中代码块,供 Codex CLI、Claude Code、AGY、OpenCode 等命令行 Agent 使用。
功能命令
在编辑器右键菜单 Copy for CLI Agent、资源管理器右键菜单 Copy for CLI Agent 或命令面板(Ctrl+Shift+P)中使用:
| 命令 |
输出内容 |
默认快捷键(Win/Linux / macOS) |
Copy Reference (@path#L1-L2) |
@/abs/path/file.ts#L10-L25(单行为 #L10) |
Ctrl+Alt+C / Cmd+Alt+C |
| Send Reference to Terminal |
发送同上引用至集成终端(不自动回车) |
Ctrl+Alt+S / Cmd+Alt+S |
| Copy Selection with Code Block |
@/abs/path/file.ts#L10-L25 + Markdown 代码块 |
Ctrl+Alt+Shift+C / Cmd+Alt+Shift+C |
| Send Selection with Code Block to Terminal |
发送同上完整内容至集成终端(不自动回车) |
Ctrl+Alt+Shift+S / Cmd+Alt+Shift+S |
Copy File Path (@path) |
@/abs/path/file.ts(资源管理器支持多选) |
— |
| Send File Path to Terminal |
发送同上路径至集成终端(不自动回车) |
— |
发送到终端:目标终端选择顺序与注意点
插件只会操作 VS Code 内置集成终端,按以下顺序选择发送目标:
- 优先使用
vscode.window.activeTerminal:即 VS Code 终端面板里当前高亮选中的终端标签页 / 分屏(即使当前焦点已切回代码编辑器,VS Code 仍会记住活跃终端)。
- 当
activeTerminal 为空时:
- 仅打开了 1 个集成终端 → 直接发送到该终端;
- 打开了多个集成终端 → 弹出下拉框(QuickPick)供手动选择;
- 未打开任何集成终端 → 弹窗提示先打开终端,不会自动新建空终端灌入代码。
使用注意点:
- 外部独立终端(Windows Terminal / iTerm2 / Xshell 等)不可直发:VS Code 插件无法操作外部终端进程,请使用
Ctrl+Alt+C(macOS Cmd+Alt+C)复制到剪贴板后手动 Ctrl+V。
- 同时打开多个集成终端时留意当前高亮 Tab:若你在多个终端之间切来切去(例如一个跑
codex / agy,另一个看服务日志),直接发送会发到当前高亮的终端 Tab;发送前确认高亮的是目标 Agent 终端。
常用配置(settings.json)
copyForAgent.pathStyle:"absolute"(默认) / "relative" / "workspaceFolderRelative"
copyForAgent.lineRangeStyle:"L1-L2"(默认,通用标准) / "L1-2" / ":1-2"
copyForAgent.expandToFullLines:true(默认补全选中首尾整行,使代码与行号严格一致)
copyForAgent.includeLineNumbers:false(是否在代码块内每行前加行号)
copyForAgent.terminalSendMode:"bracketedPaste"(默认,防止多行在 TUI 中误触发回车) / "paste" / "raw"
copyForAgent.alsoCopyOnSendToTerminal:true(发送到终端时同步写入剪贴板兜底)
copyForAgent.trailingSpaceOnSingleLineTerminalSend:true(单行引用发送到终端时末尾补空格,方便直接接着输入问题)
本地构建与安装
npm install
npm test
npm run package
生成的 .vsix 文件可在 VS Code 中通过命令面板执行 Extensions: Install from VSIX... 安装。