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, 08:00 UTC
fix(cli): t3 triage and prompts work from the desktop app's t3 on Windows (#20162)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 23:00 UTC
c0de6bd1b14b2d4c25a777589335ec19bde78f99
5 files changed
+120
-1
apps/desktop/src/app/DesktopCliShim.ts
+2
@@ -60,6 +60,8 @@ export const renderCliShim = (input: {
60
`set "T3CODE_CLI_PATH=${cmdText(input.shimPath)}"`,
61
`if not defined T3CODE_HOME set "T3CODE_HOME=${cmdText(input.t3Home)}"`,
62
'set "ELECTRON_RUN_AS_NODE=1"',
63
+ // Electron's Windows executable starts without stdin; this tells the CLI to reopen the console.
64
+ 'set "T3CODE_DESKTOP_CLI_LAUNCHER=1"',
65
// A goto, not a parenthesized block: "Program Files (x86)" would close the block early.
66
`if exist ${cmdWord(target.executable)} goto run`,
67
...restore,
apps/server/src/bin.ts
+4
@@ -18,6 +18,10 @@ if (
18
const { runAcpMcpCliFastPath } = await import("./mcp/AcpMcpStdioBridge.ts");
19
await runAcpMcpCliFastPath(command, process.argv.slice(3));
20
} else {
21
+ // Before anything reads stdin: the desktop app's Windows launcher starts
22
+ // the CLI without one. Never for the fast paths, whose stdin is a pipe.
23
+ const { attachConsoleStdin } = await import("./cli/consoleStdin.ts");
24
+ attachConsoleStdin();
25
const { runCli } = await import("./binCli.ts");
26
runCli();
27
}
apps/server/src/cli/consoleStdin.test.ts
new
+33
@@ -0,0 +1,33 @@
1
+import { describe, expect, it } from "vite-plus/test";
2
+
3
+import { needsConsoleStdin } from "./consoleStdin.ts";
4
+
5
+const launcher = {
6
+ platform: "win32" as const,
7
+ env: { T3CODE_DESKTOP_CLI_LAUNCHER: "1" },
8
+ stdinOpen: false,
9
+ stdoutIsConsole: true,
10
+};
11
+
12
+describe("needsConsoleStdin", () => {
13
+ it("reopens the console for the desktop launcher in a terminal without stdin", () => {
14
+ expect(needsConsoleStdin(launcher)).toBe(true);
15
+ });
16
+
17
+ it("leaves every other way of running the CLI alone", () => {
18
+ for (const other of [
19
+ // Input the user piped or redirected.
20
+ { ...launcher, stdinOpen: true },
21
+ // Output to a pipe or file: the desktop backend, scripts, CI.
22
+ { ...launcher, stdoutIsConsole: false },
23
+ // The desktop backend runs the same executable but is not the launcher.
24
+ { ...launcher, env: { ELECTRON_RUN_AS_NODE: "1", T3CODE_CLI_PATH: "C:\\t3.cmd" } },
25
+ // npm, the install scripts, and plain Node runs.
26
+ { ...launcher, env: {} },
27
+ { ...launcher, platform: "linux" as const },
28
+ { ...launcher, platform: "darwin" as const },
29
+ ]) {
30
+ expect(needsConsoleStdin(other)).toBe(false);
31
+ }
32
+ });
33
+});
apps/server/src/cli/consoleStdin.ts
new
+77
@@ -0,0 +1,77 @@
1
+// @effect-diagnostics nodeBuiltinImport:off - Runs before the Effect runtime starts, on raw file descriptors.
2
+import * as NodeFS from "node:fs";
3
+import * as NodeTty from "node:tty";
4
+
5
+import * as HostProcess from "@t3tools/shared/HostProcess";
6
+
7
+/**
8
+ * Whether this process is the desktop app's `t3.cmd` running the CLI in a
9
+ * terminal with no stdin. The launcher runs the app's executable with
10
+ * `ELECTRON_RUN_AS_NODE`, and Electron's Windows executable is a GUI program:
11
+ * on start it points stdout and stderr at the parent's console but leaves
12
+ * stdin unset, so prompts see no terminal and children such as the agent
13
+ * `t3 triage` starts inherit nothing to read from. Input the user piped or
14
+ * redirected is a valid descriptor and is left alone, as is any run whose
15
+ * output is not a console (the desktop backend, scripts).
16
+ */
17
+export function needsConsoleStdin(input: {
18
+ readonly platform: NodeJS.Platform;
19
+ readonly env: NodeJS.ProcessEnv;
20
+ readonly stdinOpen: boolean;
21
+ readonly stdoutIsConsole: boolean;
22
+}): boolean {
23
+ return (
24
+ input.platform === "win32" &&
25
+ // Set only by the launcher (DesktopCliShim), never for the desktop backend.
26
+ input.env.T3CODE_DESKTOP_CLI_LAUNCHER === "1" &&
27
+ !input.stdinOpen &&
28
+ input.stdoutIsConsole
29
+ );
30
+}
31
+
32
+const isOpen = (fd: number) => {
33
+ try {
34
+ NodeFS.fstatSync(fd);
35
+ return true;
36
+ } catch {
37
+ return false;
38
+ }
39
+};
40
+
41
+/**
42
+ * Reopens the console's input as `process.stdin` when {@link needsConsoleStdin}
43
+ * holds, and returns its descriptor so interactive children can be given the
44
+ * same console. Returns undefined, changing nothing, everywhere else.
45
+ * Call before anything reads `process.stdin`.
46
+ */
47
+export function attachConsoleStdin(): number | undefined {
48
+ const needed = needsConsoleStdin({
49
+ platform: HostProcess.Platform.defaultValue(),
50
+ env: process.env,
51
+ stdinOpen: isOpen(0),
52
+ stdoutIsConsole: NodeTty.isatty(1),
53
+ });
54
+ // The marker describes this process's own start; a server started here
55
+ // must not pass it on to the shells and `t3` runs it spawns.
56
+ delete process.env.T3CODE_DESKTOP_CLI_LAUNCHER;
57
+ if (!needed) return undefined;
58
+ let fd: number;
59
+ try {
60
+ fd = NodeFS.openSync("\\\\.\\CONIN$", "r+");
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ if (!NodeTty.isatty(fd)) {
65
+ NodeFS.closeSync(fd);
66
+ return undefined;
67
+ }
68
+ const stdin = new NodeTty.ReadStream(fd);
69
+ Object.defineProperty(process, "stdin", { value: stdin, configurable: true, enumerable: true });
70
+ consoleStdinFd = fd;
71
+ return fd;
72
+}
73
+
74
+let consoleStdinFd: number | undefined;
75
+
76
+/** The stdin to hand an interactive child: the reopened console, or the inherited one. */
77
+export const interactiveStdin = (): number | "inherit" => consoleStdinFd ?? "inherit";
apps/server/src/cli/triage.ts
+4
-1
@@ -21,6 +21,7 @@ import * as ServerConfig from "../config.ts";
21
import { resolveBaseDir } from "../os-jank.ts";
22
import { isProcessAlive, readPersistedServerRuntimeState } from "../serverRuntimeState.ts";
23
import { baseDirFlag } from "./config.ts";
24
+import { interactiveStdin } from "./consoleStdin.ts";
25
import { resolveCliCommand } from "./invocation.ts";
26
import {
27
buildTriageContext,
@@ -118,7 +119,9 @@ const runInteractiveSession = (input: {
119
Effect.callback<number, TriageAgentSpawnError>((resume) => {
120
const child = NodeChildProcess.spawn(input.command, [...input.args], {
121
cwd: input.cwd,
121
- stdio: "inherit",
122
+ // The agent reads the user's terminal; under the desktop app's Windows
123
+ // launcher that is the reopened console, not the (missing) inherited stdin.
124
+ stdio: [interactiveStdin(), "inherit", "inherit"],
125
shell: input.shell,
126
});
127
child.once("error", (cause) =>