Skip to content

omc kills tmux session on SSH disconnect instead of leaving it running #2197

@pgagarinov

Description

@pgagarinov

Problem

When omc is run via SSH and the terminal is closed (SSH disconnect, network drop, etc.), the tmux session created by omc is killed instead of persisting in the background.

Root cause

In src/cli/launch.ts, runClaudeOutsideTmux creates a detached tmux session and then attaches to it:

const tmuxArgs = [
  'new-session', '-d', '-s', sessionName, '-c', cwd, claudeCmd,
  ';', 'set-option', '-t', sessionName, 'mouse', 'on',
  ';', 'attach-session', '-t', sessionName,
];

try {
  execFileSync('tmux', tmuxArgs, { stdio: 'inherit' });
} catch {
  // tmux attach failed — kill the orphaned detached session
  try {
    execFileSync('tmux', ['kill-session', '-t', sessionName]);
  } catch { /* session may already be gone */ }
  runClaudeDirect(cwd, args);
}

When the SSH terminal closes:

  1. The tmux client (attach-session) dies
  2. execFileSync throws because the process was interrupted
  3. The catch block kills the tmux session assuming it was an orphaned failed launch
  4. Falls back to runClaudeDirect which also fails (no terminal)

The session is still valid and Claude is still running inside it — but omc kills it.

Expected behavior

The tmux session should persist after SSH disconnect, just like any normal tmux session. The user should be able to reconnect via tmux attach -t <session> and resume their Claude session.

Current workaround

Run tmux first, then run omc inside it. The inside-tmux path doesn't create or kill sessions.

Suggested fix

Distinguish between "attach failed because session creation failed" and "attach failed because client was disconnected." Options:

  1. Check if the session still exists before killing it: tmux has-session -t sessionName — if it exists, don't kill it
  2. Separate new-session -d and attach-session into two execFileSync calls — only kill on new-session failure
  3. Don't kill sessions at all in the catch block — let the user manage them via tmux ls / tmux kill-session

Metadata

Metadata

Assignees

No one assigned

    Labels

    agentsRelated to agent definitions

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions