Claude agent host: proxy-mode sessions on Windows get an allow-listed environment (no PATHEXT, ComSpec, APPDATA), so pwsh cannot run git or other tools
Does this issue occur when all extensions are disabled?: Not tested; the cause is in the built-in agent host (out/vs/platform/agentHost/node/agentHostMain.js), not an extension.
- VS Code Version: 1.141.2 (16507d91be0dc1ce4f94c04d4d0430210b8685d9), x64
- OS Version: Windows 11 Pro 10.0.26300
- Harness: Agents window, Claude agent host, Claude Agent SDK 0.3.281, signed in with GitHub (Copilot proxy mode). Local machine, no remote.
Problem
On Windows, Claude agent host sessions in proxy mode start with almost no environment. PATH, HOME, USERPROFILE, TEMP and a few others survive. PATHEXT, ComSpec, APPDATA, LOCALAPPDATA, ProgramData, COMPUTERNAME, OS, PROCESSOR_*, JAVA_HOME and the user's other variables are missing.
The consequences:
- PowerShell 7 started without
PATHEXTsets it to.CPLonly. It then finds only.ps1shims, sogit,gh,node,python,cmdand almost every other installed program are "not recognized".& 'C:\Program Files\Git\cmd\git.exe' --versionprints nothing and leaves$LASTEXITCODEempty. - Tools that keep their configuration under
%APPDATA%lose it. In the Bash tool,gh auth statusreports "You are not logged into any GitHub hosts" although gh is signed in. - Scripts that read
COMPUTERNAMEor similar variables fail.
The same tools and commands work from a terminal and from the Claude Code CLI on the same machine.
Steps to Reproduce
- On Windows, open the Agents window and start a Claude agent host session while signed in with GitHub (proxy mode).
- Ask the agent to run, in its Bash tool:
echo "PATHEXT=[$PATHEXT] APPDATA=[$APPDATA]"; pwsh -NoProfile -Command 'git --version' - Both variables are empty, and pwsh reports
gitis not recognized. A VS Code terminal shows both set and runs git.
Cause
agentHostMain.js builds the SDK env with a helper that, for proxy mode, starts from a fixed allow-list (minified, 1.141.2):
function HV(o=!0){let i=o?{ELECTRON_RUN_AS_NODE:"1",NODE_OPTIONS:void 0,ANTHROPIC_API_KEY:void 0,HOME:process.env.HOME,USERPROFILE:process.env.USERPROFILE,CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD:"1"}:{...process.env,ELECTRON_RUN_AS_NODE:"1",NODE_OPTIONS:void 0}; ...
It is called as HV(i.kind==="proxy"), so only native mode inherits process.env. Proxy mode is selected whenever a GitHub token is present, which makes it the normal case.
Expected
Proxy-mode sessions should inherit the user's environment the way native mode and the terminal do. Remove only what has to change: ANTHROPIC_* credentials, NODE_OPTIONS, VSCODE_* and ELECTRON_*. The Windows base variables at minimum (PATHEXT, ComSpec, SystemRoot, APPDATA, LOCALAPPDATA, ProgramData, ProgramFiles*, COMPUTERNAME) are required for normal tool execution on Windows.
Workaround
The SDK call passes settingSources: ["user","project","local"], so variables written into the env block of ~/.claude/settings.json reach the session. Writing the machine's Windows base variables there (never PATH) restored every tool we use: git, gh, node, npm, python, java, gcloud, firebase, WSL, tailscale and others.
Thanks for creating this issue! It looks like you may be using an old version of VS Code; the latest stable release is 1.143.1. Please try upgrading to the latest version and checking whether this issue remains.
Happy Coding!
Hi @scottboyan,
Thanks for the detailed investigation and reproduction steps.
I'd be interested in contributing a focused fix for this issue.
The report suggests that proxy-mode Claude agent sessions receive a restricted environment that omits essential Windows variables such as PATHEXT, ComSpec, APPDATA, and LOCALAPPDATA, causing common development tools to fail.
I'd like to investigate:
- Whether the issue remains reproducible on the latest VS Code release.
- How environment variables are constructed for proxy-mode versus native-mode sessions.
- How to preserve essential Windows environment variables without exposing sensitive credentials or weakening environment isolation.
- Regression tests covering PowerShell tool execution and expected variable filtering.
I'll review the existing implementation and contribution guidelines before proposing changes.
Is anyone already working on a fix, and would a focused external contribution be welcome?
Thanks! Putluru Sandeep (@sunny-kavixo)
Still present after upgrading to the latest stable release. Retested 2026-10-24 on the same machine.
- VS Code 1.143.1 (e646868227c3e3a9e3f24277c8c7220be42c0be7), x64, Windows 11 Pro 10.0.26300
- Agents window, Claude agent host, Claude Agent SDK 0.3.281, signed in with GitHub (proxy mode:
ANTHROPIC_BASE_URLis the localhost proxy)
Code
The installed out/vs/platform/agentHost/node/agentHostMain.js has the same proxy-mode allow-list (the function is now minified as Uve):
function Uve(o=!0){let i=o?{ELECTRON_RUN_AS_NODE:"1",NODE_OPTIONS:void 0,ANTHROPIC_API_KEY:void 0,HOME:process.env.HOME,USERPROFILE:process.env.USERPROFILE,CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD:"1"}:{...process.env,ELECTRON_RUN_AS_NODE:"1",NODE_OPTIONS:void 0}; ...
The source matches: buildSubprocessEnv(proxied) in src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts at 1.143.1. The only change from 1.141.2 is the AI_AGENT marker. On main the file was last changed in ab09914dcc (2026-09-02), so main has it too.
Observed in a live 1.143.1 session
I compared the session's process environment with the env block of ~/.claude/settings.json, which holds our workaround (below). Every Windows base variable in the session (PATHEXT, ComSpec, SystemRoot, APPDATA, LOCALAPPDATA, ProgramData, ProgramFiles*, COMPUTERNAME, OS, PROCESSOR_*, TEMP, USERNAME, ...) comes from that settings block. The harness itself supplies only:
HOME,USERPROFILE,PATHAI_AGENT,ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,ELECTRON_RUN_AS_NODE- names that Claude Code and Git Bash set for themselves (
CLAUDE_*,CLAUDECODE,MSYSTEM,SHELL,TERM, ...)
Without the workaround, the session would still have no PATHEXT, ComSpec, SystemRoot or APPDATA. pwsh would then fail to find git, gh, node or cmd, and gh would lose its login, exactly as in the original report.
How we work around it (we would still like this fixed)
Workaround details, for anyone else who hits this:
- A script reads the user's Windows environment from the registry: machine (
HKLM\...\Session Manager\Environment), user (HKCU\Environment) and logon (HKCU\Volatile Environment). It adds the process-only base names (SystemRoot,ComSpec,PROCESSOR_*, ...). - It writes them into the
envblock of~/.claude/settings.json, which the agent host loads throughsettingSources: ["user","project","local"]. - It leaves out
PATH(the harness passes it already),PSModulePath, and everyANTHROPIC_*/CLAUDE_*/VSCODE_*/ELECTRON_*name, so it can't interfere with the proxy. - It records which names it manages, so a variable an installer later removes gets removed too.
- A per-user scheduled task reruns it at every sign-in, so new or changed variables are picked up.
- Each new Claude session then gets a working environment. Sessions that were already open keep the environment they started with.
On this machine, with the workaround in place, pwsh in a new 1.143.1 session runs git (2.55.0), gh (logged in), node, npm, cmd, WSL, gcloud, firebase and the rest of our tools.
This is still a workaround, not a fix:
- Every Windows user of the Claude agent host in proxy mode hits this until they find it. The symptom ("git is not recognized" only in pwsh, only in this harness) doesn't point to the cause.
- It's a snapshot of the environment in a settings file. It gets out of date until the sign-in task runs again, and it can't follow per-process changes the way inheritance does.
- Copying the whole user environment into
~/.claude/settings.jsonputs any secret-looking user variables in a plain settings file. Inheritance would avoid that.
Suggested fix (unchanged)
In proxy mode, start from process.env as native mode does. Then remove only what must not reach the proxy or the child: ANTHROPIC_* (at least ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN, ANTHROPIC_BASE_URL), NODE_OPTIONS, VSCODE_* and ELECTRON_*. That keeps the stated goal in the source comment (the user's ANTHROPIC_API_KEY doesn't leak to the Copilot proxy) and gives the Windows base variables back.
If an allow-list has to stay, it needs at least these on Windows: PATHEXT, ComSpec, SystemRoot, windir, SystemDrive, APPDATA, LOCALAPPDATA, ProgramData, ProgramFiles, ProgramFiles(x86), ProgramW6432, CommonProgramFiles*, TEMP, TMP, USERNAME, USERDOMAIN, COMPUTERNAME, OS, PROCESSOR_ARCHITECTURE, NUMBER_OF_PROCESSORS, HOMEDRIVE, HOMEPATH. An allow-list would still drop tool-specific variables (JAVA_HOME and so on), which is why inheritance is the better fix.
Proposed fix, in detail (not built or tested by us)
This is a precise description of the change we think fixes the issue. It's for whoever picks it up, including @sunny-kavixo, who offered. We have not built VS Code with it or run the tests, so treat it as a specification. Line numbers are for main at 86db3b6922.
1. src/vs/platform/agentHost/node/claude/claudeSdkOptions.ts: buildSubprocessEnv (about L386-L412)
Today, proxy mode starts from a fixed allow-list. Native mode already starts from { ...process.env }. The SDK replaces the subprocess environment with Options.env, so in proxy mode every Windows base variable is lost (PATHEXT, ComSpec, SystemRoot, APPDATA, ...).
The proposal: both modes inherit process.env. Proxy mode then removes only the user's own Claude credentials and provider-routing variables. Those are what the existing comment wants kept away from the Copilot proxy, plus anything that would send traffic around the proxy. The proxy's own ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN still arrive through settings.env in buildOptions, which is unchanged.
Replace the function with:
/**
* Removed from the inherited env in proxied mode, so the user's own Claude
* credentials and provider routing neither reach the Copilot proxy nor route
* traffic around it. The proxy's ANTHROPIC_BASE_URL / ANTHROPIC_AUTH_TOKEN
* arrive through `settings.env` (see buildOptions).
* - ANTHROPIC_*: API keys, auth tokens, profiles, base URLs, Bedrock/Vertex/Foundry
* endpoints and keys, custom headers, model aliases
* - CLAUDE_CODE_OAUTH_*: claude setup-token / refresh-token credentials
* - CLAUDE_CODE_USE_*: provider selection (Bedrock, Vertex, Foundry, ...)
* - AWS_BEARER_TOKEN_BEDROCK: Bedrock API key
* Other CLAUDE_CODE_* names are user preferences (for example
* CLAUDE_CODE_GIT_BASH_PATH, which Windows users may need) and are kept.
*/
const PROXY_STRIPPED_PREFIXES = ['ANTHROPIC_', 'CLAUDE_CODE_OAUTH_', 'CLAUDE_CODE_USE_'];
const PROXY_STRIPPED_NAMES = new Set(['AWS_BEARER_TOKEN_BEDROCK']);
export function buildSubprocessEnv(proxied: boolean = true): Record<string, string | undefined> {
// Both modes inherit the real env: replace semantics would otherwise drop the
// OS base variables the CLI and its tools need (on Windows PATHEXT, ComSpec,
// SystemRoot, APPDATA, ...; microsoft/vscode#344072).
const env: Record<string, string | undefined> = { ...process.env, ELECTRON_RUN_AS_NODE: '1', NODE_OPTIONS: undefined };
if (proxied) {
for (const key of Object.keys(process.env)) {
// Windows env names are case-insensitive.
const upper = key.toUpperCase();
if (PROXY_STRIPPED_NAMES.has(upper) || PROXY_STRIPPED_PREFIXES.some(prefix => upper.startsWith(prefix))) {
env[key] = undefined;
}
}
// Load rules from additional directories https://code.claude.com/docs/en/memory#load-from-additional-directories
env['CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD'] = '1';
}
env[AiAgentEnvVar] = AiAgentEnvValue;
for (const key of Object.keys(process.env)) {
if (key === 'ELECTRON_RUN_AS_NODE') { continue; }
if (key.startsWith('VSCODE_') || key.startsWith('ELECTRON_')) {
env[key] = undefined;
}
}
return env;
}
Notes:
PATHnow reaches the subprocess env in proxy mode too.settings.env.PATH(ripgrep directory prepended) is still set inbuildOptionsand still takes effect for the commands the CLI runs. Nothing else inbuildOptionschanges.- Native mode behaves exactly as before.
buildModelEnumerationOptions(buildSubprocessEnv(false)) is unaffected. CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MDstays proxy-only, as today.- The strip list comes from the Claude Code environment-variable reference (https://code.claude.com/docs/en/env-vars, "authentication" and "routing/provider" variables). Two choices for the maintainers that we left alone:
- Stripping the mTLS client-certificate variables (
CLAUDE_CODE_CLIENT_CERT,CLAUDE_CODE_CLIENT_KEY,CLAUDE_CODE_CLIENT_KEY_PASSPHRASE). They hold paths, not secrets, and shouldn't matter for a localhost proxy. - Stripping
CLAUDE_CODE_EXTRA_BODY.
- Stripping the mTLS client-certificate variables (
- Update the doc comment above the function (about L295-L322): it says proxy mode is "a sparse env". It should say proxy mode inherits the env minus the credential/routing names above.
2. src/vs/platform/agentHost/test/node/claudeSdkOptions.test.ts
- Add these to
KNOWN_KEYS(about L20) soclearAndSet/teardownclean them up:PATHEXT,ComSpec,SystemRoot,APPDATA,JAVA_HOME,CLAUDE_CODE_GIT_BASH_PATH,ANTHROPIC_BASE_URL,ANTHROPIC_AUTH_TOKEN,CLAUDE_CODE_OAUTH_TOKEN,CLAUDE_CODE_USE_BEDROCK,AWS_BEARER_TOKEN_BEDROCK. strips unsafe variables and forwards home paths in proxy mode(about L44): change the expectedpathfromundefinedto'/usr/bin', and update its comment. Everything else in that test should still hold.- New test:
test('proxy mode inherits the OS environment but strips Claude credentials and provider routing', () => {
clearAndSet({
PATH: 'C:\\Windows\\system32',
PATHEXT: '.COM;.EXE;.BAT;.CMD',
ComSpec: 'C:\\Windows\\system32\\cmd.exe',
SystemRoot: 'C:\\Windows',
APPDATA: 'C:\\Users\\test\\AppData\\Roaming',
JAVA_HOME: 'C:\\jdk',
CLAUDE_CODE_GIT_BASH_PATH: 'C:\\Program Files\\Git\\bin\\bash.exe',
ANTHROPIC_API_KEY: 'sk-leak',
ANTHROPIC_BASE_URL: 'https://gateway.example',
ANTHROPIC_AUTH_TOKEN: 'gateway-leak',
CLAUDE_CODE_OAUTH_TOKEN: 'sk-ant-oat-leak',
CLAUDE_CODE_USE_BEDROCK: '1',
AWS_BEARER_TOKEN_BEDROCK: 'bedrock-leak',
});
const env = buildSubprocessEnv();
assert.deepStrictEqual({
path: env.PATH,
pathext: env.PATHEXT,
comSpec: env.ComSpec,
systemRoot: env.SystemRoot,
appData: env.APPDATA,
javaHome: env.JAVA_HOME,
gitBashPath: env.CLAUDE_CODE_GIT_BASH_PATH,
apiKey: env.ANTHROPIC_API_KEY,
baseUrl: env.ANTHROPIC_BASE_URL,
authToken: env.ANTHROPIC_AUTH_TOKEN,
oauthToken: env.CLAUDE_CODE_OAUTH_TOKEN,
useBedrock: env.CLAUDE_CODE_USE_BEDROCK,
bedrockKey: env.AWS_BEARER_TOKEN_BEDROCK,
additionalDirs: env.CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD,
}, {
path: 'C:\\Windows\\system32',
pathext: '.COM;.EXE;.BAT;.CMD',
comSpec: 'C:\\Windows\\system32\\cmd.exe',
systemRoot: 'C:\\Windows',
appData: 'C:\\Users\\test\\AppData\\Roaming',
javaHome: 'C:\\jdk',
gitBashPath: 'C:\\Program Files\\Git\\bin\\bash.exe',
apiKey: undefined,
baseUrl: undefined,
authToken: undefined,
oauthToken: undefined,
useBedrock: undefined,
bedrockKey: undefined,
additionalDirs: '1',
});
});
proxy transport sets ANTHROPIC_BASE_URL + per-session ANTHROPIC_AUTH_TOKEN(about L344) checkssettings.env, which doesn't change, so it should pass as is. The native-mode test (about L144) should also pass unchanged.
3. Manual verification on Windows
The settings workaround hides the bug, so first remove any Windows variables you added to the env block of ~/.claude/settings.json. Then:
- Sign in with GitHub so the session uses proxy mode, and start a new Claude session in the Agents window.
- Ask it to run, in its Bash tool:
echo "PATHEXT=[$PATHEXT] APPDATA=[$APPDATA]"; pwsh -NoProfile -Command 'git --version; cmd /c echo ok'; gh auth status - Expect: both variables set, git's version and
okprinted, and gh logged in. Before the fix: both are empty, pwsh reportsgitis not recognized, and gh is not logged in. - Credential check: put
ANTHROPIC_API_KEY=sk-testin the environment VS Code starts with, start a new session, and confirm thatecho "[$ANTHROPIC_API_KEY]"in the Bash tool prints[]and that requests still go through the Copilot proxy.
Still present in VS Code 1.147.0 (8a14f0cc1b08d531eb83255ea3764ae22aa932b5, x64), Claude Agent SDK 0.3.304, Windows 11 Enterprise 10.0.26200, proxy mode. The allow-list is unchanged; the helper is now minified as ZFe.
Another symptom: stdio MCP servers started from the session inherit the same environment. A server launched as powershell -NoProfile -File launcher.ps1 gets PATHEXT=.CPL, so uvx inside the script is "not recognized" and the server never starts. The same server works in Claude Code, which passes the full environment.
Workaround in the launcher: $env:PATHEXT = [Environment]::GetEnvironmentVariable('PATHEXT', 'Machine') + ';' + $env:PATHEXT
Same bug on Linux (VS Code 1.147.0, Ubuntu 26.04, Claude Agent SDK 0.3.304, proxy mode). The Claude process that the agent host starts has no PATH in its environment, only in --settings → env, so Claude Code can't find bwrap/socat although both are installed. By default it then silently runs Bash without the sandbox. With sandbox.failIfUnavailable: true in ~/.claude/settings.json, every message fails:
Error: (sendFailed) Claude Code returned an error result: Sandbox required but unavailable: sandbox is enabled but dependencies are missing: bubblewrap (bwrap) not installed, socat not installed
#344086 should fix this too.
Thanks for the detailed analysis. I can confirm the mechanism on macOS with VS Code Insiders 1.147.0, in the Agents window, signed in with GitHub (proxy mode):
- I started a Claude session and asked it to print the environment from its Bash tool.
HOMEandPATHare set.TMPDIR,USERandLANGare empty, although the app has them. buildSubprocessEnvinsrc/vs/platform/agentHost/node/claude/claudeSdkOptions.tsstill uses the same proxy-mode allow-list onmain. Running it there dropsPATHEXT,ComSpec,APPDATA,LOCALAPPDATAandJAVA_HOME, while native mode keeps them.
I haven't tried this on Windows, but the same code drops the variables listed in the report there.
🤖 Authored with GitHub Copilot on behalf of @alexdima.
Root cause on main (ef5ca45a6e): in proxy mode, buildSubprocessEnv passes a fixed allow-list as Options.env. Since SDK 0.3, that replaces the subprocess environment. PATH reaches only settings.env, which applies to the commands the CLI runs, not to the CLI process itself.
How it happened: c9b1f88ce76 (#314533) wrote that object as a set of overrides, when SDK 0.2 merged Options.env into process.env. The move to SDK 0.3 (#320709) made it the whole environment, and #323037 fixed this for native mode only.
Impact:
- Windows: no
PATHEXT,ComSpec,APPDATA, ... (libuv restores only a few, such asPATH,TEMPandSYSTEMROOT). pwsh can't find tools andghloses its login. - Linux: the CLI process has no
PATH, so Claude Code can't findbwrap/socat. With the sandbox enabled, Bash runs unsandboxed with only a warning, or every message fails withfailIfUnavailable. - macOS: no
TMPDIR,USER,LANGorSSH_AUTH_SOCK. - stdio MCP servers started by the CLI get the same environment.
Suggested fix: inherit process.env in both modes, as createCopilotCliEnvironment does for the Copilot agent. In proxy mode, remove only Claude credentials and provider routing (ANTHROPIC_*, CLAUDE_CODE_OAUTH_*, the explicit CLAUDE_CODE_USE_<provider> selectors, AWS_BEARER_TOKEN_BEDROCK), ignoring case on Windows. #344086 mostly does this. One gap: once HTTP(S)_PROXY is inherited, requests to the loopback Copilot proxy may be sent through a corporate proxy, so proxy mode should add loopback to NO_PROXY.
Reassigning to @TylerLeonhardt, who owns agentHost/node/claude.
🤖 Authored with GitHub Copilot on behalf of @chrmarti.