Running inside tmux fails with "sessions should be nested with care, unset $TMUX to force" #1

Closed
opened 2026-03-18 09:59:55 +00:00 by earthspacon · 1 comment
earthspacon commented 2026-03-18 09:59:55 +00:00 (Migrated from github.com)

Description

Running superharness from within an existing tmux session (which is the default environment in many Linux setups, including Omarchy) always fails with:

sessions should be nested with care, unset $TMUX to force
Error: tmux attach failed

Root cause

In src/tmux/session.rs, the init function unconditionally calls tmux attach-session to present the session to the user. When $TMUX is already set (i.e. the user is inside a tmux session), tmux refuses to attach because it detects nesting and exits with a non-zero code, which triggers bail!("tmux attach failed").

Expected behaviour

superharness should work seamlessly whether launched from a bare terminal or from inside an existing tmux session. This is especially important for users whose default terminal environment is tmux (e.g. Omarchy, tmuxinator users, etc.).

Fix

When $TMUX is set, use tmux switch-client -t superharness instead of tmux attach-session -t superharness. switch-client moves the current tmux client to the target session without nesting, which is exactly what is needed here. Because switch-client returns immediately (unlike attach-session which blocks until detach), the session-cleanup code must be skipped in this branch so the session is not killed right after switching to it.

Workaround

TMUX= superharness
## Description Running `superharness` from within an existing tmux session (which is the default environment in many Linux setups, including Omarchy) always fails with: ``` sessions should be nested with care, unset $TMUX to force Error: tmux attach failed ``` ## Root cause In `src/tmux/session.rs`, the `init` function unconditionally calls `tmux attach-session` to present the session to the user. When `$TMUX` is already set (i.e. the user is inside a tmux session), tmux refuses to attach because it detects nesting and exits with a non-zero code, which triggers `bail!("tmux attach failed")`. ## Expected behaviour `superharness` should work seamlessly whether launched from a bare terminal or from inside an existing tmux session. This is especially important for users whose default terminal environment is tmux (e.g. Omarchy, tmuxinator users, etc.). ## Fix When `$TMUX` is set, use `tmux switch-client -t superharness` instead of `tmux attach-session -t superharness`. `switch-client` moves the current tmux client to the target session without nesting, which is exactly what is needed here. Because `switch-client` returns immediately (unlike `attach-session` which blocks until detach), the session-cleanup code must be skipped in this branch so the session is not killed right after switching to it. ## Workaround ```bash TMUX= superharness ```
backmeupplz commented 2026-03-23 13:38:00 +00:00 (Migrated from github.com)

This was fixed in commit 10f7ede (feat/tmux-attach). SuperHarness now detects $TMUX and uses switch-client instead of attach-session when already inside a tmux session. Thanks for reporting!

This was fixed in commit `10f7ede` (feat/tmux-attach). SuperHarness now detects `$TMUX` and uses `switch-client` instead of `attach-session` when already inside a tmux session. Thanks for reporting!
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
backmeupplz/superharness#1
No description provided.