Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

tui: refuse to start a client inside an existing hn session (#452)

elvis5826142d5bc3
diff --git a/tui/src/main.rs b/tui/src/main.rs
index f11745162..b52dbc84c 100644
--- a/tui/src/main.rs
+++ b/tui/src/main.rs
@@ -314,6 +314,22 @@ async fn run(config: config::Config) -> io::Result<()> {
if !found { if !ipc::alive(f.socket.as_deref(), f.name.as_deref()) { eprintln!("can't find session: {t}") } std::process::exit(1) }
}
}
+ // Refuse to start a client from inside an existing hn client — as tmux
+ // refuses `tmux` from inside a tmux pane. Without this, `hn` (and `harness
+ // tui`, which wraps `hn`) inside a pane would open a whole TUI on top of
+ // itself, tail-eating the parent's screen until the process tree gives up.
+ // Detection matches ipc::chosen's own rule: $TMUX's socket path pointing at
+ // hn's socket directory means the parent process is a client of ours. Match
+ // tmux's exact wording so tmux-savvy users read the same escape hatch:
+ // `TMUX= hn` (or `unset TMUX; hn`) bypasses.
+ if std::env::var("TMUX").ok()
+ .and_then(|t| t.split(',').next().map(std::path::PathBuf::from))
+ .filter(|p| p.starts_with(ipc::dir()))
+ .is_some()
+ {
+ eprintln!("sessions should be nested with care, unset $TMUX to force");
+ std::process::exit(1);
+ }
if !io::IsTerminal::is_terminal(&io::stdout()) { eprintln!("open terminal failed: not a terminal"); std::process::exit(1) }
// A terminal that cannot clear its screen (dumb, or none named) is refused as tmux refuses it.
// (A name hn does not know is used anyway: it writes what every terminal since xterm reads.)