The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 09:15 UTC
fix(shell): normalize Windows PATH keys in copied environments (#19965)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 15:57 UTC
d8798dd7e9ae0de05a8b152ccfaca8d7bf2a503d
6 files changed
+77
-4
apps/desktop/src/shell/DesktopShellEnvironment.test.ts
+17
@@ -486,6 +486,23 @@ describe("DesktopShellEnvironment", () => {
486
}),
487
);
488
489
+ it.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
490
+ Effect.gen(function* () {
491
+ const env: NodeJS.ProcessEnv = { Path: "C:\\Windows\\System32" };
492
+
493
+ yield* runShellEnvironment({
494
+ env,
495
+ platform: "win32",
496
+ handler: (command) =>
497
+ command._tag === "StandardCommand" && command.args.includes("-NoProfile")
498
+ ? envOutput({ PATH: "C:\\Shell\\Bin" })
499
+ : "",
500
+ });
501
+
502
+ assert.deepEqual(env, { PATH: "C:\\Shell\\Bin;C:\\Windows\\System32" });
503
+ }),
504
+ );
505
+
506
it.effect("prefers login-shell desktop session hints over inherited values on linux", () =>
507
Effect.gen(function* () {
508
const env: NodeJS.ProcessEnv = {
apps/desktop/src/shell/DesktopShellEnvironment.ts
+2
-2
@@ -1,4 +1,4 @@
1
-import { listLoginShellCandidates } from "@t3tools/shared/shell";
1
+import { listLoginShellCandidates, setWindowsPath } from "@t3tools/shared/shell";
2
import * as Context from "effect/Context";
3
import * as Duration from "effect/Duration";
4
import * as Effect from "effect/Effect";
@@ -386,7 +386,7 @@ const installWindowsEnvironment = Effect.fn("desktop.shellEnvironment.installWin
386
]);
387
388
if (Option.isSome(mergedPath)) {
389
- config.env.PATH = mergedPath.value;
389
+ setWindowsPath(config.env, mergedPath.value);
390
}
391
if (!config.env.FNM_DIR && profile.FNM_DIR) {
392
config.env.FNM_DIR = profile.FNM_DIR;
apps/server/src/os-jank.test.ts
+16
@@ -152,3 +152,19 @@ effectIt.effect("repairs Windows PATH even when the desktop marks it prepared",
152
assert.equal(env.PATH, "C:\\Tools;C:\\Windows");
153
}),
154
);
155
+
156
+effectIt.effect("replaces a Path-spelled Windows PATH instead of adding a second key", () =>
157
+ Effect.gen(function* () {
158
+ const env: NodeJS.ProcessEnv = { Path: "C:\\Windows" };
159
+
160
+ yield* fixPath().pipe(
161
+ Effect.provideService(HostProcess.Platform, "win32"),
162
+ Effect.provideService(HostProcess.Environment, env),
163
+ Effect.provideService(WindowsShellEnvironment, () => ({ PATH: "C:\\Tools" })),
164
+ Effect.provideService(CommandAvailability, () => Effect.succeed(true)),
165
+ Effect.provide(NodeServices.layer),
166
+ );
167
+
168
+ assert.deepEqual(env, { PATH: "C:\\Tools;C:\\Windows" });
169
+ }),
170
+);
apps/server/src/os-jank.ts
+5
-1
@@ -5,6 +5,7 @@ import {
5
readEnvironmentFromLoginShell,
6
readPathFromLaunchctl,
7
resolveWindowsEnvironment,
8
+ setWindowsPath,
9
} from "@t3tools/shared/shell";
10
import * as Effect from "effect/Effect";
11
import * as FileSystem from "effect/FileSystem";
@@ -71,7 +72,10 @@ export const fixPath = Effect.fn("fixPath")(function* (options?: {
72
),
73
);
74
for (const [key, value] of Object.entries(repairedEnvironment)) {
74
- if (value !== undefined) {
75
+ if (value === undefined) continue;
76
+ if (key === "PATH") {
77
+ setWindowsPath(env, value);
78
+ } else {
79
env[key] = value;
80
}
81
}
packages/shared/src/shell.test.ts
+23
@@ -879,6 +879,29 @@ effectIt.layer(NodeServices.layer)("resolveWindowsEnvironment", (it) => {
879
}),
880
);
881
882
+ it.effect(
883
+ "probes node with one PATH key when inherited environment records have mixed casing",
884
+ () =>
885
+ Effect.gen(function* () {
886
+ const probedEnvironments: Array<NodeJS.ProcessEnv | undefined> = [];
887
+
888
+ yield* withWindowsEnvironmentMocks(
889
+ resolveWindowsEnvironment({ Path: "C:\\Stale", PATH: "C:\\Windows\\System32" }),
890
+ () => ({ PATH: "C:\\Shell\\Bin" }),
891
+ (_command, options) =>
892
+ Effect.sync(() => {
893
+ probedEnvironments.push(options?.env);
894
+ return true;
895
+ }),
896
+ );
897
+
898
+ const pathEntries = Object.entries(probedEnvironments[0] ?? {}).filter(
899
+ ([key]) => key.toUpperCase() === "PATH",
900
+ );
901
+ expect(pathEntries).toEqual([["PATH", "C:\\Shell\\Bin;C:\\Windows\\System32"]]);
902
+ }),
903
+ );
904
+
905
it.effect("loads the PowerShell profile when baseline env cannot resolve node", () =>
906
Effect.gen(function* () {
907
const readEnvironment = vi.fn(
packages/shared/src/shell.ts
+14
-1
@@ -805,13 +805,26 @@ function readWindowsEnvironmentSafely(
805
}
806
}
807
808
+/** Keep one PATH spelling in copied Windows environment records. */
809
+export function setWindowsPath(env: NodeJS.ProcessEnv, value: string): void {
810
+ for (const key of Object.keys(env)) {
811
+ if (key.toUpperCase() === "PATH") {
812
+ delete env[key];
813
+ }
814
+ }
815
+ env.PATH = value;
816
+}
817
+
818
function mergeWindowsEnv(
819
currentEnv: NodeJS.ProcessEnv,
820
patch: Partial<Record<string, string>>,
821
): NodeJS.ProcessEnv {
822
const nextEnv: NodeJS.ProcessEnv = { ...currentEnv };
823
for (const [key, value] of Object.entries(patch)) {
814
- if (value !== undefined) {
824
+ if (value === undefined) continue;
825
+ if (key === "PATH") {
826
+ setWindowsPath(nextEnv, value);
827
+ } else {
828
nextEnv[key] = value;
829
}
830
}