-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
omc kills tmux session on SSH disconnect instead of leaving it running #2197
Description
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:
- The tmux client (attach-session) dies
execFileSyncthrows because the process was interrupted- The catch block kills the tmux session assuming it was an orphaned failed launch
- Falls back to
runClaudeDirectwhich 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:
- Check if the session still exists before killing it:
tmux has-session -t sessionName— if it exists, don't kill it - Separate
new-session -dandattach-sessioninto twoexecFileSynccalls — only kill onnew-sessionfailure - Don't kill sessions at all in the catch block — let the user manage them via
tmux ls/tmux kill-session