Flatten Workspace (Flatspace) is a Visual Studio Code extension that lets you easily copy the entire structure and contents of your open workspace as a single flattened string. This is especially useful when working with AI tools that need your entire project context as inline text, or when sharing code snippets quickly without manually concatenating multiple files.
-
Copy Flattened Workspace Content: Copies all non-ignored files from the current workspace into your clipboard as a single comprehensive text output. Each file is separated and includes line numbers for easy reference.
-
Copy Directory Structure: Generates a textual representation of your workspace's directory structure, ignoring specified patterns, and copies it to your clipboard.
-
Ignore Patterns: Configure which files or directories to exclude. By default, common directories like
node_modulesand.gitare ignored, as well as certain file types. The extension also respects.gitignoresettings if enabled.
- Open VS Code.
- Go to the Extensions view (
View>Extensionsor pressCtrl+Shift+X). - Search for "Flatten Workspace".
- Click Install.
- Once installed, reload or restart VS Code if prompted.
If you've built or obtained the flatten-workspace-0.0.1.vsix file locally:
- Open a terminal.
- Run:
code --install-extension flatten-workspace-0.0.1.vsix
- Restart VS Code if needed.
-
Clone the repository:
git clone https://github.com/jameswlepage/flatten-workspace.git
-
Navigate into the project directory:
cd flatten-workspace -
Install dependencies:
npm install
-
Build the extension:
npm run compile
-
Package the extension:
npx vsce package
This will create a
.vsixfile (e.g.flatten-workspace-0.0.1.vsix). -
Install the
.vsix:code --install-extension flatten-workspace-0.0.1.vsix
-
Copying the entire workspace:
- Open the command palette (
Ctrl+Shift+Pon Windows/Linux,Cmd+Shift+Pon macOS). - Type "Flatten Workspace: Copy Workspace Content" and press enter.
- The entire filtered workspace content (based on your ignore patterns) will be copied to your clipboard.
- Paste it wherever you need (such as into an AI tool's prompt or a code snippet platform).
- Open the command palette (
-
Copying the directory structure:
- Open the command palette.
- Run "Flatten Workspace: Copy Directory Structure".
- A textual directory tree representation of your workspace is copied to your clipboard.
- Ctrl+Shift+C (Windows/Linux) or Cmd+Shift+C (macOS): By default, triggers the Flatten Workspace: Copy Workspace Content command when the editor is in focus.
flatten-workspace.copyWorkspace: Copies the flattened workspace content into the clipboard.flatten-workspace.copyDirectory: Copies just the directory structure of the workspace into the clipboard.
You can also access "Flatten Workspace: Copy Workspace Content" via the editor title bar menu (the icon will appear when the editor is in focus).
You can customize ignore patterns and other settings in your VS Code settings.json or through the Settings UI:
-
flatten-workspace.ignorePatterns(array, default as shown below)
Patterns to exclude from the flattened output:[ "node_modules/**", ".git/**", "out/**", "dist/**", "build/**", "*.vsix", "**/*.map", "**/*.log", ".vscode/**", ".vscode-test/**", "coverage/**", "tmp/**", ".DS_Store" ]
-
flatten-workspace.useGitignore(boolean, default:true)
Whether to also use.gitignorepatterns when ignoring files. -
flatten-workspace.maxFileSizeKB(number, default:1024)
Maximum file size (in KB) to include in the flattened output. Larger files will be skipped.
After running "Flatten Workspace: Copy Workspace Content", you might get a single text output that includes a directory listing followed by each file and its contents with line numbers, like:
my-project/
├── src/
│ ├── index.js
│ └── utils.js
└── package.json
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | console.log('Hello, World!');
2 |
3 | // Some code here
...
This entire output is now in your clipboard, ready to be pasted elsewhere.
Flatten Workspace is licensed under the GPL-3.0-only.
Contributions and bug reports are welcome! Please visit the GitHub repository to open issues, submit feature requests, or contribute changes.