# Arch Linux Forum Thread — The $TMUX Guard Pattern ## Metadata | Field | Value | |---|---| | Institute | Molodetz Institute — Research & Retrieval Division | | Subject | shell-multiplexer-auto-attach | | Document type | Source Dossier | | Tier | 1 | | Source title | bbs.archlinux.org forum thread (tmux auto-attach) | | Source URL | https://bbs.archlinux.org/viewtopic.php?id=144544 | | Source publisher / author | Arch Linux Forums (community) | | Source type | forum thread | | Source date (published) | Unknown — not stated | | Date researched | 2026-10-09 | | Researched by | tai (agent), model: Claude Sonnet 5, on behalf of retoor | | Research method | web search synthesis | | Confidence | Medium | | Status | Active | ## Summary Establishes the core, near-universal guard for auto-attaching tmux from a shell rc file: `[[ -z "$TMUX" ]]`, since tmux itself sets the `$TMUX` environment variable inside any pane it creates. A forum participant confirms a simple `if [[ -z "$TMUX" ]]; then tmux attach; fi` block worked for them in practice. ## Key findings - `$TMUX` is tmux's own self-identifying environment variable, set automatically inside every pane — checking for its absence is the standard way to avoid launching tmux inside itself (nested sessions). - This is community-tested, working advice, not a theoretical suggestion. ## Pros / strengths - Simple, single-variable, directly tied to tmux's own behavior rather than an inferred heuristic — about as reliable a signal as exists for "am I already inside a tmux pane." ## Cons / limitations / caveats - Only detects nesting on the *same host* — per the query D SSH-nesting dossier in this subject, `$TMUX` does not survive an SSH hop, so this guard alone is insufficient once remote sessions are involved. ## Relevance to tai The mandatory first guard for the proposal's `.bashrc` hook: never attempt to auto-attach if `$TMUX` (or tai's own equivalent marker) is already set, to prevent runaway nested sessions — this is non-negotiable baseline safety, not an optional refinement. ## Changelog | Date | Change | |---|---| | 2026-10-09 | Initial dossier created. |