Skip to content

Commit 57093a4

Browse files
UzEEclaude
andcommitted
fix(server): terminals no longer inherit the launching tmux session
When the server runs inside tmux, screen, or Zellij, integrated terminals inherited TMUX, TMUX_PANE, STY, WINDOW, and ZELLIJ* from it. Tools then acted on the pane that launched the server, e.g. clipboard helpers wrote to that tmux buffer instead of the T3 Code terminal. Drop these from the inherited env; explicit terminal env can still set them. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 2d31acb commit 57093a4

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

‎apps/server/src/terminal/Manager.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,33 @@ it.layer(
20872087
}),
20882088
);
20892089

2090+
it.effect("does not inherit the multiplexer session of the server's launching pane", () =>
2091+
Effect.gen(function* () {
2092+
const multiplexerEnv = {
2093+
TMUX: "/tmp/tmux-1000/default,1234,0",
2094+
TMUX_PANE: "%3",
2095+
STY: "1234.pts-0.host",
2096+
WINDOW: "0",
2097+
ZELLIJ: "0",
2098+
ZELLIJ_SESSION_NAME: "work",
2099+
ZELLIJ_PANE_ID: "2",
2100+
};
2101+
const { manager, ptyAdapter } = yield* createManager(5, {
2102+
env: { ...multiplexerEnv, ZELLIJ_CONFIG_DIR: "/home/user/.config/zellij" },
2103+
});
2104+
yield* manager.open(openInput());
2105+
yield* manager.open(openInput({ terminalId: "explicit", env: { TMUX_PANE: "%9" } }));
2106+
2107+
for (const key of Object.keys(multiplexerEnv)) {
2108+
expect(ptyAdapter.spawnInputs[0]?.env[key]).toBeUndefined();
2109+
}
2110+
// User multiplexer settings are not session state and still pass through.
2111+
expect(ptyAdapter.spawnInputs[0]?.env.ZELLIJ_CONFIG_DIR).toBe("/home/user/.config/zellij");
2112+
// The blocklist filters only the inherited env; explicit terminal env still wins.
2113+
expect(ptyAdapter.spawnInputs[1]?.env.TMUX_PANE).toBe("%9");
2114+
}),
2115+
);
2116+
20902117
it.effect("expands provider home paths passed to setup terminals", () =>
20912118
Effect.gen(function* () {
20922119
const { manager, ptyAdapter } = yield* createManager(5);

‎apps/server/src/terminal/Manager.ts‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,21 @@ const DEFAULT_PROCESS_KILL_GRACE_MS = 1_000;
105105
const DEFAULT_MAX_RETAINED_INACTIVE_SESSIONS = 128;
106106
const DEFAULT_OPEN_COLS = 120;
107107
const DEFAULT_OPEN_ROWS = 30;
108-
const TERMINAL_ENV_BLOCKLIST = new Set(["PORT", "ELECTRON_RENDERER_PORT", "ELECTRON_RUN_AS_NODE"]);
108+
// The tmux, GNU screen, and Zellij variables describe the multiplexer pane that
109+
// launched the server, not the PTY, so inheriting them makes multiplexer-aware
110+
// tools act on that unrelated pane.
111+
const TERMINAL_ENV_BLOCKLIST = new Set([
112+
"PORT",
113+
"ELECTRON_RENDERER_PORT",
114+
"ELECTRON_RUN_AS_NODE",
115+
"TMUX",
116+
"TMUX_PANE",
117+
"STY",
118+
"WINDOW",
119+
"ZELLIJ",
120+
"ZELLIJ_SESSION_NAME",
121+
"ZELLIJ_PANE_ID",
122+
]);
109123
const nowIso = Effect.map(DateTime.now, DateTime.formatIso);
110124
const MAX_TERMINAL_LABEL_LENGTH = 128;
111125
const decodeClaudeSettings = Schema.decodeUnknownOption(ClaudeSettings);

0 commit comments

Comments
 (0)