Skip to content

Support COPILOT_HOME for Copilot CLI state#314917

Open
praneethhere wants to merge 2 commits intomicrosoft:mainfrom
praneethhere:support-copilot-home-env
Open

Support COPILOT_HOME for Copilot CLI state#314917
praneethhere wants to merge 2 commits intomicrosoft:mainfrom
praneethhere:support-copilot-home-env

Conversation

@praneethhere
Copy link
Copy Markdown

@praneethhere praneethhere commented May 7, 2026

Summary

Adds support for COPILOT_HOME when resolving Copilot CLI state directories

The lookup order is now:

  1. COPILOT_HOME
  2. XDG_STATE_HOME/.copilot
  3. ~/.copilot

This keeps the existing XDG and home-directory fallback behavior while allowing users to explicitly relocate Copilot CLI state

Fixes #314806

Validation

  • Ran npm run eslint
  • Ran npm run watch; Copilot build/typecheck completed with 0 errors

Validation second run

  • Ran git diff --check
  • Ran npm --prefix extensions/copilot run test:unit -- src/extension/chatSessions/copilotcli/node/test/cliHelpers.spec.ts
  • Ran npm run eslint

@praneethhere
Copy link
Copy Markdown
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
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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().

Comment on lines 11 to +16
export function getCopilotHome(): string {
const copilotHome = process.env.COPILOT_HOME;
if (copilotHome) {
return copilotHome;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks, addressed by adding unit coverage for COPILOT_HOME precedence and restoring COPILOT_HOME/XDG_STATE_HOME between test cases

Comment on lines +12 to +20
const copilotHome = process.env.COPILOT_HOME;
if (copilotHome) {
return copilotHome;
}

const xdgHome = process.env.XDG_STATE_HOME;
return xdgHome ? join(xdgHome, COPILOT_HOME_DIRECTORY) : join(homedir(), COPILOT_HOME_DIRECTORY);
return xdgHome
? join(xdgHome, COPILOT_HOME_DIRECTORY)
: join(homedir(), COPILOT_HOME_DIRECTORY);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Nice catch. Aligned the agentHost session-state resolver with same COPILOT_HOME -> XDG_STATE_HOME -> home precedence so session-state paths remain consistent

@praneethhere praneethhere force-pushed the support-copilot-home-env branch from 8e74877 to ebfc4ef Compare May 7, 2026 07:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support COPILOT_HOME env var to relocate Copilot home directory.

5 participants