From 73d9469580f7feb858455e4e39147289d26dd455 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 26 Feb 2026 15:41:37 +0100 Subject: [PATCH] fix: unset $TMUX env for nested tmux session creation When running the dev server inside a tmux session, $TMUX is inherited and tmux refuses to create new sessions ("sessions should be nested with care, unset $TMUX to force"). Production (systemd) has a clean env so this only affects dev/test. Strip $TMUX from the execSync env when calling tmux new-session. Co-Authored-By: Claude Opus 4.6 --- src/tmux-manager.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/tmux-manager.ts b/src/tmux-manager.ts index 647919de..7b2627d9 100644 --- a/src/tmux-manager.ts +++ b/src/tmux-manager.ts @@ -154,7 +154,7 @@ function buildOpenCodeCommand(config?: OpenCodeConfig): string { if (config?.continueSession) { const safeId = /^[a-zA-Z0-9_-]+$/.test(config.continueSession) ? config.continueSession : undefined; if (safeId) parts.push('--session', safeId); - if (config.forkSession) parts.push('--fork'); + if (safeId && config.forkSession) parts.push('--fork'); } return parts.join(' '); @@ -405,9 +405,13 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer { // 1. Create session with default shell (starts tmux server, stays alive) // 2. Set remain-on-exit (server now exists, session won't vanish on exit) // 3. Replace shell with actual command via respawn-pane (no terminal echo) + // Unset $TMUX so nested sessions work when the dev server itself runs inside tmux. + // (Production uses systemd which has a clean env, but dev/test may be nested.) + const cleanEnv = { ...process.env }; + delete cleanEnv.TMUX; execSync( `tmux new-session -ds "${muxName}" -c "${workingDir}" -x 120 -y 40`, - { cwd: workingDir, timeout: EXEC_TIMEOUT_MS, stdio: 'ignore' } + { cwd: workingDir, timeout: EXEC_TIMEOUT_MS, stdio: 'ignore', env: cleanEnv } ); // Set remain-on-exit now that the server is running — must be before respawn-pane