[BUG] Multi-root VS Code workspace: git branch/commit operations target the primary folder's repo instead of the edited file's repo

Open 💬 4 comments Opened Jun 20, 2026 by irsali

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Summary

In a VS Code multi-root workspace (.code-workspace) containing several independent git repositories as folders, git operations Claude Code performs (e.g. branching off main before committing, or pushing) target the primary (first) workspace folder's repository — not the repository that owns the file being edited. A change intended for a secondary folder results in a new branch/commit landing in the primary folder's repo, leaving the intended repo untouched.

Environment

  • Claude Code version: 2.1.148
  • IDE: VS Code (Claude Code VS Code extension)
  • VS Code version: 1.121.0-insider (but should be reproducible from regular vs code as well)
  • Extension version: 2.1.183
  • OS: Ubuntu 26.04 LTS (Linux 7.0.0-22-generic)
  • git: 2.53.0
  • Workspace type: Multi-root VS Code workspace with multiple distinct git repositories as folders (each folder is its own standalone repo, not nested)

Actual behavior

Regardless of which workspace folder the change is made in, the operation runs against the primary/first workspace folder's repository. Branches/commits intended for a secondary project land in the primary project's repo instead.

Result: the branch is created in ProjectA (the primary folder's repo); ProjectB does not get it.

Root cause (verified mechanism)

The integrated Bash/git tool resolves its working directory to the primary (first) workspace folder, and git invocations are not scoped to the edited file's repository. So a git checkout -b / git commit / git push issued without an explicit -C <repo-path> runs against the primary folder's repo by default.

The observable facts confirmed on the affected machine:

  • The shell working directory used for git commands is the primary workspace folder, even when the edited files live in a different folder.
  • Each workspace folder is an independent git repository (separate top-level .git), so cwd-based resolution silently picks the wrong one.
  • This is _not_ caused by a git hook or any auto-push/"remote" setting. The only git hooks installed were unrelated re-indexing hooks (post-commit/post-merge/post-rewrite) that neither branch nor push, and no Claude Code hook performs git push/branch. The branch was created by an ordinary git invocation resolving against the primary folder's cwd. (Noting this because the "wrong repo" symptom can be easy to misattribute to a hook.)

Impact

  • Branches and commits land in the wrong repository, polluting the primary project's branch list.
  • The change/commit workflow silently targets the wrong repo — easy to miss, and can lead to commits in the wrong project.
  • Provenance/audit risk: a change meant for repo B gets recorded against repo A, muddying each repo's history.
  • Affects anyone using Claude Code in multi-root / multi-repo VS Code workspaces (a common monorepo-adjacent setup).

Suggested fix

Scope every git operation to the repository that owns the file(s) being modified:

  • Resolve the target repo by walking up from the edited file's path to its nearest .git, rather than defaulting to the primary workspace folder's cwd.
  • Run git with that resolved path explicitly (e.g. git -C <resolved-repo-root> …) instead of relying on the inherited working directory.
  • When a turn touches files in more than one workspace folder, perform git operations per-repo, against each owning repository.

What Should Happen?

Expected behavior

When Claude Code makes a change in a given workspace folder, any git operation it performs (branch, commit, push) should target the git repository that owns the file being modified — resolved by walking up from the edited file to its nearest .git.

Error Messages/Logs

Steps to Reproduce

Steps to reproduce

  1. Create a VS Code multi-root workspace with at least two separate git repositories as folders:
  • ProjectA (listed first → primary) — its own git repo
  • ProjectB (listed second) — a separate git repo
  1. Open the workspace in VS Code with the Claude Code extension active.
  2. Ask Claude Code to make a code change in ProjectB (a non-primary folder) and prepare a commit (e.g. branch off main first).
  3. Observe which repo the branch/commit lands in.

Claude Model

Opus

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

2.1.148

Platform

Anthropic API

Operating System

Ubuntu/Debian Linux

Terminal/Shell

VS Code integrated terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗