Copy to LLM


Streamline your workflow with LLMs using this powerful VS Code extension!
Overview
"Copy to LLM" is a Visual Studio Code extension designed to simplify the process of collecting and formatting code (or diffs or selections) for use with Large Language Models (LLMs) like ChatGPT. With just a few clicks, you can assemble exactly what you need—full files, directory trees, code snippets, or Git diffs—into a format optimized for prompt input.
Features
- Context Menu Integration: Easily access the extension's functionality by right-clicking on files or folders in the VS Code Explorer.
- Multi-Select Support: Copy contents from multiple files and folders simultaneously.
- Directory Traversal: Recursively collect files from selected directories.
- Customizable File Types: Configure which file extensions to include when processing directories.
- Formatted Output: Generate well-structured content with file paths and appropriate code blocks.
- Clipboard Support: Quickly copy single file contents to your clipboard.
- New Document Creation: Open compiled content in a new VS Code document for easy editing and review.
- Copy Selection: Copy one or more highlighted code blocks—each annotated with
path:line-start–line-end and fenced with the proper language ID.
- Copy Git Diff: Grab
git diff (or unstaged changes) for selected files even including submodules and format it as a single diff block.
Installation
- Open Visual Studio Code
- Press
Ctrl+P (or Cmd+P on macOS) to open the Quick Open dialog
- Type
ext install Compile-TomaszKasperczyk.copy-to-llm and press Enter
- Click the Install button
Alternatively, you can install the extension from the Visual Studio Code Marketplace.
Usage
Copy a Single File
- Right-click on a file in the Explorer
- Select "Copy to LLM"
- A new document will open containing the formatted content of the selected file
Process Multiple Files or Folders
- Select multiple files and/or folders in the Explorer (use Ctrl/Cmd+Click for multi-select)
- Right-click on one of the selected items
- Choose "Copy to LLM"
- A new document will open containing the formatted content of all selected items
Process an Entire Folder
- Right-click on a folder in the Explorer
- Select "Copy to LLM"
- A new document will open with the formatted content of all matching files in the folder and its subfolders
Copy Selected Text Blocks
- In any editor, highlight one or more ranges.
- Open the Command Palette "Copy Selection to LLM".
- Each block is annotated as
relative/path/file.ts:5–10, fenced with ts, etc.
- Preview opens (if enabled) and your clipboard contains the combined snippet.
Copy Git Diff
- In the Source Control view, select changed files (or leave none to diff the entire workspace).
- Right-click "Copy Diff to LLM" (or use the Command Palette).
- Diffs from submodules are automatically included and grouped.
- Preview opens (if enabled) and your clipboard holds a single
diff block.
Configuration
You can customize the extension behavior via Settings → Extensions → Copy to LLM.
⚠️ Important: When copying an entire folder, only files that match the configured extensions will be included.
Files with extensions not listed in your settings will be skipped and won't appear in the generated document.
Available Settings
| Name |
JSON Setting |
Type |
Default |
Description |
| Extensions |
copyToLLM.extensions |
string[] |
[".ts", ".tsx", ".mjs", ".ex", ".heex", ".svelte"] |
File extensions to include when copying directories. |
| Use Relative Paths |
copyToLLM.useRelativePaths |
boolean |
false |
Always accompany the file name with the directory in which it is located within the project. |
| Show Preview |
copyToLLM.showPreview |
boolean |
true |
If false, skip opening a Markdown preview editor after copying. |
JSON Configuration Example
{
"copyToLLM.extensions": [
".ts",
".tsx",
".mjs",
".ex",
".heex",
".svelte",
".cs"
],
"copyToLLM.useRelativePaths": true,
"copyToLLM.showPreview": false
}
Example Output
With default settings:
Button.tsx:
```
import React from 'react';
const Button = ({ label, onClick }) => (
<button onClick={onClick}>{label}</button>
);
export default Button;
```
helpers.ts:
```
export const capitalizeString = (str: string): string => {
return str.charAt(0).toUpperCase() + str.slice(1);
};
```
This format makes it easy to understand the structure of your code when sharing it with an LLM.
Copying selection:
src/extension.ts:531-534
```typescript
const document = await vscode.workspace.openTextDocument({
content: content,
language: "markdown",
});
```
Copying a Git diff:
```diff
diff --git a/src/index.ts b/src/index.ts
index abc123..def456 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -10,7 +10,9 @@ import { foo } from './foo';
function main() {
- console.log('Hello');
+ console.log('Hello, world!');
+ // Added greeting
}
```
Contributing
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository
- Create a new branch for your feature or bug fix
- Make your changes and commit them with a clear commit message
- Push your changes to your fork
- Create a pull request to the main repository
Please ensure your code adheres to the existing style and includes appropriate tests.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
If you encounter any issues or have suggestions for improvements, please open an issue on our GitHub repository.
Acknowledgements
Special thanks to all the contributors and users who have helped improve this extension. Your feedback and support are greatly appreciated!
Made with ❤️ by developers, for developers