Mention code snippets with file paths and line numbers — perfect for AI chats, documentation, and code reviews.
Why Code Mention?
When working with AI tools like ChatGPT, Claude, or GitHub Copilot Chat, you often need to reference specific code. Manually typing file paths, line numbers, and copying code blocks is tedious and error-prone.
Code Mention automates this workflow with one click or keyboard shortcut.
✨ Features
📋 Smart Copy with Context
- File path + line number — Always know where code comes from
- Selected code snippet — Include the actual code in your output
- Language detection — Automatically tags code blocks with the correct language
🤖 AI-Optimized Output
Formats output specifically for AI/LLM tools:
Here is the code from `src/extension.ts` (lines 10-25):
\`\`\`typescript
const x = 10;
const y = 20;
\`\`\`
Custom Output Formats
Define your own templates for different platforms:
- GitHub:
src/extension.ts#L10-25 - GitLab:
src/extension.ts#L10-25 - Markdown:
[src/extension.ts:10-25](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/src/extension.ts:10) - VS Code:
vscode://file/src/extension.ts:10
⌨️ Keyboard Shortcuts
Fast access without reaching for the mouse:
Ctrl+Shift+L— Copy relative pathCtrl+Shift+Alt+L— Copy absolute path
🎛️ Fully Configurable
Three settings to customize behavior:
- Include/exclude selected code
- Toggle AI formatting
- Custom format templates
🚀 Quick Start
Installation
From VS Code Marketplace:
- Open VS Code
- Press
Ctrl+Shift+X(Extensions) - Search for "Code Mention"
- Click Install
From VSIX:
- Download
code-mention-1.0.0.vsix - Open VS Code
- Press
Ctrl+Shift+X - Click
...→ "Install from VSIX..." - Select the downloaded file
📖 Usage Guide
Method 1: Context Menu
- Right-click anywhere in the editor
- Select one of:
- Copy Relative Path — Path relative to workspace root
- Copy Absolute Path — Full absolute path
Example:
Before: Select lines 10-25 in src/extension.ts
After: src/extension.ts:10-25 (with code snippet)
Method 2: Keyboard Shortcuts
- Select code in the editor (optional)
- Press the shortcut:
Ctrl+Shift+L→ Relative pathCtrl+Shift+Alt+L→ Absolute path
- Paste anywhere (AI chat, docs, Slack, etc.)
Pro Tip: You can customize shortcuts in VS Code:
- Open Command Palette (
Ctrl+Shift+P) - Type "Open Keyboard Shortcuts"
- Search for "Code Mention"
📊 Output Examples
Example 1: AI Chat (Default)
Input: Select lines 10-25 in src/extension.ts
Output:
Here is the code from `src/extension.ts` (lines 10-25):
\`\`\`typescript
function formatOutput(filePath: string, startLine: number) {
const lines = [filePath];
lines.push(`:${startLine}`);
return lines.join("");
}
\`\`\`
Use Case: Paste into ChatGPT, Claude, or Copilot Chat
Example 2: GitHub Issue
Setting: codeMention.customFormat = {path}#L{lineRange}
Input: Select line 42 in src/utils.ts
Output:
src/utils.ts#L42
Use Case: Reference code in GitHub issues or PR comments
Example 3: Documentation
Setting: codeMention.customFormat = [{path}:{lineRange}](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/{path}:{line})
Input: Select lines 15-30 in README.md
Output:
[README.md:15-30](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/README.md:15)
Use Case: Create clickable references in documentation
Example 4: VS Code Deep Link
Setting: codeMention.customFormat = vscode://file/{path}:{line}
Input: Cursor at line 100 in src/app.ts
Output:
vscode://file/src/app.ts:100
Use Case: Share clickable links that open directly in VS Code
Example 5: Path Only (No Code)
Setting: Disable codeMention.includeSelectedCode
Input: Cursor at line 50 in config.json
Output:
config.json:50
Use Case: Quick reference without code clutter
⚙️ Settings Reference
Open Settings (Ctrl+,) and search for "Code Mention"
codeMention.includeSelectedCode
- Type:
boolean - Default:
true - Description: Include the selected code snippet in the copied output
When enabled:
src/file.ts:10-20
\`\`\`typescript
// selected code here
\`\`\`
When disabled:
src/file.ts:10-20
codeMention.formatForAI
- Type:
boolean - Default:
true - Description: Format output for AI/LLM tools with language detection
Requires: includeSelectedCode to be enabled
When enabled:
Here is the code from `src/file.ts` (lines 10-20):
\`\`\`typescript
// selected code here
\`\`\`
When disabled:
src/file.ts:10-20
\`\`\`typescript
// selected code here
\`\`\`
codeMention.customFormat
- Type:
string - Default:
""(empty = use default format) - Description: Custom output format template
Available Variables
| Variable | Description | Example |
|---|---|---|
{path} |
File path | src/extension.ts |
{line} |
Start line number | 10 |
{endLine} |
End line number | 25 |
{lineRange} |
Formatted range | 10 or 10-25 |
{code} |
Selected text | const x = 10; |
{language} |
Language ID | typescript |
Template Examples
GitHub/GitLab Style:
{path}#L{lineRange}
Output: src/extension.ts#L10-25
Markdown Link:
[{path}:{lineRange}](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/{path}:{line})
Output: [src/extension.ts:10-25](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/src/extension.ts:10)
VS Code URL:
vscode://file/{path}:{line}
Output: vscode://file/src/extension.ts:10
Slack/Discord Code Block:
\`\`\`{language} {path}:{lineRange}
{code}
\`\`\`
Output:
```typescript src/extension.ts:10-25
function foo() { ... }
```
🎯 Use Cases
🤖 AI Chat Tools
Problem: You want to ask ChatGPT about a specific function, but need to provide context.
Solution:
- Select the function in VS Code
- Press
Ctrl+Shift+L - Paste into ChatGPT
- Ask your question
Result: AI has full context with file path, line numbers, and code.
📝 Code Reviews
Problem: You need to reference specific code in a PR review comment.
Solution:
- Set custom format to
{path}#L{lineRange} - Select the code in question
- Copy and paste into the review comment
Result: Clean, clickable reference to the exact code.
Bug Reports
Problem: You're filing a bug and need to point to the problematic code.
Solution:
- Select the buggy code
- Copy with Code Mention
- Paste into the issue description
Result: Maintainers can immediately locate the issue.
📚 Documentation
Problem: You're writing docs and need to reference implementation details.
Solution:
- Set custom format to markdown link style
- Select relevant code
- Copy and paste into docs
Result: Readers can click through to see the actual code.
💬 Team Communication
Problem: You're in Slack/Discord and need to share code with context.
Solution:
- Select the code snippet
- Copy with Code Mention
- Paste into the chat
Result: Team sees exactly what you're referring to.
🔧 Development
Build from Source
# Clone the repository
git clone https://github.com/AhmadEltobshy/code-mention.git
cd code-mention
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Package as VSIX
npm run package
Project Structure
code-mention/
├── src/
│ └── extension.ts # Main extension code
├── Resources/
│ └── icon.png # Extension icon
├── out/
│ └── extension.js # Compiled output
├── package.json # Extension manifest
├── tsconfig.json # TypeScript config
├── README.md # Documentation
── CHANGELOG.md # Version history
└── LICENSE # MIT License
Available Scripts
| Command | Description |
|---|---|
npm run compile |
Compile TypeScript |
npm run watch |
Watch for changes and recompile |
npm run lint |
Run ESLint |
npm run package |
Build VSIX package |
npm run vscode:prepublish |
Pre-publish hook (runs compile) |
📋 Changelog
See CHANGELOG.md for the full version history.
v1.0.0 (2026-07-05)
- Initial release
- Copy relative/absolute paths with line numbers
- AI-optimized formatting with language detection
- Custom output format templates
- Keyboard shortcuts
- Context menu integration
🤝 Contributing
This is an open source project. Feel free to:
- Fork the repository
- Submit issues for bugs or feature requests
- Create pull requests with improvements
Repository: https://github.com/AhmadEltobshy/code-mention
📄 License
MIT License — see LICENSE for details.
Tips & Tricks
Tip 1: Customize for Your Workflow
Set up different custom formats for different scenarios:
- GitHub issues:
{path}#L{lineRange} - Documentation:
[{path}:{lineRange}](https://github.com/AhmadEltobshy/code-mention/blob/HEAD/{path}:{line}) - Quick references:
{path}:{line}
Tip 2: Use with AI Effectively
When pasting into AI chats:
- Include the file path for context
- Include the code snippet (keep
includeSelectedCodeenabled) - Add your question after the pasted code
Example prompt:
Here is the code from `src/auth.ts` (lines 45-60):
\`\`\`typescript
function authenticate(user: User) { ... }
\`\`\`
Why does this function fail when the token expires?
Tip 3: Keyboard Shortcut Mastery
- Use
Ctrl+Shift+Lfor quick relative path copies - Use
Ctrl+Shift+Alt+Lwhen you need absolute paths - Customize shortcuts to avoid conflicts with other extensions
Tip 4: Combine with Other Tools
- GitLens: See git history, then use Code Mention to share the code
- GitHub Pull Requests: Reference code in PR comments
- Slack: Share code snippets with full context
🐛 Troubleshooting
Issue: "No file selected" warning
Cause: No active editor or no file open Solution: Open a file in the editor before using the extension
Issue: Wrong line numbers
Cause: VS Code uses 0-based lines internally Solution: Code Mention automatically converts to 1-based lines (human-readable)
Issue: Custom format not working
Cause: Invalid template syntax
Solution: Check variable names — must be {path}, {line}, etc. (case-sensitive)
Issue: AI formatting not applied
Cause: includeSelectedCode is disabled
Solution: Enable includeSelectedCode — AI formatting requires selected code
📞 Support
- Issues: https://github.com/AhmadEltobshy/code-mention/issues
- Repository: https://github.com/AhmadEltobshy/code-mention
- Email: [email protected]
Made with ❤️ for developers who work with AI