diff --git a/src/session.ts b/src/session.ts index 1bb557e0..05ee5e08 100644 --- a/src/session.ts +++ b/src/session.ts @@ -29,7 +29,7 @@ */ import { EventEmitter } from 'node:events'; -import { execSync } from 'node:child_process'; +import { execSync, execFileSync } from 'node:child_process'; import { v4 as uuidv4 } from 'uuid'; import * as pty from 'node-pty'; import { @@ -946,11 +946,28 @@ export class Session extends EventEmitter { } // Attach to the mux session via PTY + // Query existing tmux window size so re-attach matches (avoids flicker from 120x40 default) + let ptyCols = 120; + let ptyRows = 40; + try { + const sizeStr = execFileSync( + 'tmux', + ['display', '-t', this._muxSession!.muxName, '-p', '#{window_width} #{window_height}'], + { timeout: 2000, encoding: 'utf8' } + ).trim(); + const [w, h] = sizeStr.split(' ').map(Number); + if (w > 0 && h > 0) { + ptyCols = w; + ptyRows = h; + } + } catch { + /* fall back to 120x40 */ + } try { this.ptyProcess = pty.spawn(mux.getAttachCommand(), mux.getAttachArgs(this._muxSession!.muxName), { name: 'xterm-256color', - cols: 120, - rows: 40, + cols: ptyCols, + rows: ptyRows, cwd: this.workingDir, env: buildMuxAttachEnv(), }); diff --git a/src/tmux-manager.ts b/src/tmux-manager.ts index 5d5b2fd7..bb3abe7f 100644 --- a/src/tmux-manager.ts +++ b/src/tmux-manager.ts @@ -556,7 +556,7 @@ export class TmuxManager extends EventEmitter implements TerminalMultiplexer { // (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`, { + execSync(`tmux new-session -ds "${muxName}" -c "${workingDir}"`, { cwd: workingDir, timeout: EXEC_TIMEOUT_MS, stdio: 'ignore',