Skip to content

Support COPILOT_HOME for Copilot CLI state - #314917

Merged
Dmitriy Vasyura (dmitrivMS) merged 12 commits into
microsoft:mainfrom
praneethhere:support-copilot-home-env
Jul 31, 2026
Merged

Dmitriy Vasyura (dmitrivMS) merged 12 commits into
microsoft:mainfrom
praneethhere:support-copilot-home-env

Conversation

@praneethhere

@praneethhere Praneeth Kodumagulla (praneethhere) commented May 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds support for COPILOT_HOME when resolving Copilot CLI state directories across the Copilot extension, Agent Host, and workbench diagnostics.

The lookup order now matches the current Copilot CLI:

  1. COPILOT_HOME
  2. ~/.copilot

The extension and Agent Host reuse a consistent Copilot home resolver for:

  • IDE state and lock files under <COPILOT_HOME>/ide
  • session state and events.jsonl under <COPILOT_HOME>/session-state
  • permission handling for internal session resources such as plan.md
  • Open Copilot CLI State File
  • Chat Debug session discovery and live event loading
  • troubleshooting context that references session event logs
  • Export Agent Host Debug Logs, including Copilot SDK process logs under <COPILOT_HOME>/logs

This keeps session discovery, permissions, diagnostics, and log collection aligned with the directory the Copilot CLI actually uses.

Why XDG_STATE_HOME is not used

Older Copilot CLI versions stored state under $XDG_STATE_HOME/.copilot. Current Copilot CLI versions no longer treat XDG as an active configuration location. When COPILOT_HOME is not set, the CLI migrates previous XDG-based data to ~/.copilot at startup and then uses ~/.copilot.

Keeping XDG_STATE_HOME in VS Code's runtime lookup could therefore make VS Code inspect a different session-state, IDE lockfile, or diagnostics directory than the CLI itself. This change removes that mismatch while retaining migration responsibility in the CLI.

Remote Agent Host diagnostics continue to use the remote host's reported home directory because AHP does not currently expose the remote process's COPILOT_HOME.

The affected tests set and restore COPILOT_HOME explicitly so they remain hermetic when a developer or CI environment already defines it.

Fixes #314806

Validation

  • Copilot extension unit tests: 65 passed, 2 skipped
  • Agent Host unit tests: 402 passed
  • Copilot home helper tests: 3 passed
  • State-file and Copilot log URI resolver tests: 11 passed
  • npm run precommit
  • Editor diagnostics: no problems in changed files

npm run typecheck-client and npm run valid-layers-check currently reach an unrelated existing error in src/vs/platform/agentHost/node/copilot/copilotSystemNotification.ts on the latest main.

@praneethhere

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

@Montiwa11

Copy link
Copy Markdown

Agreed Montiwa11

Copilot AI review requested due to automatic review settings May 7, 2026 06:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for the COPILOT_HOME environment variable when resolving Copilot CLI state directories in the Copilot extension, while preserving the existing XDG and home-directory fallback behavior. This aligns the extension with the documented Copilot CLI configuration mechanism and helps Windows users avoid creating ~/.copilot by default.

Changes:

  • Add COPILOT_HOME as the highest-precedence location for Copilot CLI state.
  • Refactor CLI state and session-state directory resolution to be based on getCopilotHome().

@DonJayamanne
Don Jayamanne (DonJayamanne) enabled auto-merge (squash) May 13, 2026 06:17
@praneethhere

Copy link
Copy Markdown
Contributor Author

Don Jayamanne (@DonJayamanne) Alex Ross (@alexr00) Thanks for the review and approvals. I see Component Screenshots check is failing while the related Copilot/compile checks are passing. Since this change does not affect UI rendering, should I wait for a rerun or is there anything you would like me to do?

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as draft July 29, 2026 06:04
auto-merge was automatically disabled July 29, 2026 06:04

Pull request was converted to draft

Use COPILOT_HOME as the configured Copilot root and otherwise fall back to ~/.copilot, matching the current CLI. XDG_STATE_HOME is now a migration source handled by the CLI rather than an active state location.

Co-authored-by: Copilot <[email protected]>
@dmitrivMS

Copy link
Copy Markdown
Collaborator

Updated this PR against current main and aligned the implementation with the current Copilot CLI directory contract.

The important adjustment is that XDG_STATE_HOME is no longer part of VS Code's active lookup. Older CLI versions used $XDG_STATE_HOME/.copilot, but current versions treat that as a legacy migration source: when COPILOT_HOME is unset, the CLI migrates old XDG-based data to ~/.copilot at startup and then uses ~/.copilot.

If VS Code continued resolving session state or IDE lockfiles through XDG_STATE_HOME, it could inspect a different directory from the CLI after migration. Resolution is therefore now COPILOT_HOME when set, otherwise ~/.copilot, and the Agent Host path reuses the shared getCopilotHomePath helper. I also updated affected tests to isolate and restore COPILOT_HOME explicitly.

Reference: https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-config-dir-reference

@dmitrivMS

Copy link
Copy Markdown
Collaborator

Praneeth Kodumagulla (@praneethhere) I've made some updates, could you please help to test/verify that these changes still address original issue?

@DonJayamanne
Don Jayamanne (DonJayamanne) marked this pull request as ready for review July 30, 2026 23:33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer check XDG_STATE_HOME
Let me double check

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmitrivMS

Copy link
Copy Markdown
Collaborator

We no longer check XDG_STATE_HOME Let me double check

Yes, this is intentional - the point that AI made is that Copilot CLI does not support it any longer, only migrates on first start.

Don Jayamanne (DonJayamanne) added a commit to praneethhere/vscode that referenced this pull request Jul 31, 2026
Resolve the Copilot agent session conflict by preserving the latest agent host changes while using COPILOT_HOME for CLI session state.

Co-authored-by: Copilot <[email protected]>
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

TylerLeonhardt

Matched files:

  • src/vs/platform/agentHost/node/claude/claudeMapSessionEvents.ts
  • src/vs/platform/agentHost/node/claude/claudeReplayMapper.ts
  • src/vs/platform/agentHost/node/claude/claudeSubagentSignals.ts
  • src/vs/platform/agentHost/node/claude/claudeToolCallRegistry.ts
  • src/vs/platform/agentHost/node/claude/claudeToolDisplay.ts
  • src/vs/platform/quickinput/browser/quickInputActions.ts

Benjamin Christopher Simmonds (@benibenj)

Matched files:

  • src/vs/sessions/browser/parts/agentsPartCard.ts
  • src/vs/sessions/browser/parts/chatView.ts
  • src/vs/sessions/browser/parts/customViewGridPart.ts
  • src/vs/sessions/browser/parts/customViewGridParts.ts
  • src/vs/sessions/browser/parts/customViewNode.ts
  • src/vs/sessions/browser/parts/media/customViewGridPart.css
  • src/vs/sessions/browser/parts/mobile/mobileChatShell.css
  • src/vs/sessions/browser/parts/mobile/mobileCustomViewGridPart.ts
  • src/vs/sessions/browser/parts/mobile/mobileSessionsPart.ts
  • src/vs/sessions/browser/parts/panelPart.ts
  • src/vs/sessions/browser/parts/sessionView.ts
  • src/vs/sessions/browser/parts/sessionsPart.ts
  • src/vs/sessions/browser/workbench.ts
  • src/vs/sessions/contrib/layout/browser/baseSessionLayoutController.ts
  • src/vs/sessions/contrib/layout/test/browser/layoutControllerTestUtils.ts
  • src/vs/workbench/services/layout/browser/layoutService.ts

Sandeep Somavarapu (@sandy081)

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsService.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

Ladislau Szomoru (@lszomoru)

Matched files:

  • src/vs/sessions/services/sessions/browser/sessionsService.ts
  • src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts

@DonJayamanne

Copy link
Copy Markdown
Contributor

yikes, copilot messed up the merge conflict badly
I reviewed the chagnes locally, but it didint' work

Resolve the Copilot agent session conflict by preserving the latest agent host changes while using COPILOT_HOME for CLI session state.

Co-authored-by: Copilot <[email protected]>
…ot-home-env' into dev/dmitriv/support-copilot-home-env
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as draft July 31, 2026 00:34
auto-merge was automatically disabled July 31, 2026 00:34

Pull request was converted to draft

@dmitrivMS
Dmitriy Vasyura (dmitrivMS) marked this pull request as ready for review July 31, 2026 00:45
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) enabled auto-merge (squash) July 31, 2026 00:45
@dmitrivMS
Dmitriy Vasyura (dmitrivMS) merged commit b8f42e0 into microsoft:main Jul 31, 2026
29 checks passed
@vs-code-engineering vs-code-engineering Bot added this to the 1.132.0 milestone Jul 31, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Oct 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support COPILOT_HOME env var to relocate Copilot home directory.

9 participants