Skip to content

caticat/copy-code-line-for-ai

Repository files navigation

Copy Code Line For AI

Select code, press Ctrl+Shift+C, and the reference (e.g. @src/foo.ts:10-20) is instantly pasted into your AI chat input — no manual copy-paste needed.

Works with VS Code and Cursor.

中文文档

Features

  • Copy reference: Copies @relative/path:line or @relative/path:start-end to clipboard
  • Auto-focus & paste: After copy, automatically focuses and pastes into the target AI chat panel
  • Target options: Claude Code, VS Code built-in Chat, Codex chat, or clipboard-only (none)
  • No selection: When nothing is selected, copies the current line reference
  • Shortcut: Ctrl+Shift+C (Mac: Cmd+Shift+C)
  • Context menu: Right-click in editor → Copy/Paste section

Usage

  1. Select a code block, or place cursor on a line
  2. Press Ctrl+Shift+C
  3. The reference is copied and pasted into the configured AI chat input

Note: Claude Code may auto-convert @file:line to @file#line. Both formats point to the same lines. Note: Codex target defaults to paste mode. Set copyCodeLineForAI.codexUseAddToThread to true to use Codex's official Add to Codex Thread behavior.

Settings

Search copyCodeLineForAI in VS Code/Cursor settings:

Setting Type Default Description
copyCodeLineForAI.autoFocusTarget string "claudeCode" Target to auto-focus after copy: claudeCode (Claude Code), vscodeChat (VS Code built-in Chat), codex (Codex chat), none (clipboard only)
copyCodeLineForAI.codexUseAddToThread boolean false Use Codex's official Add to Thread command instead of the default paste behavior.
copyCodeLineForAI.prefix string "@" Prefix character, e.g. @ or #
copyCodeLineForAI.pathLineSeparator string ":" Separator between path and line number
copyCodeLineForAI.lineRangeSeparator string "-" Separator between start and end line
copyCodeLineForAI.focusDelayMs number 80 Delay in milliseconds before focusing or pasting into the target panel.

settings.json example

{
  "copyCodeLineForAI.autoFocusTarget": "claudeCode",
  "copyCodeLineForAI.codexUseAddToThread": false,
  "copyCodeLineForAI.prefix": "@",
  "copyCodeLineForAI.pathLineSeparator": ":",
  "copyCodeLineForAI.lineRangeSeparator": "-",
  "copyCodeLineForAI.focusDelayMs": 80
}

Output format examples

  • Default: @src/foo.ts:10-20
  • Codex paste mode on Windows: @src\foo.ts:10-20
  • Single line (no selection): @src/foo.ts:10
  • Use # as separator: @src/foo.ts#10-20

License

MIT License. See LICENSE for details.


中文文档

选中代码,按 Ctrl+Shift+C,引用(如 @src/foo.ts:10-20)立即粘贴到 AI 对话输入框,无需手动复制粘贴。

适用于 VS Code 与 Cursor。

功能

  • 复制引用:将 @相对路径:行号@相对路径:起始-结束 复制到剪贴板
  • 自动聚焦并粘贴:复制后自动聚焦并粘贴到目标 AI 对话面板
  • 目标可选:Claude Code、VS Code 内置 Chat、Codex Chat,或仅复制到剪贴板(none
  • 无选区:未选中时自动复制当前行引用
  • 快捷键Ctrl+Shift+C(Mac: Cmd+Shift+C
  • 右键菜单:编辑器右键 → 复制/粘贴区域

使用方法

  1. 选中代码块(或将光标停在某行)
  2. Ctrl+Shift+C
  3. 引用已复制并粘贴到已配置的 AI 对话输入框

提示: Claude Code 可能自动将 @文件:行号 转换为 @文件#行号,两种格式指向同一段代码。 提示: Codex 目标默认使用粘贴模式。可以将 copyCodeLineForAI.codexUseAddToThread 设为 true,使用 Codex 官方的 Add to Codex Thread 行为。

设置

在 VS Code/Cursor 设置中搜索 copyCodeLineForAI

设置项 类型 默认值 说明
copyCodeLineForAI.autoFocusTarget string "claudeCode" 复制后自动聚焦的目标:claudeCode(Claude Code)、vscodeChat(VS Code 内置 Chat)、codex(Codex Chat)、none(仅复制到剪贴板)
copyCodeLineForAI.codexUseAddToThread boolean false 使用 Codex 官方 Add to Thread 命令,而不是默认粘贴行为。
copyCodeLineForAI.prefix string "@" 路径前缀字符,如 @#
copyCodeLineForAI.pathLineSeparator string ":" 路径与行号之间的分隔符
copyCodeLineForAI.lineRangeSeparator string "-" 行号范围分隔符
copyCodeLineForAI.focusDelayMs number 80 聚焦或粘贴到目标面板前的延迟时间,单位毫秒。

许可证

MIT License. 详见 LICENSE

About

Copy Code Line Nums For AI to use.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors