Skip to content

Default background agent repo to SCM-selected repo in multi-root workspaces#3976

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-worktree-repo-alignment
Draft

Default background agent repo to SCM-selected repo in multi-root workspaces#3976
Copilot wants to merge 2 commits intomainfrom
copilot/fix-worktree-repo-alignment

Conversation

Copy link
Contributor

Copilot AI commented Feb 24, 2026

In multi-root workspaces, new background agent sessions defaulted to the MRU or first available repo instead of the repo currently selected in the SCM view, requiring a manual correction each time.

Change

  • getDefaultUntitledSessionRepositoryOption (copilotCLIChatSessionsContribution.ts): When no folder is already stored for the session, use gitService.activeRepository (the SCM-selected repo) as the first preference, before falling back to MRU then first available.

New priority order for the default repo picker:

  1. Previously stored session folder (unchanged)
  2. SCM-active repository ← new
  3. Last used folder (MRU)
  4. First available repository
const activeRepo = this.gitService.activeRepository.get();
const activeRepoId = activeRepo?.rootUri.fsPath;
const lastUsedFolderId = this.folderRepositoryManager.getLastUsedFolderIdInUntitledWorkspace();
const firstRepo = (activeRepoId && repositories.find(repo => repo.id === activeRepoId)?.id)
    ?? (lastUsedFolderId && repositories.find(repo => repo.id === lastUsedFolderId)?.id)
    ?? repositories[0].id;
Original prompt

This section details on the original issue you should resolve

<issue_title>Worktree repo doesn't align with scm multiroot repo</issue_title>
<issue_description>🩸 Picked repo for background agents should align with the scm selected repo in multi root workflows. Changing it manually each time is a bit of a papercut

Image

<agent_instructions>The changes are to be made in src/extension/chatSessions/vscode-node/copilotCLIChatSessionsContribution.ts
See getDefaultUntitledSessionRepositoryOption method</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@DonJayamanne Agreed.

🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… workspaces

Co-authored-by: DonJayamanne <1948812+DonJayamanne@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix worktree repo alignment with scm multiroot repo Default background agent repo to SCM-selected repo in multi-root workspaces Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Worktree repo doesn't align with scm multiroot repo

2 participants