Preserve WT_SESSION across restarts #8823

Open
opened 2026-01-31 01:38:51 +00:00 by claunia · 0 comments
Owner

Originally created by @davidchisnall on GitHub (Jun 5, 2020).

The macOS terminal (and iTerm, I believe) provide an environment variable analogous to WT_SESSION that is preserved across application restarts. When the terminal restarts, it will recreate all of the windows and tabs in their original position and with the same working directory.

I use this feature to preserve ssh sessions across restarts. I use a shell function to wrap ssh. This function creates a file in a specific location whose name is the terminal session ID and whose contents is the connection string. It then starts a tmux session on the remote end whose session ID is the terminal session ID. In .bashrc, I check whether a file exists describing the current session and, if so, automatically reconnect.

When I install software updates on my Mac, the terminal is killed and all of my remote connections resume after the reboot. A Windows update was forcibly installed last night causing WT to exit and I lost all of my existing connections and spent 10 minutes this morning restoring the state for my working environment.

Originally created by @davidchisnall on GitHub (Jun 5, 2020). The macOS terminal (and iTerm, I believe) provide an environment variable analogous to `WT_SESSION` that is preserved across application restarts. When the terminal restarts, it will recreate all of the windows and tabs in their original position and with the same working directory. I use this feature to preserve ssh sessions across restarts. I use a shell function to wrap ssh. This function creates a file in a specific location whose name is the terminal session ID and whose contents is the connection string. It then starts a tmux session on the remote end whose session ID is the terminal session ID. In .bashrc, I check whether a file exists describing the current session and, if so, automatically reconnect. When I install software updates on my Mac, the terminal is killed and all of my remote connections resume after the reboot. A Windows update was forcibly installed last night causing WT to exit and I lost all of my existing connections and spent 10 minutes this morning restoring the state for my working environment.
claunia added the Issue-TaskNeeds-Tag-FixProduct-TerminalArea-UserInterface labels 2026-01-31 01:38:51 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8823