Code MentionMention 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
🤖 AI-Optimized OutputFormats output specifically for AI/LLM tools:
Custom Output FormatsDefine your own templates for different platforms:
⌨️ Keyboard ShortcutsFast access without reaching for the mouse:
🎛️ Fully ConfigurableThree settings to customize behavior:
🚀 Quick StartInstallationFrom VS Code Marketplace:
From VSIX:
📖 Usage GuideMethod 1: Context Menu
Example:
Method 2: Keyboard Shortcuts
Pro Tip: You can customize shortcuts in VS Code:
📊 Output ExamplesExample 1: AI Chat (Default)Input: Select lines 10-25 in Output:
Use Case: Paste into ChatGPT, Claude, or Copilot Chat Example 2: GitHub IssueSetting: Input: Select line 42 in Output:
Use Case: Reference code in GitHub issues or PR comments Example 3: DocumentationSetting: Input: Select lines 15-30 in Output:
Use Case: Create clickable references in documentation Example 4: VS Code Deep LinkSetting: Input: Cursor at line 100 in Output:
Use Case: Share clickable links that open directly in VS Code Example 5: Path Only (No Code)Setting: Disable Input: Cursor at line 50 in Output:
Use Case: Quick reference without code clutter ⚙️ Settings ReferenceOpen Settings (
|
| 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: ahmadeltobhsy@gmail.com
Made with ❤️ for developers who work with AI