Code to Clipboard
Code to Clipboard is a Visual Studio Code extension designed to make it easy to share code with AI systems like ChatGPT and Claude3. It allows you to quickly copy code from your workspace to the clipboard in a format that provides context and clarity to the AI models.
Features
- Copy code from a single file to the clipboard
- Copy code from the current text file tab to the clipboard
- Copy code from all open text file tabs to the clipboard
- Copy code from a selected directory to the clipboard, including the directory structure
- Copy only the directory structure of a selected directory without file contents
- Respects
.gitignore
files and excludes ignored files from the copied code
- Outputs the copied code in a well-structured format with headers for easy readability
Usage
Copy Code from Current Tab
- Open a text file in the editor.
- Right-click on the editor or the tab title.
- Select "Copy Code from Current Tab to Clipboard" from the context menu.
- The code from the current text file tab will be copied to the clipboard.
Copy Code from All Open Tabs
- Right-click on any text file tab or in the editor.
- Select "Copy Code from All Open Tabs to Clipboard" from the context menu.
- The code from all open text file tabs will be copied to the clipboard.
Copy Code from a Directory
- Right-click on a directory in the explorer.
- Select "Copy Directory Code to Clipboard" from the context menu.
- The code from all text files in the selected directory and its subdirectories will be copied to the clipboard, along with the directory structure.
- Files specified in
.gitignore
files will be excluded from the copied code.
- Files matching the user-specified exclude patterns will be excluded from the copied code.
Copy Directory Tree
- Right-click on a directory in the explorer.
- Select "Copy Directory Tree to Clipboard" from the context menu.
- The directory structure of the selected directory will be copied to the clipboard without file contents.
For Code and Directory Structure:
The code is copied to the clipboard in the following format:
# Project Name
## Copied Files
- file1.js
- file2.ts
- dir1/file3.js
- dir1/file4.ts
## File Contents
### file1.js
```
// file1.js content
```
### file2.ts
```
// file2.ts content
```
### dir1/file3.js
```
// dir1/file3.js content
```
### dir1/file4.ts
```
// dir1/file4.ts content
```
For Directory Tree Only:
When copying a directory tree, the format is:
# Directory Name
## Directory Structure
- Directory Name/
- subdirectory1/
- file1.js
- subdirectory2/
- file2.ts
- file3.md
This format provides a clear and readable structure for the copied code, with the project or directory name at the top, followed by the list of copied files or directory structure, and then the contents of each file.
Extension Settings
This extension contributes the following settings:
codeToClipboard.excludePatterns
: Glob patterns for files to exclude when copying directory code. Default is ["*.lock", "yarn.lock", "package-lock.json", "pnpm-lock.yaml", "composer.lock"]
.
To specify exclude patterns, add them to your VS Code settings:
{
"codeToClipboard.excludePatterns": ["*.lock", "*.log", "node_modules/"]
}
Requirements
- Visual Studio Code 1.60.0 or higher
Extension Settings
This extension does not contribute any settings.
Known Issues
None
Contributing
Contributions are welcome! Please feel free to submit a pull request or open an issue on the GitHub repository.
License
This extension is licensed under the MIT License.