What this guide covers
When you finish, each project has a session with a fixed name, you see the same state from whichever device you connect with, and one command restores the layout after a restart. You need: Homebrew and basic terminal skills.
Steps
One named session per project
After
brew install tmux, create a session withtmux new -s <name>. Use the project name or its purpose as the name, for exampletmux new -s apiortmux new -s agent.tmux lslists all sessions, andtmux attach -t apireattaches to one. Do not crowd everything into one unnamed session: a remote machine runs for a long time, and a week from now you need to see at a glance what each session is doing.Four keys are enough for windows and panes
The default prefix key is Ctrl+B. According to the official tmux Getting Started guide: after the prefix,
ccreates a window,%splits left and right,"splits top and bottom, andddetaches from the session. A common layout is one window running the task with a pane beside it runningtail -fon the log, so both are in front of you when you come back.When the prefix key does not work in the remote desktop
When you connect from Windows or a phone, key combinations go through the remote access client first, and some may be intercepted by the local system or the client. First check whether the client has an option for sending shortcuts to the remote side turned on. If it is still awkward, change the prefix to an easier key in
~/.tmux.conf, for exampleset -g prefix C-a. On a phone with no Ctrl key, use the client's own virtual keyboard or function key bar.Add two lines so scrolling and history are good enough
Put
set -g mouse onin~/.tmux.confand you can scroll through history with the mouse wheel and click to select panes, which in a remote desktop is far easier than paging with keys. Addset -g history-limit <lines>to raise the number of history lines kept per pane. The config is read only when the tmux server starts. After changing it, press the prefix inside a session and type:source-file ~/.tmux.confto apply it.To take output with you, export it to a file
Dragging to select a large block of terminal text through a remote desktop is slow and easy to get wrong. Run
tmux capture-pane -p -S - > ~/pane.txtinside the session to write the entire history of the current pane to a file, then read it in an editor or sync it to your own storage. A more reliable approach is to redirect output to a log file when the task starts, and treat tmux history as a temporary view only.A restart clears every session; rebuild them with a script
tmux sessions live in memory, so they all disappear when the machine restarts. This is not a fault. Write your layout as a script and keep it in your repository, for example:
#!/bin/zsh tmux new -d -s api -c ~/code/api tmux new -d -s agent -c ~/code/agent tmux send-keys -t agent 'caffeinate -i ./run.sh' C-mRun it once after the machine has restarted and you have logged in to the desktop. When you need a restart, use the "Restart" option in the customer console or the Apple menu on the remote Mac. Do not shut the machine down yourself.
Attaching to the same session from several devices
Whether you connect to the remote desktop from a computer or a phone, you land on the same macOS desktop, and
tmux attachjoins the same session. There is no question of each device seeing something different. When two terminal windows are attached to the same session, each affects the other's display size. On the side where you only wanted a quick look, detach with the prefix anddwhen you are done.
FAQ
Will tasks in tmux stop when I disconnect the remote desktop?
No. Disconnecting only ends the remote access session; the remote system and tmux carry on. What does stop them is system sleep, a machine restart or the program exiting by itself. See keeping long tasks running.
Is there a way to bring the sessions back automatically after a restart?
You can hand the rebuild script above to a user-level job that starts at login. It still runs only after your account has logged in to the desktop, and automatic login needs an assessment by support first.
Is the built-in screen good enough?
It works, and the idea of detaching and reattaching is the same. tmux is more convenient when you need panes, named sessions and scripted layouts.
Related
- How to keep long tasks running on a remote Mac mini after you disconnect
- Does a long Claude Code task stop when my remote connection drops?
- How to keep a remote Mac mini awake during a task with caffeinate
- How to schedule and auto-start jobs with user-level LaunchAgents on a remote Mac mini
- How to check on a rented Mac mini from a phone or tablet with UU Remote
Pricing and availability: see the plans page · Help center (中文) · Refund policy (中文) · Telegram Contact support