@devries-cameron20 / t3code-1 / commits / ba4d01cf7f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(shared): login-shell environment probe ignores DEBUG trap output (#32646)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 21:04 UTC ba4d01cf7f78b29f2fb3a5be019e7ea8562ee692
2 files changed +42 -1
packages/shared/src/shell.test.ts
+33
@@ -118,6 +118,39 @@ describe("readEnvironmentFromLoginShell", () => {
118 },
119 );
120
121 + it.runIf(NodeFS.existsSync("/bin/bash"))(
122 + "ignores probe markers a bash DEBUG trap echoes into the terminal title",
123 + () => {
124 + const home = NodeFS.mkdtempSync(NodePath.join(NodeOS.tmpdir(), "t3-bash-env-"));
125 + try {
126 + const shellPath = `${NodePath.join(home, "bin")}:/usr/bin:/bin`;
127 + const bashEnv = NodePath.join(home, "env.bash");
128 + NodeFS.writeFileSync(
129 + bashEnv,
130 + [
131 + `export PATH=${JSON.stringify(shellPath)}`,
132 + `trap 'echo -ne "\\033]0;\${BASH_COMMAND}\\007"' DEBUG`,
133 + ].join("\n"),
134 + );
135 +
136 + expect(
137 + readEnvironmentFromLoginShell(
138 + "/bin/bash",
139 + ["XDG_DATA_HOME", "PATH"],
140 + // Non-interactive bash reads only BASH_ENV, not the host's /etc startup files that -il runs.
141 + (file, [, command = ""], options) =>
142 + NodeChildProcess.execFileSync(file, ["-c", command], {
143 + ...options,
144 + env: { HOME: home, PATH: "/usr/bin:/bin", TERM: "dumb", BASH_ENV: bashEnv },
145 + }),
146 + ),
147 + ).toEqual({ PATH: shellPath });
148 + } finally {
149 + NodeFS.rmSync(home, { recursive: true, force: true });
150 + }
151 + },
152 + );
153 +
154 it("extracts multiple environment variables from a login shell command", () => {
155 const execFile = vi.fn<
156 (
packages/shared/src/shell.ts
+9 -1
@@ -208,6 +208,8 @@ function envCaptureEnd(name: string): string {
208 return `__T3CODE_ENV_${name}_END__`;
209 }
210
211 +const DEBUG_TRAP_SHELLS = new Set(["bash", "zsh", "sh", "ksh", "ksh93"]);
212 +
213 export function buildEnvironmentCaptureCommand(
214 shell: string,
215 names: ReadonlyArray<string>,
@@ -215,7 +217,7 @@ export function buildEnvironmentCaptureCommand(
217 const executableName = NodePath.basename(shell).toLowerCase();
218 const isNushell = executableName.startsWith("nu");
219
218 - return names
220 + const capture = names
221 .map((name) => {
222 if (!SHELL_ENV_NAME_PATTERN.test(name)) {
223 throw new Error(`Unsupported environment variable name: ${name}`);
@@ -249,6 +251,12 @@ export function buildEnvironmentCaptureCommand(
251 ].join("; ");
252 })
253 .join("; ");
254 +
255 + // A DEBUG trap that echoes each command (e.g. into the terminal title) would print the markers.
256 + // OpenBSD ksh (also its /bin/sh) exits on `trap - DEBUG`, so try it in a subshell first.
257 + return DEBUG_TRAP_SHELLS.has(executableName)
258 + ? `(trap - DEBUG) 2>/dev/null && trap - DEBUG; ${capture}`
259 + : capture;
260 }
261
262 function buildWindowsEnvironmentCaptureCommand(names: ReadonlyArray<string>): string {