VS Code has built-in git worktree support. Create one from the Source Control Repositories view: select the repository, open the More Actions menu, and choose Worktrees then Create Worktree. Open one with Git: Open Worktree in New Window or Git: Open Worktree in Current Window. Set git.worktreeIncludeFiles to copy gitignored files such as .env into new worktrees, and git.detectWorktrees to surface worktrees that already exist. One window per worktree is the right default; a multi-root workspace makes search and go-to-definition span every branch.
- Create from Source Control Repositories, More Actions, Worktrees, Create Worktree.
Git: Open Worktree in New Windowis the Command Palette route.git.worktreeIncludeFilescopies gitignored files such as.envin.git.detectWorktreessurfaces ones you or an agent created outside VS Code.- One window per worktree is still the right default. Multi-root spans branches.
- Exclude in-repo worktrees from
files.watcherExcludeor pay for it in CPU.
VS Code creates and opens worktrees natively
The Source Control Repositories view is the surface. Open it from the Source Control view, select your repository, open the More Actions menu, and choose Worktrees, then Create Worktree. VS Code prompts for a branch and a location, creates the folder, and checks the branch out into it. Each worktree then appears as a separate repository in that same view.
The commands and settings, all of them.
| Thing | Where | Does |
|---|---|---|
| Worktrees, Create Worktree | Source Control Repositories, More Actions | Create one, prompting for branch and path |
Git: Open Worktree in New Window | Command Palette | Open a worktree in a second window |
Git: Open Worktree in Current Window | Command Palette | Replace the current window |
Compare with Workspace | Right-click a changed file | Side-by-side diff against your workspace |
Migrate Worktree Changes | Command Palette | Merge a worktree's changes into the current workspace |
git.worktreeIncludeFiles | Settings | Globs to copy into new worktrees |
git.detectWorktrees | Settings | Scan the repository for existing worktrees |
git.detectWorktreesLimit | Settings | How many to scan. Default 50 |
Bring the gitignored files with it
A worktree is a fresh checkout, so as VS Code's own documentation puts it, "when you create a worktree, Git does not copy files that are excluded by .gitignore". That is why a new worktree starts and then immediately fails to reach a database: the .env is not there.
{
"git.worktreeIncludeFiles": [
".env",
".env.local",
"config/secrets.json"
]
}
Surfacing worktrees you did not create in the editor
This setting matters far more than it used to, because agents now create worktrees inside your repository. Claude Code puts them under .claude/worktrees/<name>/ by default, and a subagent can create one without you asking at all.
{
"git.detectWorktrees": true,
"git.detectWorktreesLimit": 50
}
With detection on, VS Code scans the repository for worktrees and lists them in the Source Control Repositories view, so an agent's branch shows up next to yours with its own diff. The limit caps how many it will scan; the default is 50, which is generous for a human and worth checking if you run a lot of subagents.
One window each, or a multi-root workspace
This is the decision that actually changes your day, and the native worktree commands do not make it for you. Both options exist; one is the default and one is a deliberate choice for a specific job.
The same three worktrees, two arrangements.
| Concern | One window each | One multi-root workspace |
|---|---|---|
| Search scope | This branch only. Correct. | Spans every branch in the workspace |
| Go to definition | Stays in this checkout | Can land in another branch's copy |
| Source control | One repository, one branch | One repository per root; correct but crowded |
| Comparing two branches | Two windows, side by side | Good. This is the case for it |
| Extensions | Everything behaves normally | Some assume a single root |
| Terminal | Already in the right directory | Prompts you for a root |
| Cost | Several windows to manage | Cognitive load in every search |
{
"folders": [
{ "path": "../app", "name": "main" },
{ "path": "../app-auth", "name": "auth" },
{ "path": "../app-search", "name": "search" }
],
"settings": {
"search.useIgnoreFiles": true
}
}
Keeping search and the file watcher sane
Worktrees living inside the repository used to be a mistake people made. It is now the default for Claude Code, which puts them under .claude/worktrees/. That means the exclusion settings below have gone from a nice-to-have to something you configure on day one.
{
"files.exclude": { "**/.claude/worktrees": true },
"search.exclude": { "**/.claude/worktrees": true },
"files.watcherExclude": { "**/.claude/worktrees/**": true }
}
What each one buys you.
| Setting | Stops |
|---|---|
files.exclude | The directories appearing in the Explorer tree |
search.exclude | Every search returning N copies of every hit |
files.watcherExclude | The watcher indexing N copies of your source |
Comparing and migrating changes back
Two commands close the loop without leaving the editor. Right-click a changed file in the worktree and choose Compare with Workspace to see the difference side by side. Then Migrate Worktree Changes from the Command Palette merges the worktree's changes into the current workspace.
cd .claude/worktrees/feature-auth
git diff main...HEAD
git push -u origin worktree-feature-auth
gh pr create --fill
When the editor is the wrong surface
There are two different jobs here and VS Code is excellent at one of them. Editing code in a worktree is editing code in a folder, and everything works. Keeping track of four agents working in four worktrees is a monitoring problem, and windows are a poor monitor: you cannot see them all, they do not tell you which agent is blocked, and they show you a diff only once you have already switched to it.
Two jobs, two surfaces.
| Question | Best answered by |
|---|---|
| What does this function do | The editor |
| Which of my four agents is waiting on me | A list with live status |
| What has each one changed so far | A diff per session, side by side |
| Am I about to run out of quota | A usage gauge |
| Which one should I open and review now | The list, then the editor |
Questions people ask
Open the Source Control Repositories view, select your repository, open the More Actions menu, and choose Worktrees then Create Worktree. VS Code prompts for a branch and a location, creates the folder, and checks the branch out into it.
Run Git: Open Worktree in New Window or Git: Open Worktree in Current Window from the Command Palette, right-click the worktree in the Source Control Repositories view, or just open the folder like any other.
Set git.worktreeIncludeFiles to a list of globs. Git does not copy gitignored files into a new worktree, so without this setting your environment files are missing. Note that it only covers worktrees VS Code itself creates.
Because more than one worktree is in the workspace, so the same file exists on several branches. Use one window per worktree, or add the worktree directory to search.exclude.
Only when you specifically want to compare branches side by side. It makes search span every branch and can send go-to-definition into the wrong copy, and some extensions assume a single root.
Only when they are inside the workspace and being watched, which is now common because Claude Code creates them under .claude/worktrees/. Add that path to files.watcherExclude and the cost goes away.
Enable git.detectWorktrees. VS Code scans the repository and lists each worktree as its own repository in the Source Control Repositories view. git.detectWorktreesLimit caps the scan and defaults to 50.
It merges all changes from a worktree into your current workspace. It suits a small experiment, but it is the wrong move for agent output, because it collapses the one-branch-one-diff property you created the worktree to get. Open a pull request instead.
Sources
Every figure above was read from these pages on August 2026. Vendors reprice without notice; if you find a stale number, tell us.