A VS Code extension that efficiently copies selected files as markdown with syntax highlighting and minimized content—perfect for sharing code context in chat applications.
- Select multiple files in the VS Code Explorer
- Right-click and choose "Copy for Context"
- Copies selected files as formatted markdown with syntax highlighting
- Includes relative file paths as headers
- Right-click any tab title or use Command Palette
- Copies the active file as markdown with proper syntax highlighting
- Perfect for sharing individual file contents
- Right-click any tab title or use Command Palette
- Copies all files in the current tab group as formatted markdown
- Great for sharing related files together
- Use Command Palette or right-click any tab title
- Copies contents of all open tabs as markdown
- Useful for sharing your entire working context
- Right-click any tab title or use Command Palette
- Opens a quick pick menu to select which open files to copy
- Allows selective copying from all open tabs
- Right-click on any folder in the Explorer
- Copies the directory tree structure without file contents
- Perfect for sharing project organization
- Shows folders (📁) and files (📄) with proper indentation
- Right-click on any folder in the Explorer
- Copies both the directory structure and all file contents
- Ideal for sharing complete project context
- Combines folder tree visualization with actual code
- Select text in an editor and use keyboard shortcut (
Ctrl+Shift+C/Cmd+Shift+C) - Copies the selected text as markdown with proper syntax highlighting
- Includes file path and line numbers in the header
- Perfect for sharing specific code snippets
- Select text in an editor and use keyboard shortcut (
Ctrl+Shift+Alt+C/Cmd+Shift+Alt+C) - Copies the selected text with line numbers prefixed to each line
- Ideal for referencing specific lines in discussions
- Automatically respects
.gitignorerules when copying folders - Excludes files and directories listed in
.gitignore - Can be toggled on/off in settings
- Works with all folder-related copy operations
- Select one or more files in the VS Code Explorer
- Right-click on the selection
- Choose "Copy for Context"
- The formatted markdown is now in your clipboard
- Right-click on any folder in the VS Code Explorer
- Choose one of the folder options:
- "Copy Folder Structure Only" - Gets directory tree without file contents
- "Copy Folder Structure with File Structure" - Gets directory tree plus all file contents
- The formatted markdown is now in your clipboard
- Right-click on any tab title
- Choose one of the copy options:
- Copy This File for Context
- Copy This Tab Group for Context
- Copy All Open Tabs for Context
- Copy Selected Files for Context
- Select text in an editor
- Right-click on the selection
- Choose one of the copy options:
- Copy Selection for Context
- Copy Selection with Line Numbers for Context
Ctrl+Shift+C/Cmd+Shift+C- Copy Selection for ContextCtrl+Shift+Alt+C/Cmd+Shift+Alt+C- Copy Selection with Line Numbers for Context
- Open Command Palette (
Ctrl+Shift+P/Cmd+Shift+P) - Type "Copy" to see all available copy commands
- Select the desired option
The extension generates clean markdown with:
- File paths as level 2 headers (
## path/to/file.js) - Code blocks with automatic language detection
- Proper syntax highlighting identifiers
Example output:
## src/components/Button.tsx
```tsx
import React from 'react';
interface ButtonProps {
onClick: () => void;
children: React.ReactNode;
}
export const Button: React.FC<ButtonProps> = ({ onClick, children }) => {
return (
<button onClick={onClick}>
{children}
</button>
);
};.button {
padding: 8px 16px;
border: none;
border-radius: 4px;
cursor: pointer;
}
### Minified Content with Line Numbers
When both `minifyContent` and `appendLineNumbers` are enabled:
```markdown
@src/components/Button.tsx
```tsx
1: import React from 'react'; 2: interface ButtonProps { 3: onClick: () => void; 4: children: React.ReactNode; 5: } 6: export const Button: React.FC<ButtonProps> = ({ onClick, children }) => { 7: return ( 8: <button onClick={onClick}> 9: {children} 10: </button> 11: ); 12: };
### Selection with Line Numbers
Example output:
```markdown
@src/components/Button.tsx:10-15
```tsx
10: export const Button: React.FC<ButtonProps> = ({ onClick, children }) => {
11: return (
12: <button onClick={onClick}>
13: {children}
14: </button>
15: );
### Folder Structure Only
Example output:
```markdown
# Folder Structure
## src
📁 src 📁 components 📁 styles
Example output:
## Folder Structure
# src
📁 src 📁 components 📄 Button.tsx 📄 Header.tsx 📁 styles 📄 button.css 📄 header.css 📄 index.ts
## Files
## src/components/Button.tsx
```tsx
import React from 'react';
// ... file content
import React from 'react';
// ... file content.button {
padding: 8px 16px;
// ... file content
}
## Supported Languages
The extension automatically detects and applies syntax highlighting for 40+ languages including:
- JavaScript/TypeScript (`.js`, `.jsx`, `.ts`, `.tsx`)
- Python (`.py`)
- Java (`.java`)
- C/C++ (`.c`, `.cpp`, `.h`, `.hpp`)
- C# (`.cs`)
- PHP (`.php`)
- Ruby (`.rb`)
- Go (`.go`)
- Rust (`.rs`)
- Swift (`.swift`)
- Kotlin (`.kt`)
- HTML/XML (`.html`, `.xml`)
- CSS/SCSS/SASS (`.css`, `.scss`, `.sass`)
- JSON/YAML (`.json`, `.yaml`, `.yml`)
- Shell scripts (`.sh`, `.bash`)
- PowerShell (`.ps1`)
- R (`.r`, `.R`)
- Matlab (`.m`)
- Perl (`.pl`)
- Lua (`.lua`)
- VimScript (`.vim`)
- Dockerfile
- And many more...
## Configuration
Add these settings to your `settings.json`:
```json
{
"copyForContext.minifyContent": false,
"copyForContext.removeComments": true,
"copyForContext.respectGitignore": true,
"copyForContext.folderStructureType": "tree",
"copyForContext.appendLineNumbers": true,
"copyForContext.selectionMinifyContent": false
}
-
copyForContext.minifyContent(boolean, default:false)- When enabled, fully minifies code by removing all comments, unnecessary whitespace, and newlines - similar to JavaScript minification
- When combined with
appendLineNumbers: true, each line gets a line number prefix in the minified output (e.g.,1: code... 2: code... 3: code...)
-
copyForContext.removeComments(boolean, default:true)- When minification is enabled, controls whether comments are removed from the code. Only applies when
minifyContentis true.
- When minification is enabled, controls whether comments are removed from the code. Only applies when
-
copyForContext.respectGitignore(boolean, default:true)- When enabled, files and folders listed in
.gitignorewill be excluded from the copy process. Applies to all folder-related operations.
- When enabled, files and folders listed in
-
copyForContext.folderStructureType(string, default:"tree")- Choose the output format for folder structure: 'tree' shows visual tree with emojis, 'json' shows structured JSON format
-
copyForContext.appendLineNumbers(boolean, default:true)- When enabled, appends line numbers to the file path header when copying selections with line ranges
- When combined with
minifyContent: true, adds line number prefixes to each line in the minified output (e.g.,1: code... 2: code...)
-
copyForContext.selectionMinifyContent(boolean, default:false)- When enabled, minifies code specifically for line range selections, independent of the global minifyContent setting
The extension includes intelligent .gitignore support:
- Automatic Detection: Looks for
.gitignorein your workspace root - Pattern Matching: Supports common gitignore patterns including:
- Exact file/folder names (
node_modules) - Wildcards (
*.log,temp*) - Directory patterns (
dist/,build/) - Path-based patterns (
src/temp/)
- Exact file/folder names (
- Configurable: Can be disabled via settings if needed
- Folder Operations: Only affects folder-related copy operations
If your .gitignore contains:
node_modules/
*.log
dist
.env
temp*
The extension will automatically exclude:
- The entire
node_modulesfolder - Any
.logfiles - The
distfolder .envfiles- Any files/folders starting with
temp
- Open VS Code
- Go to Extensions (
Ctrl+Shift+X) - Search for "Copy for Context"
- Click Install
- Clone this repository
- Run
npm installto install dependencies - Open in VS Code
- Press
F5to launch Extension Development Host - Test the extension in the new VS Code window
- Run
npm run compileto build the extension - Use
vsce packageto create a.vsixfile for installation
- VS Code version 1.74.0 or higher
Feel free to submit issues and enhancement requests!
MIT License - feel free to use this extension in your projects.