I access my Mac both physically (sitting at the machine with Ghostty) and remotely via SSH/mosh. What I wanted was simple:
- Start a session locally, pick it up later via SSH
- Start a session remotely, continue it when I'm at the machine
- No manual "attach" commands - just open terminal and be there
- Minimal UI overhead - I don't need tabs or panes right now
Essentially: one terminal session, accessible from anywhere, invisibly.
Added this to ~/.zshrc, near the top:
# =============================================================================
# ZELLIJ AUTO-ATTACH
# =============================================================================
# Automatically attach to (or create) a persistent zellij session
# This allows the same session to be accessed locally or via SSH
if [[ -z "$ZELLIJ" ]] && [[ -n "$PS1" ]]; then
exec zellij attach --create main
fiHow it works:
-z "$ZELLIJ"- only runs if not already inside zellij (prevents nesting)-n "$PS1"- only runs for interactive shells (won't breakscp,rsync, git over SSH, etc.)exec- replaces the shell process, so exiting zellij logs you out cleanlyattach --create main- attaches to session "main" if it exists, creates it otherwise
No SSH configuration needed. SSH just starts a login shell on the remote machine, which sources .zshrc, which runs the auto-attach.
Zellij's default layout shows a status bar. For a minimal setup, enabled the compact layout in ~/.config/zellij/config.kdl:
default_layout "compact"This removes the tab bar and shows only a minimal status line.
The zellij config is managed via GNU stow from ~/.config/dotfiles:
~/.config/dotfiles/zellij/.config/zellij/config.kdl
Adopted the existing config with:
cd ~/.config/dotfiles && just adopt zellijThis moved the existing config into the dotfiles repo and created a symlink back.
- Open Ghostty locally: automatically in the "main" zellij session
- SSH in from anywhere: same session, same state
- Session persists across disconnects
- No commands to remember, no UI clutter