diff --git a/packages/coding-agent/src/exec/non-interactive-env.ts b/packages/coding-agent/src/exec/non-interactive-env.ts index ddc9bd833..c1b58ba91 100644 --- a/packages/coding-agent/src/exec/non-interactive-env.ts +++ b/packages/coding-agent/src/exec/non-interactive-env.ts @@ -74,11 +74,22 @@ function hasEnvValue( return false; } +function hasLocaleEnvValue(env: Record | undefined, platform: NodeJS.Platform): boolean { + if (!env) return false; + for (const [key, value] of Object.entries(env)) { + if (value === undefined) continue; + const normalizedKey = platform === "win32" ? key.toUpperCase() : key; + if (normalizedKey === "LANG" || normalizedKey.startsWith("LC_")) return true; + } + return false; +} + function hasEnvGroupValue( env: Record | undefined, group: ReadonlyArray, platform: NodeJS.Platform, ): boolean { + if (group.some(([key]) => key === "LC_ALL") && hasLocaleEnvValue(env, platform)) return true; for (const [key] of group) { if (hasEnvValue(env, key, platform)) return true; } diff --git a/packages/coding-agent/test/non-interactive-env.test.ts b/packages/coding-agent/test/non-interactive-env.test.ts index 831d8f454..57c4ca878 100644 --- a/packages/coding-agent/test/non-interactive-env.test.ts +++ b/packages/coding-agent/test/non-interactive-env.test.ts @@ -29,6 +29,13 @@ describe("buildNonInteractiveEnv", () => { expect(env.LC_ALL).toBe("en_US.UTF-8"); }); + it("preserves inherited Windows LC category locales as user-owned", () => { + const env = buildNonInteractiveEnv(undefined, { LC_CTYPE: "en_US.UTF-8" }, "win32"); + + expect(env.LANG).toBeUndefined(); + expect(env.LC_ALL).toBeUndefined(); + }); + it("does not force UTF-8 encoding defaults on non-Windows platforms", () => { const env = buildNonInteractiveEnv(undefined, {}, "linux");