Worktree Helper VS Code Extension
Create Git worktrees with environment configuration directly from the VS Code Command Palette.
Features
- Prompts for the folder name (inside
worktree/
).
- Prompts for the branch name to be created.
- Ensures
worktree/
is present in the project's .gitignore
.
- Executes
git worktree add
in the workspace root directory.
- Copies
.env
and .env.local
to the new worktree.
- Automatically executes the install command of the chosen package manager (or allows skipping).
- Supports presets with additional paths that also receive environment files and post-creation commands.
- Provides shortcuts to open the new worktree, reveal the directory in the system, or view execution logs.
Prerequisites
- Node.js 18+
- npm 9+
- VS Code 1.87.0 ou superior
- vsce installed globally to package the extension (
npm install -g @vscode/vsce
).
Development Installation
cd vscode-worktree-helper
npm install
npm run compile
Then, open the vscode-worktree-helper
folder in VS Code and press F5
to start a new development window with the extension loaded.
Package and Install Locally
npm run package
code --install-extension worktree-helper-0.0.1.vsix
Adjust the .vsix
file name according to the version generated by vsce
.
Usage
- Open the main project in VS Code (the root that contains the
worktree/
folder).
- Open the Command Palette (
Ctrl+Shift+P
or Cmd+Shift+P
).
- Search for "Worktree Helper: Create New Worktree".
- Provide the folder and branch names when prompted.
- Choose the package manager (or skip) when prompted.
- Choose the configuration preset.
- Wait for the success confirmation and choose whether to open the worktree, reveal the directory, or open the logs.
Execution logs are available in the VS Code OUTPUT panel, "Worktree Helper" channel.
Presets
The extension comes with two built-in presets:
- default – Copies
.env
/.env.local
to the worktree root and executes install
with the chosen package manager.
- remetricate – Same actions as the default preset + copies environment files to
packages/workflow-platform
.
You can create your own presets through VS Code settings (Settings > Extensions > Worktree Helper
or by editing settings.json
):
"worktree-helper.presets": [
{
"name": "monorepo",
"description": "Copy .env to apps/app-a and run npm install",
"usePackageManagerInstall": true,
"envTargets": ["apps/app-a"],
"postCommands": [
{
"command": "npm",
"args": ["install"],
"cwd": "apps/app-a"
}
]
}
]
envTargets
: relative paths to the worktree root that will also receive environment files.
postCommands
: commands executed in series. The cwd
field can be relative to the worktree or use the placeholders ${workspaceRoot}
and ${worktreePath}
.
usePackageManagerInstall
: when true, automatically adds the chosen package manager's install
command before custom postCommands
.
Quick Settings
worktree-helper.packageManager
: defines the default package manager (bun
, npm
, yarn
, pnpm
or skip
).
worktree-helper.promptPackageManager
: when active (default), asks which manager to use for each worktree creation.
worktree-helper.presets[].usePackageManagerInstall
: automatically enables the install
command for the preset.
Customization
- The
publisher
field in package.json
can be adjusted to the desired identifier before publishing.
- Use custom presets to extend the creation flow without needing to modify the code.
- If you want different behavior (e.g., copying additional files), adapt
src/extension.ts
as needed.
Structure
vscode-worktree-helper/
├─ dist/ # Compiled output (generated by npm run compile)
├─ node_modules/
├─ src/
│ └─ extension.ts # Extension entry point
├─ package.json
├─ tsconfig.json
└─ README.md