VS Code extension: session listing across git worktrees pulls unrelated repos into Source Control ("Close Repository" undone within ~1s)
Environment: Claude Code VS Code extension 2.1.170 · VS Code 1.124.0 · WSL2 remote (Ubuntu) · CLI used in terminal, attached to the window
Setup: Multiple git worktrees per repo, used as isolated "lanes": ~/repo (main checkout) plus ~/repo-1, ~/repo-2, ~/repo-3 (branches ws1–ws3). Each VS Code window opens a multi-root workspace containing only one lane's worktrees, e.g. lane 1 = repo-A-1, repo-B-1, …
Behavior: The extension appears to map each workspace folder to its git common dir (git rev-parse --git-common-dir) and surfaces session history from ~/.claude/projects/ for every checkout of that repo — not just the workspace folder's own cwd. VS Code's agent-sessions machinery then resolves each listed session and opens its working directory as a repository via the git extension API. Result: the lane-1 window's Source Control fills with repos that aren't in the workspace — other lanes' worktrees and the main checkouts. "Close Repository" is reverted in under a second (git extension log: [Model][close] Repository: /home/olet/mhax-biz-3 at 15:41:57.143, reopened at 15:41:57.587).
Evidence: The set of stray repos exactly equals the set of ~/.claude/projects/<flattened-cwd>/ dirs containing transcripts. Sessions actually run in ~/mhax-biz-3 are listed in the lane-1 window badged as mhax-biz-1, with changes URIs pointing into /home/olet/mhax-biz-3/.... Deleting the transcripts makes the repos disappear; new sessions in another lane bring them back.
Not gated by: git.autoRepositoryDetection: "subFolders", git.openRepositoryInParentFolders: "never", the git extension's closed-repositories memory, or chat.viewSessions.enabled: false — the opens happen via the extension API at startup, before any sessions UI is used.
Expected: List sessions only for the workspace folders' exact paths (or make cross-checkout listing opt-in), and/or don't open repositories in SCM for sessions that are merely listed. Worktree-based multi-window workflows currently get every sibling checkout dragged into every window.
Workaround: Periodically delete ~/.claude/projects/<dir>/*.jsonl for the non-workspace checkouts (carefully preserving memory/).