Remote panes
A machine running zterm serve hosts panes with no window. From a windowed
zterm on another machine you can open one of those panes in a tab, watch it,
type into it and scroll it. The program keeps running on the machine that
hosts it.
Both machines must be in the same mesh: the same Tailscale tailnet, and the same mesh secret.
Joining a mesh
zterm finds other machines through Tailscale, so Tailscale must be running on each one.
On the first machine, make a secret:
zterm net secret --new
It prints the secret on one line. On every other machine, run this, paste that line, and end the input (Ctrl-D on macOS and Linux, Ctrl-Z then Enter on Windows):
zterm net secret --set
--set reads the secret from its input, so it never lands in your shell
history. It says which mesh the machine is now in. To copy the secret from a
machine you can reach over ssh without pasting it, run this on the machine
that has it:
zterm net secret --show | ssh other-machine zterm net secret --set
zterm reads the secret when it starts, so restart zterm, and zterm serve, on
each machine after setting it.
zterm net status shows the mesh id, this machine's node, whether it is
listening, and each Tailscale peer with its state. Every machine in the mesh
shows the same mesh id. A peer reads in mesh when a zterm there answers with
the same secret.
Who can watch and type
Every machine holding the mesh secret can watch every pane on a zterm serve
host and type into it. It can also start new panes there and close them. There is no per-machine allow-list and no per-pane
prompt. The secret is the permission, so give it only to machines you would
give a shell on the host.
A windowed zterm does not share its panes, and it does not start or close panes for another machine. Its panes are listed on other machines, but opening one from elsewhere shows the pane as ended.
Keeping a host running
zterm serve --install-unit writes the file that starts zterm serve when the
machine boots and again whenever it exits: a systemd user unit on Linux and a
LaunchAgent on macOS. It prints where it wrote the file and the commands that
turn it on. It runs none of them.
On Linux it writes ~/.config/systemd/user/zterm-serve.service and prints:
systemctl --user daemon-reload
systemctl --user enable --now zterm-serve.service
loginctl enable-linger "$USER"
The last command keeps your user services running while you are logged out.
systemctl --user is-active zterm-serve.service prints active once it runs.
On macOS it writes ~/Library/LaunchAgents/dev.zestful.zterm-serve.plist and
prints one launchctl bootstrap gui/<uid> ... command that loads it.
zterm serve's log is in the journal on Linux:
journalctl --user -u zterm-serve.service
On macOS it is ~/Library/Logs/zterm/zterm-serve.log, or
zterm-serve-<name>.log for an instance. journald limits the journal's size
on Linux. Nothing rotates or limits the macOS file.
A LaunchAgent written by zterm 0.9.67 or earlier sends the log nowhere. To replace it, unload it, remove it, and write it again:
launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/dev.zestful.zterm-serve.plist
rm ~/Library/LaunchAgents/dev.zestful.zterm-serve.plist
zterm serve --install-unit
Then run the launchctl bootstrap command it prints. --install-unit does
not replace a file that differs from the one it would write, because that file
may hold your own edits.
Run with --instance <name>, it writes a unit named zterm-serve-<name>
that starts zterm --instance=<name> serve, so two instances on one machine
get two units. The named host that unit starts joins the mesh. Windows has no unit, and --install-unit says so.
zterm serve exits when its last pane closes, and the unit starts it again
with one new shell. Stopping or restarting the unit stops zterm serve and
leaves the panes running, and the next zterm serve takes them over.
A window and a host on one machine
zterm listens for other machines on TCP port 3439, on the machine's tailnet address, and the port cannot be changed. Only one zterm on a machine can hold it. That includes a zterm window, which listens too, though it shares none of its panes.
A zterm window leaves the port to a zterm serve on the same machine in the
same mesh. A window that started first gives the port up within ten seconds
of zterm serve starting, and its log says znet listener closed: a zterm serve on this machine hosts this mesh. When zterm serve exits, the
window takes the port back within five seconds. zterm net status names the zterm that holds the
port in its held by row.
Two windows, or two zterm serves, still race for the port: the first to
start holds it, and the other tries again every five seconds until it is free.
A zterm serve beside a window needs its own --instance, because both would
otherwise use the same control socket, and zterm serve exits when the socket
is taken.
Named instances stay off the mesh
A zterm started with --instance <name> or ZTERM_INSTANCE=<name>, window
or zterm serve, does not join the mesh. It lists, reads and starts no pane
on another machine, and no other machine sees its panes. It prints one line
saying so:
zterm serve: znet not started: instance probe stays off the mesh; ZTERM_MESH=on joins it
A named zterm serve that its unit starts joins the mesh. zterm sees that
the unit zterm serve --install-unit --instance <name> writes for that name
started it: launchd's job label on macOS, the systemd unit on Linux. A unit
written by zterm 0.9.68 or earlier works the same way and needs no change.
The same zterm --instance=<name> serve typed in a shell stays off, and so
does a named zterm started in one of that host's panes. To keep a named host
on the mesh, install its unit.
ZTERM_MESH=on joins any named zterm, for a one-off check. Setting
ZTERM_MESH_SECRET joins it too, to the mesh whose secret that file holds.
Do not set ZTERM_MESH=on for a host you keep running: every pane it opens
inherits the variable, so a named zterm started in one of them joins the
mesh as well. The zterm with no instance joins whenever the machine holds a
mesh secret, as before.
Opening a remote pane
zterm ls lists panes on other machines in the mesh beside your own, each
with a node field naming the machine:
# Panes on other machines: id, machine, title.
zterm ls | jq -r '.panes[] | select(.node) | [.pane_id, .node, .title] | @tsv'
Open one in a new tab by its pane_id:
zterm perform attach 01JZ8W0000000000000000000C
zterm refuses an id that no machine in the mesh lists, and opens no tab.
The command palette and the + menu offer the same thing. Under the
palette's Launch group, and at the end of the + menu, Remote Panes lists
every pane on another machine as Open remote, or for a pane's name, title or machine, finds the
same rows, including words a shortened row no longer shows. Panes you
already have open and panes that have ended are left out. With no pane on
another machine and no machine to start one on, there is no Remote Panes row.
A pane on another machine always shows a title bar, even alone in its tab.
It reads the machine's name, then the pane's title, such as
buildbox · build. With pane.title_bar = "never" it shows none.
Closing the tab stops watching. The pane and its program keep running on the host, and you can open it again later.
The panel's Overview lists remote shells beside yours, each with the program
running in it and the tab's ↔ mark, its machine (or its tab, when a tab here shows it), its folder
and how long it has been quiet. Clicking one goes to the tab that shows it;
one that no tab shows can't be opened from the panel yet.
Starting a pane on another machine
zterm perform spawn_remote starts a program in a new pane on a serve host:
zterm perform spawn_remote --node buildbox --name build --dir /home/me/src/app -- make test
--nodenames the machine by its label or its id, aszterm lsshows it innode. It is required.--namenames the new pane, and--diris the directory the program starts in, on that machine. Both are optional. Give--diras an absolute path: your shell expands~to your home on this machine before zterm sees it. A--dirthat is not a folder on that machine, or is not an absolute path there, is refused with the reason, and nothing opens. On a Windows host that includes a path with no drive, such as\src\app.--env NAME=VALUEsets a variable for the program, and may be repeated. A host running Windows refuses variables.- The command goes after
--, and is required.
The answer is {"result":"created","pane":{...}}, with the new pane's row as
zterm ls lists it. Open the pane in a tab with zterm perform attach and the
pane's pane_id.
Run from a program outside every zterm pane, spawn_remote asks you first,
as zterm perform new_tab does.
To start a shell on another machine from the menus, open the command palette's
Launch group, or the + menu, and go to Remote Panes. It has a New shell
on zterm serve that this machine is
connected to now. Choosing one starts that machine's login shell, the shell
its account names, in a new pane there, and opens the pane in a tab here.
Choosing the row is the go-ahead: zterm asks nothing more. If the machine
refuses, zterm writes the reason to its standard error, as it does when any
other launch from a menu fails. A machine running an older zterm gets no row.
To close a pane on another machine, give close_pane its id:
zterm perform close_pane --target 01JZ8W0000000000000000000C
zterm asks the machine that hosts the pane to close it, and answers ok. That
ends the program, as typing exit in its shell would.
This also removes an exited pane that zterm ls still lists. The viewer and
the host must both support closing an exit record. An older viewer may answer
not_found; an older host may report that it has no pane by that id.
Typing into a pane on another machine
zterm perform write takes the id of a pane another machine lists, and types
into it there. The pane does not need to be open in a tab:
zterm perform write --submit --target 01JZ8W0000000000000000000C 'make test'
--submit presses Enter once the pane shows the text, as it does for a pane
here. --when-idle waits until nobody has an unsent line in the pane and
nobody has typed into it for a moment, from a window on any machine in the
mesh. The machine that hosts the pane holds the write, since every keystroke
into the pane reaches it. A host running zterm 0.9.63 or older refuses
--when-idle; send the write without it there.
If the link drops while a write waits, zterm sends it again when the link
comes back, as long as zterm on that machine has not restarted, and the host
makes it once. An unsent line you left in the pane keeps holding the write for
15 seconds after the link drops, long enough for your window to reconnect.
When the write cannot be sent again, the error says which case it is:
not written means the host never got it, and may have been written means
it did, so look at the pane before you write again. spawn_remote,
close_pane and read_text aimed at another machine come back the same way:
a pane is opened or closed once, and a read is asked again.
Run from a program outside every zterm pane, a write to another machine's
pane asks you first, as spawn_remote does.
Reading a pane on another machine
zterm perform read_text takes the id of a pane another machine lists, and
answers with its screen as that machine reads it. The pane does not need to be
open in a tab, so a script that started a pane with spawn_remote can check
on it without opening a window:
zterm perform read_text --target 01JZ8W0000000000000000000C
The answer is {"result":"text","rows":[...]}, one string per row, as it is
for a pane here. A machine running an older zterm cannot answer it, and the
request is refused with a message saying so.
Run from a program outside every zterm pane, a read of another machine's pane
asks you first, as write does.
Run from a program in a zterm pane, a read of another machine's pane needs the
same read permission as reading a pane on this machine. If the program does not
have it, zterm asks you over that program's window, naming the pane by its
title and machine, such as wants to read pane 'build' on buildbox. If you
allow it, the program can read that pane from then on. If you deny it, the read
is refused and you are not asked again. With pane_access_control = "open",
nothing is asked.
The tab's link mark
A remote pane's chip in the tab bar carries a ↔ mark after its title. Its
colour says how the link to the host is:
| Mark | Meaning |
|---|---|
↔ in the title's colour |
Connected. What you see is live. |
↔ in the accent colour |
The link is down. zterm reconnects on its own. |
↔ in the theme's red |
The host says the pane has ended. |
The pane's title bar says how the link is, at its right end, after a dot:
| Title bar | Meaning |
|---|---|
| nothing | Connected. What you see is live. |
● opening |
The pane is on its way and hasn't drawn yet. |
● reconnecting · typing paused |
The link dropped. zterm reconnects on its own. |
● not reachable for N min · retrying |
The link has been down a minute or more. zterm keeps trying. |
● ended (exit N) |
The program ended on the host with exit code N. |
● ended by a signal |
A signal ended the program on the host. |
● closed |
Someone closed the pane on the host, or from another machine. |
● ended |
The pane has ended, and the host hasn't said how yet. |
● too large to send |
The pane is too large for the host to send. Make it smaller on the host, or make the tab's text larger. |
The dot is the accent colour while the link may come back, and red once it has been down a minute or the pane has ended. In a narrow pane the words after the first are dropped first.
At the title bar's right end there is one button for the link:
- While the link is down, the reconnect button makes zterm try the machine
now, instead of waiting out the pause between tries. The palette's Pane
group has Reconnect Now too, while the focused pane's link is down, and
zterm perform reconnect_panedoes the same. - Once the pane has ended or been closed, the new shell button opens a new shell on the same machine, in a new tab, as New shell on in the palette does. A pane too large to send still runs on the host, so it has no button.
To close the tab, use the tab's own close button.
With pane.title_bar = "never" there is no title bar, so the tab says it
instead: hover the tab of a pane whose link is not live, and its tooltip
starts with the same words, such as buildbox: reconnecting · typing paused.
While the link is down, or once the pane has ended, the tab keeps the last screen it received, dimmed, and writes nothing over it. Anything you type is dropped, not queued. When the link comes back, zterm watches the pane again and sends the host the tab's size. You don't need to do anything. Close the tab when you are done with an ended pane.
A program that another machine started on the host, for example with
zspawn --on, and that exits with an error keeps its pane on the host. Its
last output stays on screen, followed by
[the program exited with code N; its last output is above], so the reason
can still be read, including from a tab opened after it ended. The host
closes that pane after an hour, or when a machine closes it. Until a program
sets a title, an opened tab reads as the pane's name on the host.
Restarting the host keeps that failed pane's last screen and restores its
ended status in zterm ls. The same applies to a pane held because its
program ended by a signal within five seconds of starting. The one-hour
hold starts again when the restarted host receives the exit; the holder
does not retain the original exit time. A successful exit, a local numeric
failure, or a signal whose cause is unknown still closes as before.
A holder left running from an older version cannot replay an exit it already discarded, even after the client is updated.
One pane, many viewers
Several machines can have the same remote pane open at once. They all see one screen, because the program has one terminal:
- A scroll moves every viewer. The host keeps one scroll position per pane. Scrolling back in one tab scrolls the pane in every other tab that shows it.
- The pane takes the smallest size. Each viewer reports its tab's size, and the host sizes the pane to fit the smallest of them. A large window watching beside a small one shows the pane at the small one's size.
- Typing from any viewer reaches the program. Two people typing at once are interleaved, as on one keyboard.
- Each viewer draws in its own theme. The default foreground and background, and the 256 indexed colours, come from the theme of the window showing the pane, and change when you change that theme. A colour the program set exactly, such as a 24-bit colour or one it redefined, looks the same on every machine. A host running zterm 0.9.63 or older, or a pane held by a zptyd from that version, sends every colour already decided in the Dark theme, and the pane keeps those colours.
On the host, zterm ls gives a pane a viewers field with the number of
connections watching it. See
Who is watching a pane.
After an upgrade
On a zterm serve host, the panes live in zptyd, a process that keeps them running while zterm serve restarts. Upgrading zterm and restarting zterm serve does not restart zptyd. Every pane, including a pane opened after the upgrade, runs in the zptyd that was already running. That zptyd keeps the older version's behaviour, such as its colours, until its last pane closes and it exits.
zterm ls on the host shows the zptyd's version in each pane's holder field. When it differs from the host's own version, zterm serve says so in its log when it starts, and zterm doctor warns.
Another machine watching the host shows it too. Its zterm ls gives the same holder on the host's panes, and a tab showing one of them says, when you hover over it, which version runs it, for example "runs zterm 0.9.62's engine on buildbox". When the pane shares its tab with other panes, its title bar also shows the version. A host running an older zterm doesn't send the version, so nothing is shown.
To move a host's panes to the new version:
- Close every pane that zptyd holds. The programs in them end.
- Check that no zptyd is left:
pgrep -af zptydprints nothing. - Restart
zterm serve, for example withsystemctl --user restart zterm-serve.service. It starts a zptyd of its own version.
Restarting zterm serve before the panes are closed does not help, and stopping zptyd while zterm serve runs leaves zterm serve unable to open panes until it restarts.