files-to-context
files-to-context
is a Visual Studio Code extension that allows users to collect all currently open files (including hidden tabs) in the editor, extract their contents, and format them into a structured prompt. This formatted output can be copied to the clipboard for easy use in other tools or workflows, such as machine learning prompts or text analysis.
Features
🚀 Gather Open Files and Their Contents
- Automatically collects all currently open files in the VS Code editor, including:
- Files visible in the editor.
- Files loaded in hidden tabs.
🔍 Selection Mode
- New Feature: When text is selected in the active editor, that file is treated as the "Main File" with only the selected text included.
- Other open files are included as "Auxiliary Files" with their full content.
- Perfect for focusing on specific code sections while providing context from related files.
📝 Generates a Structured Prompt
📋 Copies to Clipboard
- Automatically copies the generated prompt to your system clipboard, ready for pasting.
⌨️ Shortcut for Efficiency
- Trigger the command with a customizable keyboard shortcut or through the Command Palette for seamless usage.
🔧 Simple and Lightweight
- The extension focuses on a single task, making it efficient and reliable for users who need a structured representation of open files.
Requirements
This extension does not have external dependencies, but it requires:
- Visual Studio Code 1.96.0 or later, as it utilizes modern APIs.
Usage
Basic Usage
- Install the extension in VS Code.
- Open multiple files in the editor (including files in hidden tabs).
- Trigger the command via:
- The Command Palette (
Ctrl+Shift+P
or Cmd+Shift+P
on macOS), then select "Generate Prompt from Open Files".
- A keyboard shortcut (default:
Ctrl+Shift+L
or customize it in your settings).
- The structured output is copied to your clipboard.
Using Selection Mode
- Open multiple files in the editor.
- Select specific text in one of the files that you want to focus on.
- Make sure the file with the selection is the active editor.
- Trigger the command as described above.
- The file with the selection will be marked as the "Main File" with only the selected text included, and other files will be included as "Auxiliary Files" with their full content.
Keyboard Shortcuts
By default, the extension provides a shortcut for easy access:
Ctrl+Shift+L
(or Cmd+Shift+L
on macOS): Generates the prompt and copies it to the clipboard.
You can customize this shortcut in your keybindings.json
:
{
"command": "filesToContext.listOpenFiles",
"key": "cmd+shift+l",
"when": "editorTextFocus"
}
Example Output
Standard Output (No Selection)
Here's an example of what the standard output might look like:
#/Absolute/path/project/src/file1.py
def hello_world():
print("Hello, world!")
#/Absolute/path/project/src/file2.js
console.log("Hello, JavaScript!");
Selection Mode Output
When text is selected in the active editor:
Main File
#/Absolute/path/project/src/file1.py
...
print("Hello, world!")
...
Auxiliary Files
#/Absolute/path/project/src/file2.js
console.log("Hello, JavaScript!"); # Full content of auxiliary file
Known Issues
- Unsaved Files: If a file has unsaved changes, the extracted content will reflect the unsaved version.
- Non-File URIs: Non-file tabs (e.g., untitled files or webviews) are excluded.
If you encounter other issues, feel free to report them on the project's GitHub repository.
Extension Settings
This extension contributes several configurable settings:
filesToContext.maxFileSizeMB
: Maximum file size in MB to include (default: 10, range: 1-100)
filesToContext.excludePatterns
: Glob patterns for files to exclude (e.g., ['/*.log', '/node_modules/**'])
filesToContext.additionalBinaryExtensions
: Additional file extensions to treat as binary files
filesToContext.includeFileSummary
: Include summary of skipped/truncated files (default: true)
filesToContext.showNotifications
: Show notification messages when copying to clipboard (default: true)
You can configure these settings in your VS Code settings (File > Preferences > Settings, then search for "Files to Context").
License
This extension is licensed under the MIT License. See the LICENSE file for details.
Enjoy using files-to-context
! Let us know if you have any feedback or feature requests.