Skip to content
pewsheenPublic

About

A VSCode plugin to copy the select line's file path and line number(range) and selected text.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

Coco — Copy Reference for AI CLIs

Copy a code reference from the VS Code editor straight onto your clipboard, formatted to paste into Claude Code, Codex, and other AI coding CLIs.

Right-click in the editor:

  • No selection → Copy Reference (path:line) — copies the **absolute path

    • the cursor's line**:
    /root/os/synobuild/code.rs:213
    
  • With a selection → Copy Reference (path:range + code) — copies the absolute path + line range, then the selected snippet in a fenced block:

    /root/os/synobuild/code.rs:213-214:
    ```rust
      fn main() {
          println!("Hello World!");
    ```
    

Only one of the two commands appears in the right-click menu at a time (depending on whether you have text selected), so it behaves like a single context-aware action. Both are also on the Command Palette (Coco: …) and bound to Ctrl+Alt+C / Cmd+Alt+C.

Why this format

  • Absolute path — resolves no matter what working directory the CLI runs in, and under Remote-SSH / WSL / Dev Containers it is the correct remote path, which is exactly what an agent running there reads.
  • path:line / path:start-end — a plain, unambiguous hint both Claude Code and Codex understand; the agent reads the file itself to get current, surrounding context.
  • Fenced snippet — preserves indentation verbatim through a terminal paste (raw multi-line text can otherwise be mangled) and pins exactly which lines you mean, even if the file has changed since you copied. The fence grows past any backticks inside the snippet so it can't terminate early.
  • 1-indexed, inclusive line numbers, matching the editor gutter and both CLIs' conventions.

Behavior notes

  • Single-line selection emits path:213: (no -213).
  • Whole-line selection dragged onto the next line's gutter (column 0) ends the range on the visually-highlighted line, not the empty trailing one.
  • Multi-cursor uses the primary selection.
  • Unsaved / virtual documents (untitled buffers, vscode.dev, notebook cells) have no real absolute path; Coco copies a best-effort path and warns.

Install (sideload)

npm install
npm run package          # produces coco-0.0.1.vsix
code --install-extension coco-0.0.1.vsix

Or in VS Code: Extensions → ⋯ → Install from VSIX…

Develop

npm install
npm run compile          # tsc -> out/
npm test                 # runs the pure-formatter unit tests
npm run watch            # recompile on change

Press F5 in VS Code to launch an Extension Development Host with Coco loaded.

Layout

  • src/format.ts — pure, vscode-free formatting logic (the clipboard text).
  • src/extension.ts — wires the VS Code editor/clipboard API to format.ts.
  • src/format.test.ts — unit tests for the formatting logic.

License

MIT

About

A VSCode plugin to copy the select line's file path and line number(range) and selected text.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages