[Copilot][Claude Code] Closing a linked Git worktree immediately reopens it when Claude session history exists for that worktree
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
- Copilot Chat Extension Version: `0.58.2026071704` (pre-release)
- VS Code Version: `1.130.0-insider` (`5e212606d57c0a17f73bc8b7ae0cc9e14bcfd345`)
- OS Version: macOS `26.5.1` (`25F80`), arm64
- Feature (e.g. agent/edit/ask mode): Claude Code session provider / Agent Sessions; Source Control repository list
- Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): N/A — no chat request was running. The affected session provider was Claude Code.
- Logs:
Abridged timeline from the VS Code Git extension log:
```text
23:06:16.754 Close repository:
23:06:16.831 git rev-parse --show-toplevel
23:06:16.849 git rev-parse --git-dir / --git-common-dir
23:06:16.870 Open repository:
```
The repository was reopened approximately 116 ms after being manually closed. The same close/reopen sequence was reproduced multiple times, generally within 100–200 ms.
After deleting only the Claude Code project/session directory corresponding to ``:
```text
00:06:07.863 Close repository:
[no subsequent Open repository event]
```
The full Git extension logs are attached.
Steps to Reproduce:
1. Create two linked Git worktrees, `` and ``, belonging to the same Git repository.
2. Confirm that both worktrees resolve to the same `git-common-dir`.
3. Create or retain a Claude Code session whose working directory is ``. This produces session data under:
```text
~/.claude/projects//*.jsonl
```
4. Open `` in VS Code with the Copilot Chat extension and Claude Code integration enabled.
5. Open the Source Control view. `` appears in the repository list.
6. Manually select **Close Repository** for ``.
7. Observe that `` is reopened almost immediately.
8. Delete only the Claude Code project/session directory for ``, leaving Claude session directories for unrelated repositories intact.
9. Reload VS Code and close `` again.
10. Observe that `` now remains closed. The unrelated Claude projects are not opened.
## Expected Behavior
Closing a repository from the Source Control view should be an explicit and persistent action. Discovering or displaying a persisted Claude Code session should not reopen its working directory as a Git repository.
## Actual Behavior
When a persisted Claude Code session belongs to a sibling linked worktree, closing that worktree triggers a session refresh, after which Copilot immediately opens the worktree again in the Source Control repository list.
This repeats every time the worktree is manually closed.
## Additional Diagnostics
- `` and `` are linked worktrees of the same Git repository.
- An unrelated repository also has several entries under `~/.claude/projects/`, but it is not opened.
- Therefore, the trigger is not the mere presence of entries under `~/.claude/projects/`; the Git worktree relationship appears to be required.
- `git.detectWorktrees` is not enabled in the user settings, and its built-in default is `false`.
- The separate `chatParticipant must be declared in package.json: claude-code` error is not involved in this reproduction.
Inspection of the installed Copilot extension and Claude Agent SDK suggests the following sequence:
1. Copilot requests Claude sessions using the current workspace directory.
2. The Claude Agent SDK includes sessions belonging to all linked Git worktrees by default (`includeWorktrees: true`).
3. Copilot creates metadata for the session belonging to ``.
4. During metadata construction, Copilot performs a Git repository lookup that is allowed to call `openRepository(...)`.
5. Consequently, the sibling worktree is reopened even though the user explicitly closed it.
The worktree-aware session discovery itself may be intentional. The unexpected behavior is that constructing session metadata has the side effect of reopening a closed Git repository.
## Workaround
Delete the Claude Code project/session directory corresponding specifically to the affected worktree:
```text
~/.claude/projects//
```
This removes the local Claude Code session history for that worktree. Deleting the entire `~/.claude/projects/` directory is not necessary.
## Suggested Fix
When constructing Claude session metadata, use a non-opening Git repository lookup and respect repositories that the user has explicitly closed.
For example, use the equivalent of `getRepository(uri, false)` or another lookup that does not call `openRepository(...)`.
If sessions from sibling worktrees are not intended to appear in the current window, another possible change would be to call the Claude SDK with `includeWorktrees: false`; however, preventing the metadata lookup from reopening repositories would preserve cross-worktree session discovery without overriding the user's explicit close action.
Assisted-by: Codex:gpt-5.6-sol[max]
Contributor guide
Assessment
This issue has not been assessed yet.