Integrating with zterm
This page is for anyone writing a script or a tool that works with zterm. It covers how to find the pane a process is running in, how to bring a pane to the front, how to read and write panes, and the small things a program inside a pane can ask the terminal to do.
The formats here are stable. Tests pin every request and response byte for byte, so a change to one is a deliberate decision.
Quick start
zterm locate $$ # which pane is this shell in?
zterm ls # every pane, as JSON
zterm focus <pane> # bring a pane to the front
Naming a pane
A pane's id is created when the pane opens and never changes. It is the pane's identity. Use it in place of window titles or tab positions, which change whenever someone rearranges their terminal.
Windows and tabs have ids too, and they do not change either. What can change
is which tab and which window a pane is in. Dragging a tab to another window
moves every pane in it to that window. join_pane and break_pane move one pane
to another tab, and join_pane <pane> can take it from another window.
Reordering tabs and splitting a pane move nothing.
The full address of a pane is a URI that says where the pane is:
workspace://zestful-terminal/window:<W>/tab:<T>/pane:<P>
zterm finds a pane by the pane id in the URI and nothing else. A URI you saved
before a pane moved still reaches that pane, although its window or tab part is
out of date. A verb that acts on a tab, such as close_tab, acts on the tab
the pane is in now. zterm ls always reports where each pane is now.
zterm focus and --target take any of three things:
- the URI
- the bare pane id
- the pane's name, if it has one
So zterm perform write 'hi' --submit --target build reaches the pane named
build.
Names are unique among live panes. rename_pane refuses a name another pane
holds and suggests free ones. If a name could also be read as a pane id, zterm
reads it as the id.
A name lasts only as long as its pane. When the pane closes, the name is free,
and another pane may take it. A target that names a closed pane gets not found. If you need an address that stays valid, use the pane id.
Panes on other machines
A URI with three parts after the host is a pane on this machine. A pane on
another machine has a fourth part, node:
workspace://zestful-terminal/node:<N>/window:<W>/tab:<T>/pane:<P>
A bare pane id names a pane on this machine, with three exceptions:
zterm perform attach, zterm perform close_pane and zterm perform write
also take the id of a pane another machine lists. See Remote
panes. zterm focus
refuses a four-part URI as not local, and an older zterm refuses it as
malformed.
What a pane's programs can see
zterm sets these variables for every program it starts in a pane:
| variable | value |
|---|---|
TERM_PROGRAM |
zestful-terminal |
TERM_PROGRAM_VERSION |
The zterm version. |
ZESTFUL_TERM_WINDOW_ID |
The window id. |
ZESTFUL_TERM_TAB_ID |
The tab id. |
ZESTFUL_TERM_PANE_ID |
The pane id. |
Reading $ZESTFUL_TERM_PANE_ID is the cheapest way for a program to learn its
own pane. It needs no socket. It can go stale inside tmux or zellij. See
Under a multiplexer.
The window and tab variables are set once, when the program starts. If the pane
later moves to another tab or window, they still name the old one, because
nothing can change the environment of a running program. The pane id stays
right. Rely on the pane id, and ask zterm ls for the tab and window.
Every other variable zterm itself was started with reaches its panes, except those that belong to one agent session. A zterm started from an agent's shell does not pass on that agent's identity or session:
ZC_AS, and everyZSPAWN_*variableCLAUDECODE,CLAUDE_PID,CLAUDE_EFFORT, and everyCLAUDE_CODE_*variableAI_AGENTCODEX_SANDBOXandCODEX_SANDBOX_NETWORK_DISABLEDPI_CODING_AGENT,PI_SESSION_ID,PI_SESSION_FILE,PI_PROVIDER,PI_MODELandPI_REASONING_LEVEL
Settings such as ZTERM_CONFIG and ZTERM_INSTANCE, PATH, and anything
else still pass. A variable your shell profile sets is set again in each pane,
because each pane's shell runs the profile. To run a program in a pane as a
particular principal, set the variable in its command:
zterm perform new_tab -- env ZC_AS=ash claude. zspawn does this for the
agents it launches.
Exit codes
| code | meaning |
|---|---|
0 |
Yes, or done. |
1 |
zterm understood the question and the answer is no. For example, no such pane. |
2 |
Something failed: a bad command line, no terminal running, or a refusal. |
3 |
You are not allowed to do this. See Permissions. |
4 |
A --when-idle=<t> wait ran out. Nothing was written. |
5 |
The terminal reached the request after its deadline. Nothing was done. |
6 |
A person was asked to allow this and did not answer within the wait. Nothing was done, and it is not a refusal. |
7 |
The pane is at a password prompt, so the write was not typed. See Password prompts. |
A 3 or a 6 from zterm perform can arrive up to two minutes late, because
the command waits while a person is being asked. See Waiting for a
person.
4 and 5 both mean the request had no effect, so you can send it again. 4
says what held the pane for the whole wait:
{"result":"idle_timeout","reason":"draft"}: someone typed a line in the pane and did not submit it.{"result":"idle_timeout","reason":"typing"}: someone kept typing in the pane.{"result":"idle_timeout","hidden_input":true}: the pane stayed at a password prompt.
An answer with no reason comes from an older zterm, and means typing or a
draft. 5 says the terminal was too slow to reach the request, and the answer
is {"result":"expired"}.
zterm decides a pane has a draft from the keys typed into it. Any key that
types a character counts, a paste counts, and Up or Down counts, because a
shell puts a history line there. Return, Ctrl+C and Ctrl+U end it, and so
does Backspace down to nothing. A key a program takes without putting it on
the line, such as a digit that answers a menu, still counts, so a draft can
outlast the line it stands for. A write with --submit into a pane on the
same machine ends the draft, because its Enter submits whatever was on the
line. Into a pane on another machine it does not, yet.
Keep 1 and 2 apart in your scripts. 1 means zterm is running and the pane
does not exist. 2 can mean zterm is not running at all. A script that treats
them alike will quietly do nothing on a machine with no terminal.
When the terminal does not answer
A request waits five seconds for its answer. A write sent with
--when-idle=<t> waits <t> and two seconds more. If no answer comes, zterm
exits 2 and prints one of two sentences after the socket's path.
the terminal did not answer within 5s. The request was sent with a deadline that has now passed, so it will not be carried out. This is what zterm perform prints. The terminal has the whole request and did not run in time to
read it. Every perform carries a deadline, set one second before zterm stops
waiting. A terminal that reaches the request after that does nothing, on every
platform, so you can run the command again.
the terminal did not answer within 5s. The request was sent and may still be carried out. This is what zterm focus prints. A focus request carries no
deadline, and a terminal that starts running again may still raise the pane.
A terminal can also answer in time and say it was too slow. Its main thread has
two seconds to reach a perform. After that the terminal answers error with
the terminal did not answer in time. The request was dropped and will not be carried out, and zterm exits 2. If the main thread reaches the request in
the last quarter second, it answers {"result":"expired"} and zterm exits
5. In both cases nothing was done.
the terminal did not take the request within 5s. It was not carried out. The
request was larger than the socket's buffer, about 8 KB on macOS, and the
terminal read none of it in time. No version carries out part of a request. Run
the command again.
write --submit is one request. The terminal types the text, waits until the
pane shows it, presses Enter, and then answers. It waits at least 50 ms. It
waits at most 2 seconds plus 5 ms for each byte of the text, and at most 30
seconds, and then presses Enter anyway. A program that shows what it is sent,
such as a shell or an agent's prompt, gets its Enter shortly after the text
appears. ok means the text was typed and Enter was pressed. not_found, denied, idle_timeout and expired mean nothing was
typed, so you can run the command again.
If the pane closes between the text and Enter, the answer is an error: the text was typed, and the pane closed before Enter was pressed.
If the pane goes to a password prompt between the text and Enter, the answer is
{"result":"input_concealed","text_typed":true}, zterm prints the text was typed but Enter was not sent on stderr, and exits 7. The text is in the
pane's line and was not submitted.
Password prompts
zterm does not type a write into a password prompt. A program asks for a
password by turning off the echo of what is typed while it reads a line, as
sudo, ssh and passwd do. While a pane is in that state:
- A
writeis not typed. The answer is{"result":"input_concealed"},ztermsays so on stderr, and it exits7. - A
writewith--when-idle=<t>waits until the prompt has ended and nobody is typing. If<t>runs out first, nothing is typed, the answer is{"result":"idle_timeout","hidden_input":true},ztermsays why on stderr, and it exits4. - No grant and no
pane_access_controlvalue lets a write through. - Your own keys, pastes and input methods reach the prompt as always, and so does a person typing into the pane from another machine.
- It holds for a pane on another machine in your mesh too, and the answer is the same as for a pane here. The machine that hosts the pane decides, from its own terminal.
An answer sent from zterm's panel saves the reply on the board, then rings the asker's pane. For a pane on another machine open here, the host checks the ring as a held write too. Time spent waiting here leaves less of the ring's one-minute hold for the host. A refused or timed-out ring is dropped quietly; the saved reply remains on the board. The panel does not confirm that the pane received the ring.
What this cannot see:
- Windows. A Windows console has no echo setting zterm can read, so a pane on Windows is never treated as being at a password prompt.
- A machine running an older zterm. A write into a pane on a machine whose
zterm is older than this one is typed as before. A machine this new answers a
write from an older zterm with an error that says the pane is at a password
prompt, and
ztermexits2; nothing is typed. - A program that hides input by its own means, such as a full-screen program drawing its own password field. It reads keys one at a time with echo off, which zterm cannot tell from any other full-screen program.
Permissions
Any caller may list panes, locate a process, focus a pane, and close panes. A program running in a pane may open one freely. For a caller zterm cannot place in a pane it asks the person, and the subsection below lists which actions those are.
Writing into a pane or reading its screen is restricted. rename_pane and
write need a write grant. read_text needs a read grant. More actions
may join this list in later versions.
How far you reach without a grant is a setting,
pane_access_control, and the person at the keyboard chooses it. Every value
lets a program act on its own pane. They differ in what else it reaches:
siblings: the pane that opened it, the panes it opened, and the panes opened alongside it by the same pane.children: the panes it opened, and nothing upward or sideways.always_ask: nothing. Every reach outside its own pane asks the person.open: every pane in the terminal, with no grant and no question.
The default is siblings. A program that needs to know what it may do
should try the action and read the answer rather than assume, because the
answer depends on a value it cannot see.
A pane's relations come from who opened it: when a program in one pane opens
another, the opening pane is the new pane's parent, and a pane the person opens
by hand has no parent. Two panes the person opened separately are never
related to each other, so under any value but open neither can type into the
other without a grant.
When zterm restarts with restore_agents on, an agent that another agent
opened is that agent's child again once both have come back, whichever comes
back first. Only agents the restore itself reopens are related this way. A
group the person approved at launch is not restored, and asks again.
A caller on another machine belongs to no family and always needs a grant.
Opening a group that reaches each other
Under children and always_ask, the panes one program opens do not reach
each other without a grant: children gives each pane only what it opened, and
always_ask gives it nothing. A program opening several panes that must drive
each other, such as a leader and its agents, can declare that up front, so the
person answers once instead of at every crossing.
new_tab, split_right, split_down and spawn take an optional group:
{"cmd":"perform","action":"spawn","group":{"size":3,"reach":"write"}}
size is how many panes the group will have. It is advisory, shown to the
person and not enforced, so a group may open more panes than it declared, and
each still gets only the approved reach. reach is read, write or control: the
class each pane of the group may use on every other pane of the group and on the
pane that opened them.
Before the first pane opens, the person is asked once to approve the group. The
first perform is answered asked and retried until they answer, as a grant
is; on approval the panes open and reach each other, and on deny nothing opens.
Under siblings and open the field is ignored, because those values already
let the panes reach each other; a zterm serve host, which has no person to
ask, refuses a group.
Permissions in the command palette lists each group the person approved or refused, as Allowed or Denied, with the class, in the group under, and the pane that opened it. Choosing an approved group's row revokes it: the panes stay open, and their next crossing asks again. Choosing a refused group's row lifts the refusal, so the group's next declaration asks instead of being refused. A group is also dropped when the pane that opened it closes.
The pane that opened the group is never named on the wire. The group is "the panes this pane opens", found from who opened them, so a caller cannot declare a group for panes it did not open.
A program running in no pane
A program that zterm cannot place in any pane is treated differently from one it can. A shell you opened outside zterm, a script, a daemon, and a program that re-parented itself away from the pane that started it are all in this group. So is anything that reaches the socket without a handle.
For these callers nine actions ask the person at the keyboard: read_text,
write, rename_pane, new_tab, new_window, split_right, split_down,
retype_pane and spawn. The last six need no grant from a program in a
pane and are refused for nobody, so a script that has been opening tabs from
outside zterm will start seeing asked where it used to see created.
The window names the program, its process id and what it asked for, and shows the command it would run. Nothing else about the request reaches the person, so a long command is shown cut off at the edge of the window with an ellipsis.
How long an answer lasts depends on what the operating system can tell zterm about the calling process:
- Where zterm can identify a process in a way that survives the reuse of a
process id, which is every platform it ships on, an approval covers the
program the caller works for, for every action on the list above, until
that program exits. zterm finds that program by walking up from the caller,
past
ztermitself and any shells, to the first other program: Claude Code for a command its Bash tool runs, the ssh session for a command run over ssh, or the script that ranzterm perform. The window says which program an approval will cover, for example Approve covers Claude Code (claude.exe) until it exits. A program that later takes the same process id is a different program and is asked about. - An approval never covers a program running as another user. Where the walk reaches only a terminal window or the desktop, the approval covers the outermost shell under it instead, never the terminal or the desktop itself.
- Where zterm cannot identify the process that way, each request is approved on its own. The person is asked again for the next one.
Permissions in the command palette lists each program approved this way, with the words until it exits. Choosing its row revokes it, and the program's next request asks again.
A denial covers only what was asked: the same program asking for the same thing again is refused without a second window.
Over ssh, each connection asks once. Every ssh host 'zterm perform ...'
is a new ssh session, so a run of separate ssh commands asks for each one. To
ask once for the run, keep one connection open and send the commands through
it, with ssh's connection sharing in ~/.ssh/config on the machine you ssh
from:
Host mac
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 10m
A refused request looks like this:
$ zterm perform rename_pane "build" --target <pane-id>
{
"result": "denied",
"needs": "write",
"reason": "no_principal"
}
$ echo $?
3
needs is the grant the request required. Branch on reason:
reason |
meaning | what you can do |
|---|---|---|
no_principal |
zterm could not tell who is asking, and there was no way to ask a person. | Get a handle, described below. On a zterm with a window this request would have been asked instead, so this answer means there was no window to ask in: a zterm serve host, or a request naming a pane that has gone. |
grant_missing |
zterm knows who is asking, they have no grant, and nobody was asked. | Nothing from here. There was no window to ask in: zterm serve never asks, and neither does a request naming a pane that has gone. |
asked |
zterm is asking the person now, and nobody has answered yet. | Wait for the answer. The zterm command waits for you; see below. |
refused |
The person was asked and said no. | Do not send it again. Ask them what they want instead. |
unspecified |
An older zterm left the field out, or a newer one used a word this table does not list. | Do not treat it as grant_missing. The person may not be reachable. |
asked and refused are different answers, and a script that folds them
together gets one of them badly wrong. asked is a question still open: the
same request sent again may be allowed. refused is a decision, and sending it
again asks a person who has already answered.
Waiting for a person
When the answer is asked, zterm perform sends the same request again every
500 milliseconds until the answer is something else or its own wait runs out.
The wait is two minutes by default.
Approving takes longer than one click for a program running in no pane. The
operating system asks the person to confirm they are present, with Touch ID or
the login password on macOS and Windows Hello on Windows, and the request is not
allowed until it does. On a machine with no such check the person's answer
stands on its own. Either way the caller sees asked until they have finished,
and then either the request's own answer or refused.
It prints one line on stderr while it waits:
zterm: a person is being asked; waiting up to 2m
When the wait runs out, the command prints the last reply with result set to
timeout, such as {"result":"timeout","needs":"write","reason":"asked"},
prints this on stderr, and exits 6:
zterm: no answer within 2m; not a refusal
The person is still being asked at that point, so this says what happened to your command, not to the request. Nothing was written. Send it again, and it goes through once they allow it.
| flag | effect |
|---|---|
--timeout=<t> |
Wait <t> instead of two minutes. 30s, 5m, 1500ms, or a bare number of seconds. |
--no-ask-wait |
Do not wait. Return the first asked reply and exit 3. |
--timeout takes its value with an =, like --when-idle=<t> and for the
same reason: write's payload is a positional argument, so --timeout 2m
would send an empty write and wait on it. A bare --timeout is refused rather
than treated as the default.
Use --no-ask-wait in a script with nobody at the keyboard. A script that
blocks two minutes per pane on a machine where no one is watching takes two
minutes per pane to fail.
zterm identifies a caller by a handle. It puts the handle in
ZESTFUL_TERM_GRANT_HANDLE for every program it starts, and the zterm
command sends it for you.
- A handle works only at the zterm that issued it. A process that talks to
a different zterm, such as another
--instanceor one on another machine, getsno_principalthere. Writing and reading work against the terminal you are running inside. - tmux and zellij do not pass the handle on. The setup under Under a multiplexer forwards the id variables and leaves the handle out on purpose. A forwarded handle would let every pane in a tmux session act as the one pane tmux started in.
What zterm ls reports
zterm ls prints {"result":"tree","panes":[...]}, one object per pane. A field marked
optional is left out when it has no value, so a script should test for it
rather than for null.
| Field | Meaning |
|---|---|
window_id, tab_id, pane_id |
The pane's window, tab and pane ids. |
uri |
The pane's full address. See Naming a pane. |
node |
Optional. The machine the pane runs on, when it is not this one. |
pid, tty |
Optional. The pane's shell process and terminal device, on the machine that hosts it. A Windows pane has no tty. |
title |
What the program in the pane calls itself. |
title_truncated |
Optional. true when title was shortened on its way from another machine. Absent means the title is whole. |
name |
Optional. The name a person gave the pane. Absent when nobody has named it. |
command_running |
Optional. true while the shell reports a command running. Absent when no command is running, when the shell has no integration, and on a pane on another machine. |
last_command_exit, last_command_duration_ms |
Optional. The exit code and run time of the last finished command, as the shell reported them. |
tab_color, tab_squad |
Optional. The tab's colour and squad. See A colour on a tab and A squad on a tab. |
panel |
Optional. How the window's panel is drawn: full, minimal or hidden. |
cwd |
Optional. The folder the pane's shell is in. |
web |
Optional. On a web pane opened on a folder, {dir, entry}: the folder it serves and the file it opened on (entry is missing for the folder's index.html). Missing on a terminal pane and on a page opened at an address. |
focused, last_focused |
Whether the pane has focus now, and whether it is the pane the user was in last. See Which pane the user is in. |
output_idle_ms |
Optional. Milliseconds since the program last wrote on its own. See Which panes have gone quiet. |
geometry |
Optional. The pane's size and place in its tab. See How the panes are laid out. |
attention |
Optional. A notification or bell waiting for the person. |
program_status, outside_status |
Optional. A status the program reported, or one set from outside. See Reporting a program's status. |
exited, exited_at, exit_signal |
Optional. The exit code, or null for a signal, the time, and the signal number when known, for an hour after the program ended. See Which panes have ended. |
viewers |
Optional. On a zterm serve host, how many connections from other machines watch the pane. See Who is watching a pane. |
holder |
Optional. On a zterm serve host whose panes live in zptyd, the zterm version of the zptyd holding the pane. That version decides the pane's colours and reads what its program prints. On another machine's pane, present only when that machine's zptyd version differs from its own zterm serve. See After an upgrade. |
Finding the pane a process is in
zterm locate <pid> works for a pane's shell and for anything started under
it. zterm knows the process it started in each pane. For any other pid it walks
up the process tree until it reaches one of those. An editor, a build or an
agent started from a pane's shell all resolve to that pane.
$ zterm locate 999999
{
"result": "not_found"
}
$ echo $?
1
If a process somehow sits under two panes, the nearest one wins.
The walk stops at a herdr process above the one being asked about, and the
answer is not_found. herdr's server is forked from the first herdr client, so
without this every program in every herdr pane would resolve to the zterm pane
that client was started in, wherever herdr is attached now. The same programs
are treated as outside callers, as they already are once that first client
exits. A herdr client itself still resolves to the pane it runs in.
Ask only about processes you know are alive. The OS reuses the pid of a
process that has exited, and locate would then answer for whatever unrelated
process has that number now. zterm cannot detect this.
Which pane the user is in
Each pane in zterm ls has two flags, focused and last_focused. Most tools
want last_focused.
focused is true for the pane the user is typing in right now. At most one
pane has it. When zterm is not the frontmost application, no pane has it. A
tool that routes notifications usually runs just when the user has switched to
their browser, and at that moment focused is false everywhere.
last_focused is true for the pane the user was in most recently. At most
one pane has it, and it stays set while zterm is in the background. No pane has
it if nothing has been focused yet, or if the pane that had it has closed.
While zterm is frontmost, both flags are on the same pane.
# Where should this notification go?
zterm ls | jq -r '.panes[] | select(.last_focused) | .uri'
Do not poll zterm ls and remember the last pane that had focused.
last_focused already is that, and polling misses any focus change that falls
between two polls.
Which panes have ended
When the program in a pane exits on its own, zterm ls keeps listing the pane
for an hour, with these fields:
exitedis the exit code, ornullif a signal ended the program.exited_atis when it exited, in UTC, such as2026-11-09T14:02:05Z.exit_signalis the signal number when the local engine knows it. It is absent for a normal exit and when the holder does not report the signal.
A running pane has none of these fields. A pane you closed, with Cmd+W or
zterm perform close_pane, is not listed at all. A pane that ended more than
an hour ago is not listed either.
# Panes whose program ended, with the code and the time.
zterm ls | jq -r '.panes[] | select(has("exited"))
| [.name, (.exited // "signal"), .exited_at] | @tsv'
A pane that ended can still be listed while it is open on screen: zterm keeps a pane open after its program fails, so you can read its last output.
A local child ended by a signal within five seconds of its spawn also keeps
its pane open. The pane shows the signal number and elapsed milliseconds.
Press Enter or Esc to close it in a window, or use zterm perform close_pane
on a serve host. Serve keeps that pane for at most an hour. A later signal
exit closes the pane as before. Both hosts log a known signal with the pane
id and elapsed time.
The five-second window keeps a new pane's last words visible. It does not
identify a fault in zterm: deliberately running kill -9 on a shell you just
opened, or killing a profile's command immediately, produces the same held
line. The elapsed time runs from the spawn call to the engine's exit
notification.
A child held by a protocol-6 zptyd reports the same signal metadata and follows
this hold policy on a serve host. New clients still attach to protocol-4 and
protocol-5 holders after an upgrade; those holders omit the metadata, so their
signal exits keep the previous close behavior and exit_signal is absent.
Known signal numbers also travel in another machine's ended-pane listing;
older hosts omit them.
Panes on other machines in your mesh are listed the same way, with node set.
When a program ends on another machine, your zterm ls shows its exited and
exited_at, the time that machine saw it exit. If that machine is running an
older zterm, its ended panes are not listed.
Who is watching a pane
On a machine running zterm serve, zterm ls gives each pane that another
machine in your mesh is viewing a viewers field: the number of open
connections watching it. A pane nobody is viewing has no viewers field.
# Panes someone is viewing from another machine.
zterm ls | jq -r '.panes[] | select(.viewers) | [.name, .viewers] | @tsv'
The count covers this machine's own panes only. A pane listed from another
machine, with node set, has no viewers field.
Which panes have gone quiet
output_idle_ms is the number of milliseconds since the program in a pane last
wrote something on its own. A pane that keeps repainting, such as top, a
progress bar or an agent's spinner, stays near zero. A pane sitting at a prompt
climbs.
# Panes that have said nothing for a minute, longest-quiet first.
zterm ls | jq -r '.panes[]
| select((.output_idle_ms // 0) > 60000)
| [.output_idle_ms, .name, .title] | @tsv' | sort -rn
What counts as output:
- Any bytes the program writes, even if nothing visible changes. A busy program can write only invisible control sequences, so a pane with a frozen screen may still be active.
- The echo of text you sent with
zterm perform write. zterm does not treat a scripted write as typing, so the echo counts as output and resets the timer. If you send a pane some text and then polloutput_idle_ms, you measure your own text coming back. To see what the pane did with it, useread_text.
What does not count:
- The echo of the person's own typing. Pressing a key in a pane to see whether it is stuck does not make it look busy.
- Replies to zterm's own messages. zterm tells a full-screen program when its pane gains or loses focus and when the pane is resized, and the program answers. Those answers are ignored for a moment after each message.
A missing output_idle_ms means unknown. It does not mean zero. Zero means
the pane wrote just now, which is the opposite. If you give it a default in
jq, use // null and not // 0. The field is missing in three cases:
- a local pane whose program has written nothing since the pane opened
- every pane on another machine (one with a
nodefield), because zterm cannot compare against that machine's clock. Ask the machine that owns the pane. - every pane on a
zterm servehost, which does not measure output
A quiet pane has not necessarily finished. It may be done, waiting for an
answer, or running something that prints nothing. The number is the same for
all three. A program that reports its status
tells you which. A program that works silently for a minute looks the same as one
that finished a minute ago, and a program that prints dots in a loop looks
busy. command_running tells you whether a command is running, and only in
panes whose shell has command marks set up.
The tab bar shows no activity for a pane that is not an agent's. A shell
or a web pane's chip never moves, however much the pane writes. Its chip shows
only an amber ! while its program reports blocked or after a
bell you have not answered, and a red ! on an
error, and a coloured tab's colour otherwise. An agent's
chip shows what it is doing on its tile, measured the same way
as output_idle_ms when the agent reports no status of its own.
Which folder a pane is in
zterm ls lists cwd on each pane: the folder its shell is standing in, which is where a new pane opened out of it would start. The key is missing when the OS and the shell both decline to say, and on a pane on another machine. zterm locate and other answers leave it out.
How the panes are laid out
Each pane in zterm ls has a geometry object: its size and its place in its
tab, in character cells.
"geometry": {"cols": 44, "rows": 22, "col": 48, "row": 2}
colsandrowsare the size of the pane's grid. They are the numbers zterm last gave the program in the pane, so they equal whatstty sizeprints on the pane'stty(stty sizeprints rows first).colandroware where the pane's text starts, counted from the top left of the area below the tab bar.zoomedistrueon a pane its tab is zoomed to, and is missing otherwise.
# The panes of one tab in reading order, with their sizes.
zterm ls | jq -r --arg tab "$ZESTFUL_TERM_TAB_ID" '.panes
| map(select(.tab_id == $tab and .geometry))
| sort_by(.geometry.row, .geometry.col)[]
| [.geometry.row, .geometry.col, .geometry.cols, .geometry.rows, .name] | @tsv'
Use col and row to order and group panes. Do not add them to sizes.
- Panes stacked in one column have the same
col. Panes side by side in one row have the samerow. Both are exact. - Sorting by
rowand thencolgives reading order. - A grid of three columns and two rows has three different
colvalues and two differentrowvalues, and six panes whosecolsandrowsdiffer by one cell at most. col + colsof a pane is less than thecolof the pane to its right. The text starts inside the pane's padding and below its title strip, so the gap between two panes depends on the padding and title bar settings. The top left pane does not start at 0 for the same reason.
Every tab is reported, whether or not it is showing. Filter on tab_id
before you compare places, because every tab's places are counted from the same
corner.
A zoomed tab. The zoomed pane reports the whole area, which is the size it
really has, and carries "zoomed": true. The panes it hides still report the
size and place they have in the layout, and their programs still have that
size. If any pane of a tab has zoomed, the tab's places overlap. Unzoom with
zterm perform zoom_pane --target <pane> before you check a layout.
A missing geometry means zterm has no layout for that pane. It is never
reported as zeros. It is missing for:
- every pane on a
zterm servehost, which draws nothing and has no layout - every pane on another machine (one with a
nodefield). Ask the machine that owns the pane.
A zterm command older than 0.9.37 prints the panes without geometry, even
when the terminal it asks is newer, because it prints only the fields it knows.
A program that receives zterm's events does not need to
poll zterm ls for this. layout.changed carries the same geometry for every
pane of a tab each time one of them changes size or place.
Splitting a pane to a size
split_right and split_down take --ratio <share>. The share is the new
pane's part of the pane being divided, from 0.05 to 0.95.
# A log pane in the bottom quarter of this pane.
zterm perform split_down --ratio 0.25 --target "$ZESTFUL_TERM_PANE_ID" -- tail -f build.log
- Without
--ratiothe two panes are even, as they are from the keyboard. - The share is of the pane you divide, not of the window. Splitting a pane that
is half the window with
--ratio 0.5gives a quarter of the window. - The new pane gets that share of the space to within one cell. Read the result
from
geometry. Padding and title strips come out of each pane, so comparecolsorrowsof the two panes with each other, and expect them to be a cell or two off the exact share. - The share holds when the window is resized. It is a share, not a number of cells.
- A share outside 0.05 to 0.95 is refused and nothing is split.
zterm performexits 2 before it sends anything. A program on the socket gets anerrorreply that names the range. zterm never picks a nearby share for you. - On the socket the field is
ratio, a number:{"cmd":"perform","action":"split_right","ratio":0.3}. zterm reads it to the nearest thousandth. - A
zterm servehost has no layout. It checks the number, opens the pane and sizes nothing, so the same command still starts its program there.
Showing a page in a pane
new_tab, new_window, split_right and split_down take --web <dir> [entry] in place of a command. The pane then shows a page instead of running
a process: the directory is served to it under zterm-web://<id>/ and it opens
entry, index.html when you leave that out. A file in place of the directory
names its parent and itself.
# A chart under this pane, a third of its height.
zterm perform split_down --web /srv/report chart.html --ratio 0.33 --target "$ZESTFUL_TERM_PANE_ID"
On the socket it is the
webfield:{"cmd":"perform","action":"split_down","web":{"dir":"/srv/report","entry":"chart.html"}}. The directory is yours to make absolute;zterm performdoes that for you.zterm performmakes a relative--cwdabsolute against the folder it runs in. On the socket,cwdmust already be absolute and name a folder on the machine that opens the pane. Otherwisenew_tab,new_window,split_right,split_downandretype_paneanswerfailedwithno such directory: <path>, and nothing opens. For a pane on another machine, give the full path there; a relative one is refused.A profile's folder is different: one that has gone still opens a terminal, where zterm would otherwise start it.
A pane shows a page or runs a process.
--webbeside--cwdor--is refused, naming both, and nothing opens.retype_panegives an existing pane a new content in place, with the same flags:--web <dir> [entry]makes it a page, a command after--(with--cwd <dir>) or nothing makes it a terminal again. The pane keeps its id, its place and size in the layout and its grants; the process it ran is killed, the page it showed is dropped, and a terminal retyped to a terminal starts where the old one was standing. On the socket:{"cmd":"perform","action":"retype_pane","web":{"dir":"/srv/report"}}and{"cmd":"perform","action":"retype_pane","command":["htop"]}. Underzterm serveit is refused as not supported there.The page is handed the terminal's theme before its own scripts run, as variables on
<html>:--zt-bg,--zt-fg,--zt-cursor,--zt-selection-bg,--zt-selection-fg,--zt-ansi-0to--zt-ansi-15(#rrggbbeach),--zt-font-mono(the family, quoted, withmonospaceafter it) and--zt-font-mono-size(inpx), plusdata-appearanceand thecolor-schemeproperty,lightordarkby the background. A stylesheet uses them asbackground: var(--zt-bg). When the theme or the font changes the variables are set again andappearance-changedis dispatched ondocument, so a page that drew itself from them can draw again. The selection pair is what the terminal draws: a selected cell swaps foreground and background.The view's appearance follows the terminal's theme, not the system's, so a page's
prefers-color-schememedia queries answerlightordarkasdata-appearancedoes, and change with it. A page that sets no colours gets the terminal's background, foreground and font from a base stylesheet in a cascade layer, so any rule of the page's own wins over it. A page shown with--urlgets the appearance but not the stylesheet.The page may run only the scripts it ships: a script from another origin is refused by the pane's content security policy. A valid
zterm://focus/...link focuses its target in this terminal. The page's script can follow one without a click, so a page can move typing focus to any pane in this terminal, and the keys you type next go to that pane. Other links off the page's origin open in the system browser and the pane stays.--url <address>in place of--webshows a page that a server on this machine already serves, such as the zc dashboard thatzc webnames. The address ishttporhttpsonlocalhost,127.0.0.1or[::1], at any port, or anhttpsaddress whose host you list in[web] remotein settings, such ascanva.com; anything else is refused naming that setting, and nothing opens. Only the settings file adds a host. On Linux a page on another machine is refused for now. The page is shown as the browser would show it: no theme variables, nowindow.zterm, and no content security policy from zterm. A local page's validzterm://focus/...link focuses its target in this terminal, clicked or not. The page's own script can follow one, and so can any script the page loads from another site, such as a library from a CDN, so a page on this machine and the scripts it loads can move typing focus to any pane without a click. A--webpage loads no outside script. A remote page cannot use that route. Other links off its origin open in the system browser; for a listed site, a link off the listed hosts does, and frames inside the page load where they are. Until the page names itself, the pane's title is the address without its query and fragment, so a token in the query is not shown. On the socket it is thewebfield:{"web":{"url":"http://127.0.0.1:7437/"}}. On Linux it needs an X11 window, as--webdoes.The page's main frame has
window.zterm, a bridge to this terminal; a subframe and any other page have nothing. It has four members:zterm.call(method, params, {signal})sends a socket request and returns a promise of the socket's answer.methodis the request'scmd(list,list_page,locate,focus,perform) andparamsthe rest of it, so the grammar is the socket's and there is nothing to learn twice:zterm.call("perform", {action: "split_down", web: {dir: "/srv/report"}, ratio: 0.33}),zterm.call("list"). The promise resolves with the response object as the socket would write it ({result: "ok"},{result: "created", pane: {...}},{result: "denied", ...},{result: "error", message}), so a refusal is a value, not a rejection. It rejects only for what the socket cannot say: anAbortErrorwhensignalaborts (the request is not recalled, and what it asked for may still happen), and anErrorwhen the request is over the size bound. The call is made as the pane: its occupant is the principal, its grants are the grants, and ahandleinparamsis dropped. Aperformwith notargetacts on this pane, sosplit_downwith none splits the page's own pane.zterm.subscribe(topics, callback)hears the terminal's events by the names in EVENTS.md (pane.title_changed,layout.changed,focus.gained, ...),*for all of them, or a prefix such aspane.*.callback(event_type, payload)gets the documented payload and no envelope. It returns a function that removes the subscription. Closing the pane, retyping it, or reloading or navigating the page cancels every subscription, and a reloaded page subscribes again from its own script.zterm.contextis{pane, window, tab}: the pane's URI and the ids of its window and tab, replaced when the pane moves to another tab or window.zterm.setTitle(title)names the pane;zterm.setTitle(null)drops the name, and the pane's title falls back todocument.title, then to the entry file's name. A page'sdocument.titlenames the pane from the start, so a page with a<title>is named by it without a call.
A request and a response are each bounded at the socket's line limit, 65535 bytes: an oversize request is rejected before it is sent, and an oversize response becomes
{result: "error", message}naming the bound, so a tree that does not fit is read withlist_page.Three verbs are a page's feedback loop, for an agent that cannot open the inspector. Each takes
--target <pane>and answers a pane that runs no page with an error saying so;zterm serverefuses them.zterm perform read_consoleprints what the page wrote toconsole.log,.info,.warn,.error,.debugand.trace, one row per call as<level>: <text>, with an uncaught exception aserror: Uncaught <message> (<file>:<line>:<col>)and an unhandled promise rejection aserror: Unhandled rejection: <reason>. The pane keeps the last 500 rows of the current document, each cut at 4 KiB; a reload starts the record again. Socket:{"action":"read_console"}, answered{"result":"text","rows":[...]}. Needs theReadgrant, asread_textdoes.zterm perform screenshot_pane shot.pngwrites the page as the web process renders it to that PNG, overwriting; a relative path is made absolute against your working directory, and on the socket it is{"action":"screenshot_pane","path":"/abs/shot.png"}. The pixels are the web process's own render at the pane's size, not a copy of the screen: on macOS WebKit draws it while the screen is locked or the pane is covered; on Linux it is WebKitGTK's snapshot of the visible region and needs the view mapped, so a pane with no surface yet answers "no surface yet"; on Windows WebView2 documents that the control has to be visible. Answeredokonce the file is written. Needs theReadgrant.zterm perform reload_panereloads the page at the address it shows, so an edited file is seen. When the page's process has died or stopped answering, the reload opens a new web view there instead, so a blank or frozen page comes back. The bridge's subscriptions and the console record start again. Ungated, asretype_paneis.
When the system ends the web engine's process that ran a page, under memory pressure or in a crash, the pane goes blank. zterm opens the page again in a new view at the address it showed, the panel's page too. zterm also asks each page on screen to answer every five seconds, and opens a new view for one that leaves two questions in a row unanswered for thirty seconds each. Time zterm itself spent stalled does not count against a page. zterm reopens a page at most three times a minute, and after that leaves it as it is until
reload_pane.A dev build (one with debug assertions) opens the web view with the platform inspector enabled, for a person at the pane's context menu; a release build does not.
Files are read from the directory on every request, so a page that polls a file sees it change. Nothing outside the directory is served:
.., absolute paths and symlinks that leave it answer 404.A
zterm servehost has no window to draw in and refuses the action as not supported there.A profile can carry the same page:
kind = "web"withdirand an optionalentry, opened byopen_profileand from the+menu like any other.On macOS the pane is a WebKit view; on Windows it is WebView2, and a machine without the WebView2 runtime refuses the action; on Linux it is WebKitGTK, and it needs an X11 window. A Wayland session runs zterm under XWayland for this. A native Wayland window refuses the action, which happens when
native_waylandis true or no X server answers.
Reading a pane's screen
zterm perform read_text --target <pane>
# {"result":"text","rows":["$ cargo test"," Compiling zterm v0.9.23",""]}
rows has one string for each row on screen, top to bottom. Blank rows at the
bottom are included, so you can tell a blank line in the middle of the output
from the end of it. Spaces at the end of each row are trimmed. The text
contains no escape sequences.
read_text returns what is visible now. It does not return scrollback, and no
action reads scrollback yet.
read_text needs a read grant outside your own family of panes. A refusal is
{"result":"denied",...} with exit code 3. It is never an empty screen.
Use read_text when output_idle_ms cannot tell you enough. A quiet pane that
has finished and one that is waiting for an answer have the same idle time and
different screens.
Under a multiplexer
Two things go wrong inside tmux or zellij.
ZESTFUL_TERM_PANE_IDgoes stale. A shell gets the variable when it starts. If you detach the tmux session and attach it from a different zterm pane, every shell inside still has the id of the pane the session was created in. Nothing reports an error.zterm focuskeeps working and raises the wrong pane.zterm locatestops working. Processes inside tmux are children of the tmux server, and the tmux server is not a child of any pane's shell.locatewalks up from the process, never reaches a pane, and answersnot_found.
The first can be fixed. The second cannot be fixed from inside zterm, so inside
a multiplexer rely on the environment variables and not on locate.
herdr is worse for the first. Its server keeps the environment of the zterm
pane it was first started in, and every herdr pane inherits that pane's ids,
even after that pane closes. Nothing refreshes them. zc ignores the ids there,
because herdr sets TERM_PROGRAM=herdr. zspawn ignores them when HERDR_ENV
is set: it does not rename the pane, colour its tab or check names against
zterm, and its name line says why.
The process tree leads back to that first pane too, so zterm locate answers
not_found for anything inside herdr rather than name it. See Finding the pane a process is in.
zc gives an agent inside herdr a herdr address instead, made of herdr's API
socket (HERDR_SOCKET_PATH) and its pane id (HERDR_PANE_ID). The board
offers no link to focus it: zterm does not follow links into herdr.
The board also shows the state herdr detects for that agent: idle, working, blocked or done. While the dashboard runs, zcd reads it from herdr's API socket and follows herdr's events. A state herdr calls unknown shows as no state. When herdr stops, the agent's state goes until herdr is back. After a herdr restart, an agent shows no state until it next runs a zc command, because herdr reuses pane ids. herdr's blocked does not add to Needs you, which lists questions asked on the board.
Keeping the variables current
Add these lines to your configuration:
# ~/.tmux.conf
source-file /path/to/zestful-terminal/shell/tmux.conf
# ~/.zshrc or ~/.bashrc
. /path/to/zestful-terminal/shell/zestful.sh
# ~/.config/fish/config.fish
source /path/to/zestful-terminal/shell/zestful.fish
tmux.conf adds zterm's id variables to tmux's update-environment list. On
each attach, tmux then copies them from the attaching terminal into the
session. That fixes shells started after the attach. The shell snippet fixes
shells that were already running: before each prompt it reads the variables
again from the tmux session. Outside tmux the snippet does nothing.
tmux.conf appends to update-environment and does not replace it. Replacing
the list would drop tmux's defaults and break SSH_AUTH_SOCK and DISPLAY
forwarding.
Tests check that these files name exactly the variables zterm sets, and that
zestful.sh parses under sh, bash and zsh. The setup has not been run
against a live tmux, and zestful.fish has not been run under fish. If it does
not work for you, please report it.
Command marks
zterm can track whether a command is running in a pane and how the last one ended, if the shell tells it. zterm makes zsh, bash and PowerShell tell it when it starts one of them as a pane's shell with no arguments. You change nothing, and none of your files is edited:
- zsh: zterm points
ZDOTDIRat a folder of its own. That folder's.zshenvputs yourZDOTDIRback, runs your.zshenvand loads the marks, and zsh then reads your.zprofile,.zshrcand.zloginas usual. - bash: zterm adds a hook to
PROMPT_COMMANDthat loads the marks at the first prompt, after your profile and rc files, and then removes itself. An rc file that setsPROMPT_COMMANDoutright, rather than adding to it, removes the hook too, and that shell sends no marks. bash 4.4 and later marks when a command starts; macOS's/bin/bash(3.2) marks only the prompt and how a command ended. - PowerShell: zterm's prompt hook, which already reports the directory, sends the marks. The command-start mark needs PSReadLine, which PowerShell loads by default.
zterm keeps the zsh and bash scripts in ~/.local/share/zterm/shell/, or
under $XDG_DATA_HOME when that is set.
For fish, or a shell zterm did not start, source a snippet yourself:
# ~/.zshrc or ~/.bashrc
. /path/to/zestful-terminal/shell/osc133.sh
# ~/.config/fish/config.fish
source /path/to/zestful-terminal/shell/osc133.fish
Sourcing osc133.sh in a shell zterm already set up does nothing the second
time.
The marks are OSC 133 sequences at the start of each prompt, when a command starts and when it finishes. Anything that writes to the pane can send a mark, so a mark does not prove a command ran or succeeded. For whether the pane's process is alive, zterm relies on its own process tracking.
Without any configuration
You can match panes by tty with no setup. Ask tmux which terminal is attached, then find that tty in the pane list:
tty=$(tmux display-message -p '#{client_tty}')
zterm ls | jq -r --arg tty "$tty" \
'.panes[] | select(.node == null) | select(.tty == $tty) | .uri'
Keep the select(.node == null). The pane list can include panes on other
machines, and a remote pane's tty is whatever that machine reported. A remote
pane with the same tty string as your local one would otherwise match first.
Local panes have no node field, and every remote pane has one.
This route has limits:
ttyis alwaysnullon Windows, where panes have no tty path. The route works on macOS and Linux only.- A detached session has no attached terminal, so it has no tty.
- A session attached from two terminals has two, and the user is looking at only one of them.
Desktop notifications
A script in a pane can ask for a desktop notification. zterm accepts the sequence most terminals use and iTerm2's shorter one:
printf '\e]777;notify;Deploy;failed on staging\a' # title, then body
printf '\e]9;build finished\a' # body only
The words always appear on the pane itself, in a small label at the top left of its text. The label stays until you press a key or click in that pane.
What the desktop banner says depends on who opened the pane:
- A pane you opened yourself, with a new window, a new tab or a split from
the keyboard, posts a banner with the pane's name or title as its heading
and the script's words under it:
Deploy: failed on staging. - Any other pane posts a banner that says only that the pane sent a
notification. This covers panes an agent opened and panes opened from a shell
with a command such as
zterm perform split_right. The words are on the pane when you get there. This keeps text from an untrusted source, such as a file someone printed withcat, off your lock screen.
Limits:
- One banner per pane every five seconds. A pane that sends twenty in a second produces one banner, and the label shows the last words sent. Extra banners are dropped and not queued.
- Title and body are each made into one line. Control characters become spaces. Zero-width characters and characters that override text direction are removed. The title is cut at 80 characters and the body at 200. The banner's heading is always the pane's name or title, never text from the script.
- A body with fourteen or more semicolons is cut short. The parser keeps
sixteen
;-separated fields and drops the rest without a warning. If your body is a list, join it with a different character.
To turn banners off, set on_request = false under [notifications]. The
label on the pane still appears.
When you test this on macOS, switch to another application first. macOS shows no banner while zterm is frontmost. You can also look for the label on the pane.
Clicking a banner brings zterm to the front and focuses the pane that sent it, switching to its window and tab. If that pane has closed, the click does nothing.
Reporting a program's status
A program can tell zterm what it is doing: working, waiting on the person,
done or failed. zterm shows that on the tab bar and in the
pill, and zterm ls reports it. The sequence
is OSC 7501, followed by key=value pairs joined with ::
# The pane's program is working on its root record.
printf '\e]7501;state=working:app=myagent\e\\'
title and msg are standard base64 of UTF-8 text, so a shell helper is the
easy way to send them:
status() { # status <state> [kind] [msg]
local seq="state=$1"
[ -n "$2" ] && seq="$seq:kind=$2"
[ -n "$3" ] && seq="$seq:msg=$(printf '%s' "$3" | base64 | tr -d '\n')"
printf '\e]7501;%s\e\\' "$seq"
}
status working
status blocked permission 'Run cargo test?'
status done
The keys
stateis required:idle,working,done,blocked,error, orclearto remove the record. A report without a known state is ignored.kindsays what a blocked program waits for:permission,questionorauth. It is kept only withstate=blocked.progressis a whole number from 0 to 100, kept only withworkingandblocked. Without it the progress is unknown.appnames the program, in ASCII letters, digits and_ . + -, up to 32 characters.titleandmsgare base64. Text that does not decode, or that holds a control character such as a newline, makes zterm ignore the whole report.idnames a record, as a path such asbuild/test. Leave it out for the pane's root record. A program running several tasks gives each its own id, and a record with noapptakes its nearest parent's.
Each report replaces its record whole, so send every key you want to keep.
Unknown keys are ignored. A report over the size limits (4096 bytes in all,
2048 bytes of decoded msg, 192 of title, 8 levels of id) is ignored
whole. A pane keeps up to 256 records and drops the least recently updated one
past that.
To ask whether the terminal reads these, send printf '\e]7501;?\e\\'. zterm
answers with
ESC ] 7501 ; ? : states=idle,working,done,blocked,error : kinds=permission,question,auth ESC \
(without the spaces).
What zterm shows
A pane shows its most urgent record: blocked, then error, then working, then done. An agent's chip shows all of them on its tile. Any other pane's chip shows only the two that need you:
- blocked: an amber
!. It stays until the program reports something else, even while you are looking at the pane. The pill turns red and pulses, and lists the pane with what it waits for, such asNeeds permission: Run cargo test?. - error: a red
!, until you focus the pane.
Working, done and idle show nothing on such a pane. The overflow buttons show no mark. A pane that is on screen shows its mark on its chip too.
A pane that wears a title strip shows the
same ! at the strip's right end, an agent's included. The mark never moves
the title.
A pane that reports a status is read from its report alone. While a report
stands, even idle, its output does not count as working or as unread for an
agent's tile. An agent that has reported nothing is read from its output, as
Which panes have gone quiet describes.
How long a record lasts
state=clearremoves the record and every record under its id.clearwith no id removes them all.- A new shell prompt, from command marks, and the program's exit remove working, blocked and idle records. Done and error stay until a report replaces them. So a program that crashes while blocked does not leave the pane marked blocked.
- A terminal reset (
RIS,ESC c) removes every record.
OSC 9;4 progress stands in for the root record until the pane sends its
first OSC 7501, state=clear included. A 9;4 progress, indeterminate or
paused report makes the root record working, with its progress. 9;4;2, an
error, makes it error, a red !. 9;4;0 removes it. After the first 7501
report zterm ignores 9;4 for the pane's status until a reset. The dock's
progress bar still reads 9;4.
Reading it back
zterm ls gives each pane that has reported a program_status. Its top-level
fields are the record the pane shows: state and since_ms, the time it
entered that state in milliseconds since the Unix epoch, and kind,
progress, app, title and msg when they are set. id is the record's path,
empty for the root. records lists every record, oldest update first. A pane
that is blocked also carries an attention with severity urgent.
Codex reports working while it waits for an answer to its own question, and
says it is waiting only in its title, which blinks [ ! ] Action Required and
[ . ] Action Required. So zterm ls lists a pane whose record is Codex's
(app=codex) and working, while its title starts with either form, as
blocked with kind=question, and gives the title's next part as msg. A
Codex record that already says blocked is listed as Codex reports it. The
pane's chip on the tab bar draws the same amber ! for as long as the title
says so.
A pane's notification (OSC 9, 777 or 99) or bell is also listed as its
attention until you focus the pane. It goes sooner if the program moves on: a
record that enters working or idle after the notification, or 2.5 seconds
of steady output after it. A program waiting silently at a prompt keeps it.
# Panes waiting on a person, with what they wait for.
zterm ls | jq -r '.panes[]
| select(.program_status.state == "blocked")
| [.name, .program_status.kind, .program_status.msg] | @tsv'
A status from outside the pane
A program that is not running in the pane, such as a multiplexer that hosts it,
can mark it with set_pane_status:
zterm perform set_pane_status 'herdr/blocked:waiting on approval' --target <pane>
zterm perform set_pane_status none --target <pane>
The argument is [<from>/]<state>[:<label>]. state is idle, working,
blocked or done, and none clears. from is the name the caller gives
itself, up to 32 letters, digits, ., _ or -. label is up to 80
characters. On the socket the fields are state, label and from.
The tab chip and title strip draw the same marks as OSC 7501. When the pane
reports its own status, that report wins. Hovering the chip shows where the
mark came from, as "herdr says: blocked · waiting on approval", or "from
outside: blocked" when from is absent. zterm does not check from.
An outside status never asks for a person. It does not bounce the dock, post a
notification, show in the notch, or count toward Needs you, and zterm ls
gives no attention for it. It needs no grant. zterm ls lists it as
outside_status, with state, label, from and since_ms. It lasts until
it is cleared or the pane closes.
Light or dark
A program can ask whether zterm draws light or dark, and ask to be told when that changes. herdr and other TUIs use this to match their colours to the terminal's.
CSI ? 996 nasks. zterm answersCSI ? 997 ; 1 nfor dark andCSI ? 997 ; 2 nfor light.CSI ? 2031 hasks for a report on every change, andCSI ? 2031 lstops it. While it is on, switching zterm between a light and a dark theme sends the pane the sameCSI ? 997 ; 1|2 nunasked.CSI ? 2031 $ preads the mode back.
Dark means the theme's background contrasts more with white than with black.
A pane served by zptyd answers from the palette zptyd started with and does
not follow a theme change, the same as its answer to OSC 11.
A pane icon
A program can send a small PNG to say its pane is an agent's:
printf '\e]9378;icon;%s\a' "$(base64 < icon.png | tr -d '\n')"
The sequence has exactly three fields: 9378, the word icon, and the PNG in
base64. zterm ignores the sequence if it has a fourth field or a different
word.
zterm does not draw the image. A pane that sends one wears the zc dashboard's agent tile on its tab chip instead, after the pane number: a blank rounded square, the size of the dashboard's tile at the default font (12 pt at 14 pt), in the colour the dashboard gives that agent: its squad's colour when the zc board puts the pane's name in a squad, and otherwise a colour from the name. With no zc daemon to ask, the tab's colour stands in for the squad's. A pane with no name keeps one colour for as long as it is open. The title strip a pane wears when its tab is split shows no tile.
The tile shows what the agent is doing:
- working: the tile fades out a little and back, every 1.8 seconds.
- idle: the tile is faded and still.
- done, with output you have not seen: the tile is solid and still.
- waiting on you, for a reported block or a permission dialog: the tile
becomes a
!in its colour, which shakes every few seconds. - error: a small cross is cut from the tile's centre.
The colour always names the agent's squad and never the state, so a red squad does not read as an error. The dashboard draws its tiles the same way.
zspawn sends the agent's logo this way for every agent it launches.
A pane that sends no logo also wears the tile while Claude Code or Codex
reports its status from it with OSC 7501.
So an agent started by hand, or in a pane on another machine, still shows
its tile.
zterm refuses an image over any of these limits, checked in this order:
| limit | |
|---|---|
| base64 text | 8 MiB |
| width or height | 2048 px |
| width × height | 1,048,576 px, for example 1024 × 1024 |
A refused icon fails silently. zterm writes nothing back to the pane and the pane keeps the icon it had. If your icon does not appear, check it against the limits first, and scale it down if it is over.
Sending a new icon replaces the old one. There is no way to clear an icon. It goes when the pane closes.
The graphics setting does not affect icons. That setting controls images
inside a pane's content, so an icon still draws with graphics = false.
Rounded grounds
A text UI can ask zterm to paint a rounded rectangle under a block of its cells, so a panel has the corners the web dashboard's panels have. Paint the cells the panel's colour as you would in any terminal, then name the block:
# A panel 110 cells wide and 29 tall, its top-left cell at column 2, row 6,
# with 8px corners, in #1c1917.
printf '\e]9378;ground;2,6,110,29,8,1c1917\e\\'
The sequence has three fields: 9378, the word ground, and the request.
The request is six values separated by commas: the column and the row of the
block's top-left cell, counted from 0 at the pane's top-left; the block's
width and height in cells; the corner radius in pixels; and the colour as six
hex digits with no #. zterm ignores a request with a value missing, a width
or height of 0, or a fourth field.
zterm draws the ground and leaves unpainted every cell inside the block whose background is the ground's colour. The ground shows through those cells, and at the corners whatever is under the ground shows: the pane's background, or a larger ground beneath it. A cell inside the block with any other background paints as usual, square, over the ground. In a terminal that is not zterm the sequence is dropped and the cells are the panel, with square corners.
Grounds paint in the order you send them. A highlighted row inside a panel is two requests, the panel first. A cell inside the row is compared with the row's colour, not the panel's, so a cell of the panel's colour inside the row is painted, square.
When grounds go away:
printf '\e]9378;ground;clear\e\\'drops every ground on the current screen.- Erasing the whole display,
ESC [ 2 J, drops them, so a program that clears before a redraw starts clean. Erasing part of the display does not. - A resize drops them. Send them again with the frame you draw at the new size.
- The alternate screen has its own set. It is empty when you enter the screen and dropped when you leave it, so a full-screen program's panels do not outlive it.
- A full reset,
ESC c, drops both screens' sets.
A ground does not scroll with the text. Send clear and then the grounds
with each frame you draw, in the same write as the frame. A console of twenty
panels is about six hundred bytes.
To find out whether the terminal draws grounds, ask once at startup:
printf '\e]9378;ground;?\e\\\e[c'
zterm answers ESC ] 9378 ; ground ; 1 ESC \ and then the usual answer to
ESC [ c. A terminal that does not draw grounds answers only the second, so
read until the ESC [ ? … c reply arrives and look for the ground answer
before it. The 1 is the request form described here.
One ground per sequence. zterm's parser keeps sixteen ;-separated fields
and 1024 bytes of one sequence, so a list of grounds in one sequence is cut
short.
A colour on a tab
A program can give a tab a colour. zterm draws a short bar in that colour
before the tab's first pane in the tab bar, and lists it so the program can
read it back. The bar never moves: the colour says which tab it is, not what
it is doing. An agent's tile, or a !, takes its place. A squad shown as one
item on the bar draws its bar in the first colour any of its tabs has, the same
way.
zterm perform set_tab_color teal --target <pane>
The colour goes on the tab the target pane is in. It is one of six hue names, a hex colour, or the word that clears it:
| argument | what it draws |
|---|---|
lime, teal, sky, violet, fuchsia, pink |
the theme's value for that hue: one on a dark theme, another on a light one |
#rrggbb |
that colour, on every theme |
none |
nothing; the tab has no colour |
A hex is read in either case and listed in lowercase. Anything else is
refused with the list above, and the tab keeps what it had. Without an
argument zterm perform prints the same list and sends nothing.
zterm ls lists the colour as tab_color on every pane of the tab, as the
word that set it: "teal", or "#5eead4". A pane whose tab has no colour
has no tab_color key. A pane on another machine never has one.
The colour stays with the tab: moving the tab along the bar or to another window keeps it, and a pane that leaves the tab for another leaves the colour behind. Closing the tab drops it. It is not saved, so a new zterm starts with no coloured tabs, as it starts with no named panes.
A program that opens a tab for a group of panes, as the zc console does for a
squad, can colour it to tell it from the others. A zterm from before this
action answers zterm perform set_tab_color with no such action, and a
program that sees that answer can go on without a colour.
A squad on a tab
A program can say which squad a tab belongs to. zterm lists the squad so the program can read it back, and keeps the squad's tabs together. While the tab bar has room for every chip, a squad's tabs are chips like any other, and each agent shows its own tile. When the bar is too narrow, zterm draws a squad none of whose panes is focused as one item instead of a chip per pane. It folds one squad at a time, the one furthest from the focused tab first, and only as many as it needs, before it hides any tab at the bar's edges.
zterm perform set_tab_squad render --target <pane>
The squad goes on the tab the target pane is in. The argument is the squad's
name, or none, which takes the tab out of its squad. A name is at most 64
characters; an empty or longer one is refused and the tab keeps what it had.
zterm keeps a squad's tabs together in the bar. A tab given a squad moves to
the end of that squad's run of tabs; a tab opened from inside the run opens at
the run's end; moving a tab so that another squad's run would be split is
refused; and a tab moved to another window joins its squad's run there, or
lands outside every run when it has none. Moving a tab one place with
move_tab_left or move_tab_right steps a plain tab over a whole run.
The item stands for every pane of the squad. It shows the range of pane labels
it covers, as 4-7, so ⌘4 still focuses the fourth pane; the squad's name;
and one mark for the whole squad: a ! if one of its panes waits on you, else
the tile of its busiest agent (working, then done, then idle), else the squad's
colour. Clicking the item focuses the
squad's first pane, and focusing any pane of the squad expands the item back
into chips. The item takes the same bar room as a chip, so a squad of twelve
panes costs the bar one item. When the bar is still too narrow to show every tab, it
hides the ones furthest from the active tab: those to the right of the shown
run behind a +N ▶ summary at the run's right end, those to the left behind a
◀ +N marker at its left end. Each button counts its own side and is drawn
only while its side hides a tab. Neither shows a mark: the dashboard shows what
each hidden agent is doing. A click on a button opens a list of the panes
hidden on its side, one row per pane in bar order: its status mark, its label,
its tile or its tab's colour, and its name, each in a column of its own. An
agent's tile carries its state, as on its chip, and its row has no other mark. Typing filters the list by name, label or squad. A click or Enter on a row
goes to that pane, a second click on the button closes the list, and a click on
the other button shows that side's list instead. The list is as wide as its
widest row, up to the command palette's width.
zterm ls lists the squad as tab_squad on every pane of the tab, as the
name that set it. A pane whose tab is in no squad has no tab_squad key.
The squad stays with the tab: moving the tab keeps it, and a pane that leaves
the tab for another leaves the squad behind. Closing the tab drops it. It is
not saved, so a new zterm starts with no squads, as it starts with no coloured
tabs. A zterm from before this action answers zterm perform set_tab_squad
with no such action.
The panel
Every window has a panel on its left edge, under the tab bar. It shows the zc dashboard. It is no pane: it has no tab index or title, it stays when you switch tabs or close the last one, and it cannot be split, moved, zoomed or closed.
zterm perform panel --state full|minimal|hidden sets it in the window of the pane it names, or the focused window when it names none, and saves the panel setting for the next window. Other windows keep their panel. Changing the panel setting sets every window. The same three are the actions panel_full, panel_minimal and panel_hidden. zterm perform panel alone is cycle_panel, which switches between full and minimal like the panel's button, and leaves hidden alone. zterm perform reload_panel opens the panel's page again in a new view, for a page that froze; hiding the panel and showing it again does the same. A hidden panel has no view, and opens a new one when it is shown. zterm ls lists panel on every pane of a window: the state drawn there, which is minimal for a window too narrow for full, and hidden where no web view can run. The panel has no keyboard of its own: a click in it hands the keyboard back to the window's pane, unless the click lands in a text field.
The first launch with no settings file opens a setup wizard in the panel: theme, agents, and a first agent. Esc skips a step. The palette's Replay Setup Wizard shows it again.
After that wizard, a five-step tour of the panel opens when the first agent starts. Enter moves on and Esc skips it. Help in the panel's rail replays the tour or the wizard.
Links that focus a pane
A notification, or anything else that can carry a link, can use a URL that brings a pane to the front:
zterm://focus/window:<W>/tab:<T>/pane:<P>
zterm://focus/name:<name>
The part after focus/ is the same as in a workspace:// URI. workspace://
is for passing between programs. zterm:// is the form registered with the
desktop, so the operating system hands a click on it to zterm.
The short form names the pane by the name rename_pane gave it, or zspawn --name did. The three ids change on every restart; the name survives a
relaunch and reads as the agent's name. The rest of the URL after name: is
the name, as it is. A name that no live pane holds is the same miss as a pane
that has closed.
A pane on another machine in your mesh can be named by its id, in the long
form or as zterm focus <id>. If a tab here already shows it, zterm raises
that tab. Otherwise zterm opens it in a new tab, as Open remote pane in the
palette does. Its name is the other machine's, so the name: form finds only
panes here. A link to a pane that no machine lists, or that has ended, is a
miss.
focus is the only action a zterm:// URL can name, and zterm refuses any
other. Any web page can present a zterm:// link, so the most a link can do is
raise a pane, or open a tab showing a pane a machine in your mesh already
runs. Nothing in the URL reaches a shell.
zterm in the URL may be in any case. focus and name: must be lower case.
A link to a pane that has closed does nothing visible. No window or dialog appears. A script can tell the cases apart by exit code.
A zterm://focus/... URL printed in a pane is a link, as an https:// URL
is: the modifier chord underlines it, a chord-click raises the pane, and the
link overlay labels it. The click stays inside zterm and never goes to the
operating system, so it works whether or not the scheme is registered with
the desktop. An agent that prints zterm://focus/name:hawthorn has given the
reader a way to the pane called hawthorn.
zterm ships the registration files for macOS, Linux and Windows, and tests check that they name the right scheme. Whether a click reaches zterm on a real desktop has not been confirmed on any platform, so try it on yours before you rely on it.
Talking to the socket directly
The zterm command is a thin wrapper over a socket that speaks JSON, one
object per line. Anything the command does, your program can do without
starting a process.
| platform | socket |
|---|---|
| macOS | ~/Library/Application Support/zterm/control.sock |
| Linux | $XDG_RUNTIME_DIR/zterm/control.sock |
| Windows | \\.\pipe\zterm-control-<user SID> |
The socket belongs to one user. On Windows the user's SID is in the pipe name so that two signed-in users do not collide, and the pipe's access control list is what keeps other users out.
A request names its kind in cmd. A response names its kind in result:
{"cmd":"list"}
{"cmd":"locate","pid":4242}
{"cmd":"focus","target":"workspace://zestful-terminal/window:01A/tab:01B/pane:01C"}
{"result":"tree","panes":[...]}
{"result":"located","pane":{...}}
{"result":"not_found"}
{"result":"error","message":"..."}
These are examples. The full set of requests and responses is the Request and
Response types in crates/zterm-control/src/protocol.rs in the zterm
repository. That file is the reference, and its tests pin the bytes of each
one.
Rules for reading and writing messages:
- zterm ignores fields it does not know, and your program should too. A newer zterm may add fields.
- There is no version field. If
cmdorresulthas a value the reader does not know, parsing fails. That is how a program learns it is talking to something newer. - Do not branch on the text of
message. It is written for people. - Keys may come in any order. A repeated key is an error.
pidmust be a JSON integer that fits in 32 bits, unsigned.4242.0and"4242"are both rejected. Take care in JavaScript, where every number is a float.pidandttyarenullwhen absent, and both are absent in normal operation.pidisnullwhen a pane has no live process, andttyis alwaysnullon Windows.activation_tokenonfocusis left out when absent. It is nevernull.
One place is strict about unknown fields: the defer object on perform,
which is what --when-idle sends. If defer contains a condition this zterm
does not understand, zterm refuses the request. Ignoring the condition would
mean carrying out the write anyway and answering ok. A condition placed
anywhere outside defer is ignored like any other unknown field and has no
effect.
A perform can carry a deadline. not_after is an integer beside cmd,
in milliseconds since the Unix epoch:
{"cmd":"perform","action":"write","bytes":"ls\r","target":"build","not_after":1790000000000}
A zterm that comes to act on the request at or after that moment does nothing
and answers {"result":"expired"}. Set it to the moment your program stops
waiting for the answer, less a margin for the answer to travel. The zterm
command uses one second. With defer, set it later than timeout_ms, or a
write that waited its turn expires instead of landing. Leave not_after out
and the request has no deadline of yours.
zterm applies a deadline of its own as well. A perform that the main thread
does not reach within two seconds is dropped, whether or not it carried
not_after. expired always means nothing was done.
spawner keeps its connection open. Plain zspawn in a pane sends it to
bring the window's panel forward as a form for choosing an agent:
{"cmd":"spawner","version":1,"pane":"<the pane's id>"}
zterm answers once. {"result":"ok"} means the panel shows the form, and from
then on the connection carries no more requests: zterm and zspawn send each
other one JSON object per line until the person launches or cancels, or zspawn
closes the connection. zterm passes those lines between zspawn and the panel's
page and acts on nothing in them but which call a reply answers and whether
the launch is going ahead. zterm never starts a program from them. When the
session ends the panel goes back to full, minimal or hidden as it was, and its
width is unchanged. If the person sets the panel to another state while the
form is up, the form closes and their choice stands.
zterm answers {"result":"error",...} and closes the connection when:
paneis not the pane of the process on the connection. A program in one pane cannot open the form for another, and a program in no pane cannot open it at all;- the window's panel cannot open a web view, or is showing the setup wizard;
- the panel already shows the form, for this pane or another;
versionis not 1;- the host is
zterm serve, which has no panel.
A page in a web pane cannot send spawner.
Focus on Wayland
On X11, macOS and Windows, zterm asks the window system to bring it to the front. Wayland has no such request. A Wayland compositor gives focus only to a program that holds a token issued to the program that has focus now.
To focus a pane under Wayland, pass your XDG_ACTIVATION_TOKEN unchanged as
activation_token in the focus request.
Other platforms ignore the field, and you may always leave it out. A launcher
sets the variable and it works once, so a zterm focus typed minutes later has
no token to send. That is normal.
zterm serve
zterm serve runs zterm with no window. It lets a server or a build machine
host panes without a GPU or a desktop session. It answers the same socket and
the same ls, locate and focus requests.
It opens one shell when it starts. A program running in one of its panes can open more, as it can in a windowed zterm.
A windowed zterm on another machine in your mesh can open a serve pane in a
tab, watch it and type into it. See Remote panes.
Callers outside its panes
A program running in no pane of a serve host, such as a cron job or a shell
over ssh, is refused every action a windowed zterm would ask a person about:
typing into a pane, reading its screen, renaming it, and opening a pane. The
answer is {"result":"denied","needs":...,"reason":"no_principal"}. This holds
under every value of pane_access_control, open included, because a host
with no window has nobody to ask. Listing, locating and focusing still work for
any caller, and a program running in one of the host's panes is unaffected.
Running more than one zterm
--instance <name> or the ZTERM_INSTANCE variable chooses which socket a
zterm uses. It applies to the windowed terminal, to serve and to every
zterm command. Write --instance=<name> when the name is also a command,
such as --instance=serve.
A name is 1 to 32 characters from a-z, 0-9, _ and -. zterm refuses
anything else, capital letters included, and does not convert it. File names on
macOS and pipe names on Windows ignore case, so Work and work would be the
same socket there while looking like two instances.
The name changes only the last part of the socket's path:
| platform | default | --instance work |
|---|---|---|
| macOS | ~/Library/Application Support/zterm/control.sock |
~/Library/Application Support/zterm/control-work.sock |
| Linux | $XDG_RUNTIME_DIR/zterm/control.sock |
$XDG_RUNTIME_DIR/zterm/control-work.sock |
| Windows | \\.\pipe\zterm-control-<user SID> |
\\.\pipe\zterm-control-<user SID>-work |
A named instance does not join the mesh unless ZTERM_MESH=on or
ZTERM_MESH_SECRET is set, so it neither sees nor touches another machine's
panes. See "Named instances stay off the mesh" in remote-panes.md.
Starting a zterm without taking the keyboard
A zterm started from a script or an agent's shell comes to the front and takes
the keyboard, so whatever the person at the machine was typing goes into it.
Set ZTERM_PROBE=1 on a private instance to stop that:
ZTERM_PROBE=1 ZTERM_INSTANCE=probe zterm
Its windows open without taking focus. On macOS zterm does not become the active app, and each window is placed in front of other apps' windows without taking the keyboard, so it keeps drawing and a screenshot by window id works. On Windows the window opens without activating. On Linux X11 and Wayland decide; zterm cannot ask them not to focus a new window.
zterm focus against that instance moves focus between its panes and never
activates zterm. On macOS it also places the window in front, as above.
ZTERM_PROBE is read only with --instance or ZTERM_INSTANCE. On the default
instance zterm says so on stderr and starts as usual.
focus succeeds and raises nothing
A serve host answers focus with {"result":"ok"} and marks the pane as the
active one. It has no window, so nothing comes to the front. The response is
identical to a windowed zterm's, so a client cannot tell from the response
whether anything was raised.
--when-idle on a serve host
--when-idle delays a write while someone has an unsent line in the pane, and
then until nobody is typing there. A serve host has no keyboard. Everyone
who types into its panes does so from a windowed zterm on another machine, and
each of those tells the host when it has an unsent line there.
So a write with --when-idle from another machine works: the host holds it
until nobody has an unsent line in the pane and nobody has typed there for
idle.debounce_ms, as set on the host. When --when-idle=<time> runs out,
nothing is written and the answer is the same idle_timeout a local write
gives, with the same reason.
A host running zterm 0.9.63 or older cannot hold the write, and the write is
refused with a message saying so. Send it without --when-idle, or update
that machine.
A program running on the serve host itself waits the same way. Its
zterm perform write --when-idle is held until nobody on another machine has
an unsent line in the pane or has typed there recently.
pid and tty belong to the machine that hosts the pane
A pane's pid and tty describe the machine the pane runs on. zterm ls can
include panes on other machines:
- A pane with no
nodefield is local. Itspidandttyare processes and devices on the machine you asked. - A pane with a
nodefield is remote. Itspid,ttyandtitleare whatever that machine reported. The connection between the machines proves that the other machine belongs to your mesh. It does not prove that what the machine reports is true.
Local panes leave node out entirely. It is never null. A tool written
before remote panes existed therefore still parses the list, and it sees every
remote pane as local. For actions on the uri the damage is limited, because
zterm focus refuses a remote URI. A tool that acts on pid, by killing it,
attaching to it or running ps on it, would act on a local process whose
number a remote machine chose.
If your tool uses pid or tty, filter on node first. Every example on this
page that matches on tty does.
The window size is made up
A serve pane always opens at 80×24. With no display to measure, it also
reports a pixel size of about 672×408 to its programs (ws_xpixel and
ws_ypixel). That size describes no real screen.
This matters if you run an image tool, such as a sixel viewer, in a shell on a
serve host. The tool reads the pixel size to decide how big to draw, and it
gets a plausible number that means nothing. Do not size anything from a serve
pane's reported dimensions.
Once a windowed zterm opens the pane, the pane takes the size of that tab, or of the smallest tab when several machines have it open. See Remote panes.
Events
Everything on this page is a request to the terminal. zterm can also send
events outward, over HTTP on the local machine. This is off unless you set
send_events = true or ZESTFUL_EVENTS_URL. See Events.