Copy Code Reference for AI
Copy code references — @src/foo.ts#10-20 (relative) or
@/Users/you/project/src/foo.ts#10-20 (absolute) — straight to the clipboard,
ready to paste into Claude Code, the built-in VS Code Chat, or any other AI
input.
Works with both VS Code and Cursor.
Commands
| Command |
Default shortcut |
Output |
| Copy Relative Code Reference for AI |
Ctrl+Shift+C / Cmd+Shift+C |
@src/foo.ts#10-20 |
| Copy Absolute Code Reference for AI |
Ctrl+Shift+Alt+C / Cmd+Shift+Alt+C |
@/Users/you/project/src/foo.ts#10-20 |
| Copy Code Reference as... |
Ctrl+Alt+C / Shift+Alt+C |
Quick-pick: code reference, file only, or permalink |
| Copy Remote Reference |
— |
https://github.com/owner/repo/blob/commit/path/file.ts#L10-L20 |
- With just a caret (no selection), each command copies a single-line reference
(e.g.
@src/foo.ts#10).
- Copy Code Reference as... appears in the editor's right-click menu under
the Copy/Paste section.
- Rebind either shortcut independently from VS Code's Keyboard Shortcuts UI.
Note that
Ctrl+Shift+C / Cmd+Shift+C overrides VS Code's built-in Open
New External Terminal; rebind there if you need it back. On macOS
Shift+Alt+C is otherwise free, but binding it means the editor no longer
types Ç.
- The relative command falls back to the absolute path when the file is outside
every workspace folder.
- In a multi-root workspace the relative path is prefixed with the workspace
folder name, so
src/app.ts in two roots stays unambiguous.
- The remote reference command copies a GitHub/GitLab/Bitbucket permalink. After
copying, a prompt offers to Open in Browser.
"Copy as..." quick-pick
The Copy Code Reference as... command opens a menu with a live preview of
each option for your current selection:
$(file-code) Code reference @src/reference.ts#13-19
format: claude-code
$(file) File only (no line numbers) @src/reference.ts
$(link) Remote Permalink https://github.com/owner/repo/blob/abc/src/reference.ts#L13-L19
Pick one and it copies immediately.
The menu does not list every format profile — it shows what your format
setting currently produces. Change the format in Settings, not here; modern AI
agents parse all of the variants anyway, so the pick that matters is reference
vs. whole file vs. permalink.
File only (no line numbers) copies @src/foo.ts — for pointing an AI agent
at a whole file rather than a range.
Settings
| Setting |
Type |
Default |
Description |
copyCodeRefForAi.format |
enum |
"claude-code" |
Reference format (see below) |
copyCodeRefForAi.prefix |
string |
"@" |
Prefix character — only used when format is "custom" |
copyCodeRefForAi.pathLineSeparator |
string |
":" |
Between path and line number — only used when format is "custom" |
copyCodeRefForAi.lineRangeSeparator |
string |
"-" |
Between start and end line — only used when format is "custom" |
copyCodeRefForAi.remoteRef |
enum |
"commit" |
Remote reference type: "commit" (stable permalink) or "branch" (mutable) |
Every setting is optional — the defaults above are used when a setting is
absent. The block below lists all settings at their default values:
{
"copyCodeRefForAi.format": "claude-code",
"copyCodeRefForAi.prefix": "@",
"copyCodeRefForAi.pathLineSeparator": ":",
"copyCodeRefForAi.lineRangeSeparator": "-",
"copyCodeRefForAi.remoteRef": "commit"
}
Set copyCodeRefForAi.format to one of the built-in profiles to switch formats
without touching the individual separator settings:
| Value |
Output example |
Notes |
"claude-code" |
@src/foo.ts#10-20 |
Default. Claude Code native format |
"opencode" |
@src/foo.ts:10-20 |
OpenCode format |
"plain" |
src/foo.ts:10-20 |
No prefix |
"custom" |
@src/foo.ts:10-20 |
Uses your prefix/pathLineSeparator/lineRangeSeparator settings |
The exact separator rarely matters — current AI agents recognise all of these.
Set "custom" only if you need a shape none of the profiles produce.
- Default (
claude-code): @src/foo.ts#10-20
- Single line (no selection):
@src/foo.ts#10
- Absolute:
@/Users/you/project/src/foo.ts#10-20
- File only, from the quick-pick:
@src/foo.ts
- Remote (GitHub):
https://github.com/owner/repo/blob/abc123/path/file.ts#L10-L20
Example settings.json
{
"copyCodeRefForAi.format": "opencode",
"copyCodeRefForAi.remoteRef": "branch"
}
Or with full custom separators:
{
"copyCodeRefForAi.format": "custom",
"copyCodeRefForAi.prefix": "@",
"copyCodeRefForAi.pathLineSeparator": ":",
"copyCodeRefForAi.lineRangeSeparator": "-",
"copyCodeRefForAi.remoteRef": "commit"
}
Notes
Claude Code may auto-convert @file:line to @file#line — both formats resolve
to the same lines.