Skip to content
Servey logoServey

How to keep a terminal session running after you disconnect

By Janesh Kapoor · · 7 min read

The build takes forty minutes. Your train leaves in ten. If the shell running that build lives inside the app you are about to close, the build dies with it - and this is the most common way remote work on a Mac goes wrong. The fix is older than most of the tools people reach for, and it is the thing Servey turns on by default. Here is what actually kills a session, what survives, and how to get persistence whether you use Servey or not.

Frequently asked questions

How do I keep a command running after I close the terminal?
Run it inside a tmux session. Type tmux new -s work before you start anything long, then press Ctrl-b followed by d to detach. The command keeps running on the machine because it is a child of tmux rather than a child of your connection, so closing the app or losing signal cannot send it a hangup signal. Come back later and type tmux attach -t work to rejoin it with the scrollback and any waiting prompt intact. Servey opens every terminal session this way by default, so there is nothing to remember.
Why does my SSH session die when I lose signal?
Because your shell is a child of the SSH connection. When the connection drops, the kernel sends SIGHUP down the process tree and the default response to that signal is to terminate, so your shell and everything it started stop. This is a deliberate design going back to modems physically hanging up. Using nohup or disown prevents the kill but also takes away your ability to see output or answer a prompt, which is why a terminal multiplexer is the better answer.
Is tmux or screen better?
tmux, for a new setup. Both do the same core job of keeping your shell alive independently of your connection, but tmux is actively maintained, has cleaner splitting and scripting, and is what almost every guide written in the last decade assumes. GNU screen is often already installed and is perfectly usable, so if it is what your fingers know there is no urgent reason to switch.
Can I rejoin the same session from a different device?
Yes. tmux allows several clients to attach to one session at the same time, so you can start something on an iPad and carry on from your Mac with the same output in front of you. This is what makes it possible to begin a job on a phone and finish it at a desk. Servey exposes this directly: a session started from the iPad can be opened on the Mac, on a second device, or in any terminal app using the attach command it gives you.
Does Servey lock my sessions into its own app?
No. Servey runs your sessions as ordinary tmux sessions on your own Mac and shows you the attach command for each one. Paste that into Terminal.app, iTerm, Ghostty or an SSH connection and you are in the same live session with Servey uninstalled. Nothing you start is stored in a format only Servey can open, so the persistence you get is yours rather than ours.

Servey puts your Mac in your pocket. Launching soon.