zellij: Unable to attach to sessions over SSH

2. Issues with the Zellij UI / behavior / crash

Issue description

Currently Zellij session discovery need $XDG_RUNTIME_DIR, which is set by systemd, and may not be set when connecting over SSH https://github.com/zellij-org/zellij/discussions/3700

Minimal reproduction

  1. Open local session, run some commands
  2. Connect from remote machine over SSH
  3. Run zellij attach to local session

See no content from previous commands in attached tab.

Other relevant information

About this issue

Commits related to this issue

Most upvoted comments

Just wanted to bring up that XDG_RUNTIME_DIR isn’t guaranteed to persist if user logs out, according to the specification iirc the sticky bit that Zellij uses to “save” the socket from getting deleted actually only protects it from optional wipe that can be set to happen every 6 hours. Tmux doesn’t use XDG_RUNTIME_DIR for this and unless the intended behaviour of Zellij is to create a dangling unreachable session if user only logs in over ssh, starts Zellij session, disconnects from the session and then from ssh, I feel like the socked should be moved to a location that doesn’t potentially get wiped in those situations.

I’m still questioning whether $XDG_RUNTIME_DIR is used at all. This code doesn’t seem to use it:

Yeah, I think this is it.

If we let ⭐️ mean /var/folders/0j/2q1m_86950q5gjl4b1mt62f40000gn/T in my case, then:

How mktemp on commandline $TMPDIR on commandline Path used by zellij
macOS in Terminal.app ⭐️ ⭐️ ⭐️
macOS over SSH ⭐️ ⭐️ ⭐️
macOS in iTerm.app ⭐️ (empty) /tmp/

I can confirm that a connection over SSH has no issue connecting to the same sessions as a shell in Terminal.app. So the issues appear to be:

  • zellij is not actually using $XDG_RUNTIME_DIR at all.
  • The computed temporary dir is different in iTerm.app, presumably because $TMPDIR is not set.

Unfortunately:

  • Despite what the Rust docs suggest, I’m finding that setting set -x TMPDIR (dirname (dirname (mktemp))) does not fix the issue in iTerm[^1], even if I killall zellij to reset memory state.
  • If I send a PR for $XDG_RUNTIME_DIR that certainly doesn’t solve the problem for other iTerm users.

The only solutions that would work out of the box are:

  1. Hardcode /tmp/ as the temp dir root, at least on macOS. This is less safe.
  2. Implement macOS-specific logic. Since the mktemp command gets the correct path even when $TMPDIR is not set, this implies the “correct” temp dir should be possible to access in a minimally hacky way.

I would appreciate input from the maintainers about how to handle this in a PR.

[^1]: EDIT: Turns out set -x TMPDIR (dirname (mktemp)) does work.