@devries-cameron20 / t3code Mirror · read-only / commits / a625e0b531
Fork 0

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 21, 23:30 UTC

fix(terminal): identify T3 Code terminal sessions (#9954)

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>

Julius Marminge committed Nov 11, 2026 at 09:29 UTC a625e0b531e30ca1f9bd78c7123c2f2054f24982
2 files changed +55
apps/server/src/terminal/Manager.test.ts
+46
@@ -41,6 +41,7 @@ import * as ProjectSetupScriptRunner from "../project/ProjectSetupScriptRunner.t
41 import * as TerminalManager from "./Manager.ts";
42 import { terminalOutputStream } from "./OutputProtocol.ts";
43 import * as PtyAdapter from "@t3tools/shared/PtyAdapter";
44 +import packageJson from "../../package.json" with { type: "json" };
45
46 vi.mock("effect/SynchronizedRef", async (importOriginal) => {
47 const original = await importOriginal<typeof SynchronizedRef>();
@@ -1853,6 +1854,51 @@ it.layer(
1854 }),
1855 );
1856
1857 + it.effect.each([
1858 + {
1859 + platform: "linux",
1860 + parentEnv: { TERM_PROGRAM: "Apple_Terminal", TERM_PROGRAM_VERSION: "455" },
1861 + runtimeEnv: { TERM_PROGRAM: "", TERM_PROGRAM_VERSION: "custom-version" },
1862 + },
1863 + {
1864 + platform: "win32",
1865 + parentEnv: { term_program: "Apple_Terminal", Term_Program_Version: "455" },
1866 + runtimeEnv: { Term_Program: "", term_program_version: "custom-version" },
1867 + },
1868 + ] as const)(
1869 + "identifies as T3 Code unless the terminal env overrides it on $platform",
1870 + ({ platform, parentEnv, runtimeEnv }) =>
1871 + Effect.gen(function* () {
1872 + const originalEnv = { ...parentEnv };
1873 + const env = Object.freeze(parentEnv);
1874 + const { manager, ptyAdapter } = yield* createManager(5, { env }).pipe(
1875 + Effect.provide(layerWithHostPlatform(platform)),
1876 + );
1877 +
1878 + yield* manager.open(openInput());
1879 + yield* manager.open(openInput({ terminalId: "override", env: runtimeEnv }));
1880 +
1881 + expect(ptyAdapter.spawnInputs).toHaveLength(2);
1882 + for (const [index, expected] of [
1883 + { TERM_PROGRAM: "t3code", TERM_PROGRAM_VERSION: packageJson.version },
1884 + { TERM_PROGRAM: "", TERM_PROGRAM_VERSION: "custom-version" },
1885 + ].entries()) {
1886 + const spawnEnv = ptyAdapter.spawnInputs[index]!.env;
1887 + for (const [key, value] of Object.entries(expected)) {
1888 + expect
1889 + .soft(
1890 + Object.entries(spawnEnv)
1891 + .filter(([candidate]) => candidate.toUpperCase() === key)
1892 + .map(([, entryValue]) => entryValue),
1893 + `${index === 0 ? "default" : "override"} ${key}`,
1894 + )
1895 + .toEqual([value]);
1896 + }
1897 + }
1898 + expect(env).toEqual(originalEnv);
1899 + }),
1900 + );
1901 +
1902 it.effect("filters app runtime env variables from terminal sessions", () =>
1903 Effect.gen(function* () {
1904 const { manager, ptyAdapter } = yield* createManager(5, {
apps/server/src/terminal/Manager.ts
+9
@@ -62,6 +62,7 @@ import * as Scope from "effect/Scope";
62 import * as Stream from "effect/Stream";
63 import * as SynchronizedRef from "effect/SynchronizedRef";
64
65 +import packageJson from "../../package.json" with { type: "json" };
66 import * as ServerConfig from "../config.ts";
67 import { mergeProviderInstanceEnvironment } from "@t3tools/provider-core/server/instanceEnvironment";
68 import { resolveCodexHomeLayout } from "../provider/Drivers/CodexHomeLayout.ts";
@@ -1363,8 +1364,16 @@ function createTerminalSpawnEnv(
1364 for (const [key, value] of Object.entries(baseEnv)) {
1365 if (value === undefined) continue;
1366 if (shouldExcludeTerminalEnvKey(key)) continue;
1367 + if (platform === "win32") {
1368 + const normalizedKey = key.toUpperCase();
1369 + if (normalizedKey === "TERM_PROGRAM" || normalizedKey === "TERM_PROGRAM_VERSION") continue;
1370 + }
1371 spawnEnv[key] = value;
1372 }
1373 + // The server inherits its launcher's identity (e.g. Apple_Terminal); shells
1374 + // and tools inside the integrated terminal should see T3 Code instead.
1375 + spawnEnv.TERM_PROGRAM = "t3code";
1376 + spawnEnv.TERM_PROGRAM_VERSION = packageJson.version;
1377 if (runtimeEnv) {
1378 for (const [key, value] of Object.entries(runtimeEnv)) {
1379 const existingKey =