git worktrees in VS Code: windows, workspaces, and search

VS Code creates and opens worktrees natively now, so the interesting question has moved. It is no longer how to make one, it is how to stop three checkouts of the same code from poisoning search, go-to-definition, and the file watcher.

By the Continuum team. We build a workbench that runs Claude Code, Codex, and their peers, so the model rates quoted here are the ones our own cost analytics ship with.

The short version

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.

What you need to know
  • Create from Source Control Repositories, More Actions, Worktrees, Create Worktree.
  • Git: Open Worktree in New Window is the Command Palette route.
  • git.worktreeIncludeFiles copies gitignored files such as .env in.
  • git.detectWorktrees surfaces 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.watcherExclude or 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.

ThingWhereDoes
Worktrees, Create WorktreeSource Control Repositories, More ActionsCreate one, prompting for branch and path
Git: Open Worktree in New WindowCommand PaletteOpen a worktree in a second window
Git: Open Worktree in Current WindowCommand PaletteReplace the current window
Compare with WorkspaceRight-click a changed fileSide-by-side diff against your workspace
Migrate Worktree ChangesCommand PaletteMerge a worktree's changes into the current workspace
git.worktreeIncludeFilesSettingsGlobs to copy into new worktrees
git.detectWorktreesSettingsScan the repository for existing worktrees
git.detectWorktreesLimitSettingsHow 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.

.vscode/settings.json
{
  "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.

ConcernOne window eachOne multi-root workspace
Search scopeThis branch only. Correct.Spans every branch in the workspace
Go to definitionStays in this checkoutCan land in another branch's copy
Source controlOne repository, one branchOne repository per root; correct but crowded
Comparing two branchesTwo windows, side by sideGood. This is the case for it
ExtensionsEverything behaves normallySome assume a single root
TerminalAlready in the right directoryPrompts you for a root
CostSeveral windows to manageCognitive load in every search
app.code-workspace, when you do want them together.
{
  "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.

.vscode/settings.json
{
  "files.exclude":         { "**/.claude/worktrees": true },
  "search.exclude":        { "**/.claude/worktrees": true },
  "files.watcherExclude":  { "**/.claude/worktrees/**": true }
}

What each one buys you.

SettingStops
files.excludeThe directories appearing in the Explorer tree
search.excludeEvery search returning N copies of every hit
files.watcherExcludeThe 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.

The route that keeps the review.
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.

QuestionBest answered by
What does this function doThe editor
Which of my four agents is waiting on meA list with live status
What has each one changed so farA diff per session, side by side
Am I about to run out of quotaA usage gauge
Which one should I open and review nowThe 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.

  1. VS Code: branches and worktrees
  2. git-worktree manual
  3. Claude Code: run parallel sessions with worktrees
Try it

Monitor in one place.
Edit in another.

Continuum shows every session and diff in one sidebar, so you open an editor only on the one you are reviewing.

free app · your subscriptions · local-first