The best way to control Claude Code, Codex and more from any computer or phone
fix(shell): Windows PATH probe reads User and Machine registry (#37632)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Dieter committed
Nov 16, 2026 at 23:48 UTC
5a20d59db38abef8e0b98cfe47fed81d074bcecc
12 files changed
+210
-9
apps/desktop/src/shell/DesktopShellEnvironment.ts
+2
-1
@@ -6,6 +6,7 @@ import {
6
mergePathValues,
7
readUserLoginShell,
8
setWindowsPath,
9
+ windowsEnvironmentValueCommand,
10
} from "@t3tools/shared/shell";
11
import * as Context from "effect/Context";
12
import * as Duration from "effect/Duration";
@@ -232,7 +233,7 @@ const captureWindowsEnvironmentCommand = (names: ReadonlyArray<string>) =>
233
...names.flatMap((name) => {
234
return [
235
`Write-Output '${startMarker(name)}'`,
235
- `$value = [Environment]::GetEnvironmentVariable('${name}')`,
236
+ windowsEnvironmentValueCommand(name),
237
"if ($null -ne $value -and $value.Length -gt 0) { Write-Output $value }",
238
`Write-Output '${endMarker(name)}'`,
239
];
apps/server/src/os-jank.test.ts
+18
-1
@@ -8,7 +8,7 @@ import * as NodeChildProcess from "node:child_process";
8
import * as NodeOS from "node:os";
9
import { assert, it, vi } from "vite-plus/test";
10
11
-import { fixPath, hydratePosixHome } from "./os-jank.ts";
11
+import { fixPath, hydratePosixHome, refreshWindowsPath } from "./os-jank.ts";
12
13
vi.mock("node:child_process", { spy: true });
14
@@ -204,3 +204,20 @@ effectIt.effect("replaces a Path-spelled Windows PATH instead of adding a second
204
assert.deepEqual(env, { PATH: "C:\\Tools;C:\\Windows" });
205
}),
206
);
207
+
208
+effectIt.effect("adds a directory an installer wrote to the registry after launch", () =>
209
+ Effect.gen(function* () {
210
+ const env: NodeJS.ProcessEnv = { Path: "C:\\Tools;C:\\Windows" };
211
+ const installed = "C:\\Users\\me\\AppData\\Local\\cursor-agent";
212
+
213
+ yield* refreshWindowsPath().pipe(
214
+ Effect.provideService(HostProcess.Platform, "win32"),
215
+ Effect.provideService(HostProcess.Environment, env),
216
+ Effect.provideService(WindowsShellEnvironment, () =>
217
+ Effect.succeed({ PATH: `C:\\Windows;${installed}` }),
218
+ ),
219
+ );
220
+
221
+ assert.deepEqual(env, { PATH: `C:\\Tools;C:\\Windows;${installed}` });
222
+ }),
223
+);
apps/server/src/os-jank.ts
+16
@@ -4,10 +4,12 @@ import {
4
extractEnvironmentValues,
5
listLoginShellCandidates,
6
mergePathEntries,
7
+ mergePathValues,
8
readEnvironmentFromLoginShell,
9
readPathFromLaunchctl,
10
resolveWindowsEnvironment,
11
setWindowsPath,
12
+ WindowsShellEnvironment,
13
} from "@t3tools/shared/shell";
14
import * as Duration from "effect/Duration";
15
import * as Effect from "effect/Effect";
@@ -217,6 +219,20 @@ export const refreshPathFromLoginShell = Effect.fn("refreshPathFromLoginShell")(
219
}
220
});
221
222
+// Installers write PATH to the registry, which the server's launch-time PATH never sees again.
223
+// Returns whether PATH gained a directory.
224
+export const refreshWindowsPath = Effect.fn("refreshWindowsPath")(function* () {
225
+ if ((yield* HostProcess.Platform) !== "win32") return false;
226
+ const env = yield* HostProcess.Environment;
227
+ const readEnvironment = yield* WindowsShellEnvironment;
228
+ const { PATH: registryPath } = yield* readEnvironment(["PATH"], { loadProfile: false });
229
+ const currentPath = env.PATH ?? env.Path ?? env.path;
230
+ const mergedPath = mergePathValues(currentPath, registryPath, "win32");
231
+ if (!mergedPath || mergedPath === currentPath) return false;
232
+ setWindowsPath(env, mergedPath);
233
+ return true;
234
+});
235
+
236
export const expandHomePath = Effect.fn(function* (input: string) {
237
const { join } = yield* Path.Path;
238
const home = yield* HostProcess.HomeDirectory;
apps/server/src/policy/ManagedPolicy.test.ts
+5
-1
@@ -193,7 +193,11 @@ it.layer(NodeServices.layer)("ManagedPolicy.load", (it) => {
193
]);
194
// The host variable that replaces Codex's launch arguments is ignored too.
195
const host = { PATH: "/usr/bin", T3CODE_CODEX_LAUNCH_ARGS: "-c mcp_servers.x.command=sh" };
196
- assert.deepEqual(providerHostEnvironment(policy.summary, host), { PATH: "/usr/bin" });
196
+ const managedHost = providerHostEnvironment(policy.summary, host);
197
+ assert.deepEqual(managedHost, { PATH: "/usr/bin" });
198
+ // A PATH refresh after launch reaches drivers that hold the managed copy.
199
+ host.PATH = "/opt/new/bin:/usr/bin";
200
+ assert.strictEqual(managedHost.PATH, "/opt/new/bin:/usr/bin");
201
assert.strictEqual(providerHostEnvironment(undefined, host), host);
202
}),
203
);
apps/server/src/policy/managedProviders.ts
+17
@@ -168,6 +168,23 @@ export const providerHostEnvironment = (
168
delete next[name];
169
}
170
}
171
+ // Drivers keep this object, so PATH reads through to the host for a refresh after launch to reach them.
172
+ const pathKeys = Object.keys(next).filter((name) => name.toUpperCase() === "PATH");
173
+ if (pathKeys.length > 0) {
174
+ for (const name of pathKeys) delete next[name];
175
+ Object.defineProperty(next, "PATH", {
176
+ enumerable: true,
177
+ configurable: true,
178
+ get: () => environment.PATH ?? environment.Path ?? environment.path,
179
+ set: (value) =>
180
+ Object.defineProperty(next, "PATH", {
181
+ value,
182
+ enumerable: true,
183
+ writable: true,
184
+ configurable: true,
185
+ }),
186
+ });
187
+ }
188
return next;
189
};
190
apps/server/src/provider/ProviderInstanceRegistry.ts
+10
@@ -637,6 +637,15 @@ export const makeProviderInstanceRegistry = Effect.fn(
637
(rawInstanceId) => instanceId === undefined || rawInstanceId === instanceId,
638
undefined,
639
).pipe(Effect.asVoid);
640
+ const rebuild: ProviderInstanceRegistryMutator.ProviderInstanceRegistryMutatorShape["rebuild"] = (
641
+ instanceIds,
642
+ ) =>
643
+ semaphore.withPermits(1)(
644
+ Ref.get(configMapRef).pipe(
645
+ Effect.flatMap((configMap) => reconcileWithR(configMap, new Set(instanceIds))),
646
+ Effect.provideContext(driverContext),
647
+ ),
648
+ );
649
const applySecret: ProviderInstanceRegistryMutator.ProviderInstanceRegistryMutatorShape["applySecret"] =
650
(reference, value) =>
651
reloadWhere(
@@ -697,6 +706,7 @@ export const makeProviderInstanceRegistry = Effect.fn(
706
const mutator: ProviderInstanceRegistryMutator.ProviderInstanceRegistryMutatorShape = {
707
reconcile,
708
reloadSecrets,
709
+ rebuild,
710
applySecret,
711
};
712
apps/server/src/provider/ProviderInstanceRegistryHydration.test.ts
+1
@@ -165,6 +165,7 @@ describe("layerSettingsWatcher", () => {
165
const mutator = Layer.succeed(ProviderInstanceRegistryMutator, {
166
reconcile: () => Queue.offer(reconciled, undefined),
167
reloadSecrets: () => Effect.sync(() => void reloads++),
168
+ rebuild: () => Effect.void,
169
applySecret: () => Effect.succeed([]),
170
});
171
yield* Layer.build(
apps/server/src/provider/ProviderInstanceRegistryMutator.ts
+2
@@ -11,6 +11,8 @@ export interface ProviderInstanceRegistryMutatorShape {
11
readonly reconcile: (configMap: ProviderInstanceConfigMap) => Effect.Effect<void>;
12
/** Re-reads the secrets of every instance, or one, and rebuilds those whose secrets changed. */
13
readonly reloadSecrets: (instanceId?: ProviderInstanceId) => Effect.Effect<void>;
14
+ /** Rebuilds these live instances from their current configuration and the host environment. */
15
+ readonly rebuild: (instanceIds: ReadonlyArray<ProviderInstanceId>) => Effect.Effect<void>;
16
/**
17
* Rebuilds the instances that read `reference` with `value`, keeping the other secrets a live
18
* instance holds, and returns them. A parked instance reads its other secrets from the resolver.
apps/server/src/provider/ProviderRegistry.test.ts
+87
@@ -43,6 +43,7 @@ import {
43
import { HttpClient, HttpClientResponse } from "effect/http";
44
import { ChildProcessSpawner } from "effect/process";
45
import * as HostProcess from "@t3tools/shared/HostProcess";
46
+import { WindowsShellEnvironment } from "@t3tools/shared/shell";
47
import { deepMerge } from "@t3tools/shared/Struct";
48
import { createModelCapabilities } from "@t3tools/shared/model";
49
import { applyServerSettingsPatch } from "@t3tools/shared/serverSettings";
@@ -2425,6 +2426,92 @@ it.layer(
2426
}),
2427
);
2428
2429
+ it.effect(
2430
+ "rebuilds only instances missing their CLI when a refresh finds a new Windows PATH",
2431
+ () => {
2432
+ const env: NodeJS.ProcessEnv = { PATH: "C:\\Windows" };
2433
+ return Effect.gen(function* () {
2434
+ const driver = ProviderDriverKind.make("codex");
2435
+ const makeInstance = (id: string, installed: boolean): ProviderInstance => {
2436
+ const instanceId = ProviderInstanceId.make(id);
2437
+ const provider = {
2438
+ instanceId,
2439
+ driver,
2440
+ status: installed ? "ready" : "error",
2441
+ enabled: true,
2442
+ installed,
2443
+ auth: { status: "unknown" },
2444
+ checkedAt: "1970-01-01T00:00:00.000Z",
2445
+ version: null,
2446
+ models: [],
2447
+ slashCommands: [],
2448
+ skills: [],
2449
+ } as const satisfies ServerProvider;
2450
+ return {
2451
+ instanceId,
2452
+ driverKind: driver,
2453
+ continuationIdentity: { driverKind: driver, continuationKey: `codex:${id}` },
2454
+ displayName: undefined,
2455
+ enabled: true,
2456
+ snapshot: {
2457
+ resolveMaintenance: () =>
2458
+ Effect.succeed(
2459
+ makeManualOnlyProviderMaintenanceCapabilities({
2460
+ provider: driver,
2461
+ packageName: null,
2462
+ }),
2463
+ ),
2464
+ getSnapshot: Effect.succeed(provider),
2465
+ refresh: Effect.succeed(provider),
2466
+ streamChanges: Stream.empty,
2467
+ applyUsageLimits: () => Effect.void,
2468
+ },
2469
+ orchestrationAdapter: {} as ProviderInstance["orchestrationAdapter"],
2470
+ textGeneration: {} as ProviderInstance["textGeneration"],
2471
+ };
2472
+ };
2473
+ const instances = [makeInstance("present", true), makeInstance("missing", false)];
2474
+ const rebuilt: Array<ReadonlyArray<ProviderInstanceId>> = [];
2475
+ const changes = yield* PubSub.unbounded<void>();
2476
+ const registry = yield* ProviderRegistry.ProviderRegistry.pipe(
2477
+ Effect.provide(
2478
+ ProviderRegistry.layer.pipe(
2479
+ Layer.provide(
2480
+ Layer.mock(ProviderInstanceRegistryMutator.ProviderInstanceRegistryMutator)({
2481
+ rebuild: (ids) => Effect.sync(() => void rebuilt.push(ids)),
2482
+ }),
2483
+ ),
2484
+ Layer.provideMerge(
2485
+ Layer.succeed(ProviderInstanceRegistry.ProviderInstanceRegistry, {
2486
+ getInstance: (id) => Effect.succeed(instances.find((i) => i.instanceId === id)),
2487
+ listInstances: Effect.succeed(instances),
2488
+ listUnavailable: Effect.succeed([]),
2489
+ streamChanges: Stream.fromPubSub(changes),
2490
+ subscribeChanges: PubSub.subscribe(changes),
2491
+ }),
2492
+ ),
2493
+ Layer.provideMerge(
2494
+ ServerConfig.layerTest(process.cwd(), { prefix: "t3-provider-registry-path-" }),
2495
+ ),
2496
+ Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
2497
+ ),
2498
+ ),
2499
+ );
2500
+
2501
+ yield* registry.refresh();
2502
+
2503
+ assert.strictEqual(env.PATH, "C:\\Windows;C:\\Tools");
2504
+ assert.deepStrictEqual(rebuilt, [[ProviderInstanceId.make("missing")]]);
2505
+ }).pipe(
2506
+ Effect.provideService(HostProcess.Platform, "win32"),
2507
+ Effect.provideService(HostProcess.Environment, env),
2508
+ Effect.provideService(WindowsShellEnvironment, () =>
2509
+ Effect.succeed({ PATH: "C:\\Windows;C:\\Tools" }),
2510
+ ),
2511
+ );
2512
+ },
2513
+ );
2514
+
2515
it.effect("rescans a requested cwd whose snapshot is still current", () =>
2516
Effect.gen(function* () {
2517
const h = yield* makeWorkspaceRescanHarness;
apps/server/src/provider/ProviderRegistry.ts
+24
-5
@@ -11,6 +11,7 @@ import {
11
import * as Cause from "effect/Cause";
12
import * as Context from "effect/Context";
13
import * as DateTime from "effect/DateTime";
14
+import * as Duration from "effect/Duration";
15
import * as Deferred from "effect/Deferred";
16
import * as Effect from "effect/Effect";
17
import * as Equal from "effect/Equal";
@@ -30,6 +31,7 @@ import * as ProviderLatestVersions from "@t3tools/provider-core/server/ProviderL
31
import * as ModelManifest from "./ModelManifest.ts";
32
import { applyProviderCompatibility } from "./providerCompatibility.ts";
33
import * as ServerConfig from "../config.ts";
34
+import { refreshWindowsPath } from "../os-jank.ts";
35
import * as ProviderInstanceRegistry from "./ProviderInstanceRegistry.ts";
36
import * as ProviderInstanceRegistryMutator from "./ProviderInstanceRegistryMutator.ts";
37
import {
@@ -699,6 +701,25 @@ export const layer = Layer.effect(
701
});
702
703
type RefreshAllCompletion = Deferred.Deferred<ReadonlyArray<ServerProvider>>;
704
+ // A refresh is how a user asks T3 to see a CLI installed since launch; a burst shares one probe.
705
+ // Drivers copy the environment when built, so instances still missing their CLI are rebuilt
706
+ // on the new PATH. They cannot have live sessions, and installed ones keep theirs.
707
+ const refreshHostPath = yield* refreshWindowsPath().pipe(
708
+ Effect.flatMap((changed) =>
709
+ changed
710
+ ? Ref.get(providersRef).pipe(
711
+ Effect.flatMap((providers) =>
712
+ instanceRegistryMutator.rebuild(
713
+ providers
714
+ .filter((provider) => provider.enabled && !provider.installed)
715
+ .map((provider) => provider.instanceId),
716
+ ),
717
+ ),
718
+ )
719
+ : Effect.void,
720
+ ),
721
+ Effect.cachedWithTTL(Duration.seconds(10)),
722
+ );
723
const refreshAllInFlightRef = yield* Ref.make<Option.Option<RefreshAllCompletion>>(
724
Option.none(),
725
);
@@ -707,6 +728,7 @@ export const layer = Layer.effect(
728
const probedManifestUpdatedAt = yield* Ref.make(initialManifest.updatedAt);
729
730
const refreshAll = Effect.fn("refreshAll")(function* () {
731
+ yield* refreshHostPath;
732
const claimed = yield* Ref.modify(
733
refreshAllInFlightRef,
734
(
@@ -754,16 +776,13 @@ export const layer = Layer.effect(
776
if (provider === undefined) {
777
return yield* refreshAll();
778
}
757
- const instance = (yield* Ref.get(liveSubsRef)).get(defaultInstanceIdForDriver(provider));
758
- if (!instance) {
759
- return yield* Ref.get(providersRef);
760
- }
761
- return yield* refreshOneSource(instance);
779
+ return yield* refreshInstance(defaultInstanceIdForDriver(provider));
780
});
781
782
const refreshInstance = Effect.fn("refreshInstance")(function* (
783
instanceId: ProviderInstanceId,
784
) {
785
+ yield* refreshHostPath;
786
yield* syncLiveSourcesAndContinue;
787
const instance = (yield* Ref.get(liveSubsRef)).get(instanceId);
788
if (!instance) {
packages/shared/src/shell.test.ts
+13
@@ -35,6 +35,7 @@ import {
35
resolveSpawnCommand,
36
resolveWindowsEnvironment,
37
runsGitWithoutConsole,
38
+ windowsEnvironmentValueCommand,
39
SpawnExecutableResolution,
40
WindowsShellEnvironment,
41
withPathDirectoryListings,
@@ -257,6 +258,18 @@ describe("mergePathEntries", () => {
258
});
259
});
260
261
+describe("windowsEnvironmentValueCommand", () => {
262
+ it("joins PATH as Process, then Machine, then User so prepends win and User installs still appear", () => {
263
+ const command = windowsEnvironmentValueCommand("PATH");
264
+ const processAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','Process')");
265
+ const machineAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','Machine')");
266
+ const userAt = command.indexOf("[Environment]::GetEnvironmentVariable('PATH','User')");
267
+ expect(processAt).toBeGreaterThan(-1);
268
+ expect(processAt).toBeLessThan(machineAt);
269
+ expect(machineAt).toBeLessThan(userAt);
270
+ });
271
+});
272
+
273
describe("readEnvironmentFromWindowsShell", () => {
274
effectIt.effect("yields while the native shell probe is pending", () =>
275
Effect.gen(function* () {
packages/shared/src/shell.ts
+15
-1
@@ -278,6 +278,20 @@ export function buildEnvironmentCaptureCommand(
278
: command;
279
}
280
281
+// Process first so profile prepends win; User and Machine add dirs missing from the launch snapshot.
282
+export function windowsEnvironmentValueCommand(name: string): string {
283
+ if (name === "PATH") {
284
+ return (
285
+ "$value = (@(" +
286
+ "[Environment]::GetEnvironmentVariable('PATH','Process')," +
287
+ "[Environment]::GetEnvironmentVariable('PATH','Machine')," +
288
+ "[Environment]::GetEnvironmentVariable('PATH','User')" +
289
+ ") | Where-Object { $_ }) -join ';'"
290
+ );
291
+ }
292
+ return `$value = [Environment]::GetEnvironmentVariable('${name}')`;
293
+}
294
+
295
function buildWindowsEnvironmentCaptureCommand(names: ReadonlyArray<string>): string {
296
return [
297
"$ErrorActionPreference = 'Stop'",
@@ -288,7 +302,7 @@ function buildWindowsEnvironmentCaptureCommand(names: ReadonlyArray<string>): st
302
303
return [
304
`Write-Output '${envCaptureStart(name)}'`,
291
- `$value = [Environment]::GetEnvironmentVariable('${name}')`,
305
+ windowsEnvironmentValueCommand(name),
306
"if ($null -ne $value -and $value.Length -gt 0) { Write-Output $value }",
307
`Write-Output '${envCaptureEnd(name)}'`,
308
];