Skip to content

How it works

nomux runs three types of process on a Host: the client, the daemon and the holder. This page describes what exists in nomux 0.5.0. The concepts overview describes the full design.

The three nomux processes and the disk The client connects to the daemon through a Unix socket. The daemon connects to one holder for each Session through a control socket, and it reads the terminal output of the Session from shared memory of the holder. The holder owns the PTY of the command and writes the description and the journal of the Session to the disk. The daemon reads the disk to find the Sessions after a restart. The holder and the command continue when the daemon stops. client: nomux (the CLI) runs one command, or stays attached Unix socket ~/.nomux/run/nomuxd.sock daemon: nomuxd one for each user: starts and finds holders reads at its start control socket ~/.nomux/run/<id>/sock terminal output: shared memory holder: nomux-holder one for each Session: owns the PTY disk description, journal PTY command of the Session a shell, an agent, a server continue when the daemon stops
An arrow points from the process that connects to the process that answers, or from the writer to the disk. The PTY carries data in the two directions. During an attach, the Unix socket of the daemon carries the keys to the Session and the terminal output to the client. The disk is the state directory of the user: it stays after a restart of the Host.

The client is the program that you use. Now the only client is the CLI, nomux. It reads the command line, connects to the daemon, sends its request, prints the result and ends. For an attach, it stays connected and gives your keyboard and your screen to the Session. If no daemon runs, the CLI starts one. For a remote Host, the CLI connects to the daemon of that Host through SSH, and the daemon and the holders run there.

The daemon is nomuxd. One daemon runs for each user. It starts a holder for each new Session, keeps the list of the Sessions and answers the clients. It carries the keys and the terminal output between an attached client and the holder. It owns no terminal. It also runs the daemon parts of the extensions, each as a separate process. It keeps the agent status of each Session, and it keeps a few holders ready for new Sessions: the holder pool.

The holder is nomux-holder. One holder runs for each Session. It opens the PTY, starts the command of the Session and reads the output of the command, also when no client and no daemon is connected. It keeps the current screen of the Session in memory: the visible cells with their colours, the cursor and the terminal modes. It writes the description of the Session and its output to the disk: refer to The journal. It also reads what the programs report in their output: the program status (the OSC 7501 terminal sequence), the prompt marks of a shell (OSC 133) and notifications (OSC 9 and OSC 777). The daemon uses the first two for the agent status. No command shows the notifications in this version. A holder is a small process with one thread. It does no work while the command writes nothing.

A client talks only to the daemon. Only the daemon talks to a holder.

nomux attach and nomux new --attach connect your terminal to the terminal of a Session. You name the Session with a target: its identifier, its name, or the start of one of the two. The quick start shows it with real commands.

  1. The window size. The CLI sends the size of your terminal, and the Session gets that size.
  2. The screen. The daemon asks the holder for the current screen. The holder gives a byte sequence that draws that screen in an empty terminal. The CLI writes the sequence to your terminal. Thus you see the Session as it is now, also if its programs drew the screen hours before.
  3. The output stream. After the screen, the client gets each byte that the command writes, in sequence. The screen and the stream fit together: no byte is absent and no byte comes two times.
  4. The keys. Each key goes from the CLI to the daemon, to the holder and into the PTY. Only the keys after a prefix key (Ctrl-a or Ctrl-\ by default) are for nomux: d detaches.

The holder does not know the clients and never waits for one. It keeps the most recent 256 KiB of output in memory, and the daemon has one buffer of 64 KiB for each client. A slow client gets a fresh screen. If a client takes its output more slowly than the command writes it, and the output that it needs next is no longer in the memory of the holder, the daemon sends the current screen again and continues from there. That client gets the latest screen and not the bytes between. Thus a flood of output does not make the memory of the daemon grow and does not slow the command. A slow client changes nothing for a different client of the same Session.

More than one client can be attached to one Session. Each client gets the same output, and each one can type. A Session has one window size: the size of the client that attached or changed its size last.

A detach closes only the connection of the client. The command of the Session gets no signal and sees no change. An attach goes through the daemon. If the daemon stops, the attach ends with an error, and the Session continues: attach again, and the new daemon gets the screen from the holder.

An attach shows the screen, not the lines that left the screen. nomux capture prints these lines from the journal.

Why a Session continues when the daemon stops

Section titled “Why a Session continues when the daemon stops”

The command of a Session is a child of its holder, not of the daemon. The terminal of the command belongs to the holder. Thus the end of the daemon closes no terminal and stops no command.

The holder is also independent of the process that started it:

  • It has its own process session and its own process group. A signal for the daemon or for its group does not reach the holder.
  • The holder of a Session has no pipe to the daemon. It does not fail when the daemon is gone.
  • It writes three files into the runtime directory. A new daemon reads these files, finds the holder and connects to it.

When a daemon starts, it scans the runtime directory. It connects to each holder that runs, and removes the directory of each holder that is gone. This is why nomux ls shows the same Sessions after nomux daemon stop, after kill -9 of the daemon and after a daemon failure. The quick start shows it with real commands.

Only one daemon can run for one runtime directory. A second daemon ends with an error and changes nothing. nomuxd --replace stops the daemon that runs and takes its place, and no Session ends.

A holder in the holder pool is the exception: it has no Session yet, and it ends with the daemon.

The holder writes the output of its Session to the journal on disk, in the state directory of the user. The journal has the bytes as the command wrote them and, at intervals, a checkpoint: a copy of the screen at that position.

  • The holder writes the output to the journal 1 second after it read it, or earlier after 64 KiB. It does not wait for the disk while the command runs.
  • The holder writes a checkpoint at the start, after each 1 MiB of output and after a change of the window size.
  • The journal of one Session has 32 MiB of files at most. The holder removes the oldest files first. 32 MiB hold 50 MiB to 90 MiB of terminal output.
  • If the disk is full, the holder stops the journal and the Session continues.

The holder also writes a description of the Session to the state directory: the command and its arguments, the working directory, the window size, the start time and, after the end, the exit status. The description has no environment variable, because the environment can have secrets.

nomux capture reads the journal. Thus it prints lines that left the screen, and the output of a Session whose command stopped.

The daemon keeps the agent status of each Session: what runs in it, its state (idle, working, done, needs you or error) and the source of that state. A client can always tell the report of a program from a guess of the daemon. A guess is never shown as a fact.

The daemon asks six sources in a fixed order. The first source that reports an item gives its state:

Order Source What it is
1 Adapter An adapter extension that reports from the hook events of an agent tool
2 Program status A program reports in the terminal stream (OSC 7501)
3 Self-report A program in the Session runs nomux status set
4 Session restore The Session lost its process: what stays of its status
5 Prompt marks The prompt marks of the shell: a command runs, or the input line waits. This is a guess
6 Foreground program A program that is not the command of the Session has the terminal. This is a guess
  • nomux status prints one row for each Session, and (guess) marks a guess. nomux status --tree adds the Child work and the Groups and Projects with the most urgent status below them. nomux agent explain <target> prints each source in this order with what it says. nomux events -f prints each change when it happens.
  • The most urgent status decides the status of the Session, and of a Group or a Project: needs you first, then an error or a done that you did not see, then working. An attach marks the results of the Session as seen.
  • A Session without a process runs no work. When a Session becomes dormant, its working and needs you become done with the source “session restore”. An ended Session keeps its last Agent run, the kept run, until the daemon removes the Session. The daemon keeps 64 kept runs at most.
  • The daemon keeps no status on disk. After the daemon starts again, it reads the program reports from the holders. The self-reports, the reports of the adapters, the times in the state and the events are gone.

An adapter is an extension that takes the hook events of one agent tool. The tool runs nomux hook <tool> <event> at its events. The command sends the event to the daemon and waits 80 ms at most. Its exit code is always 0, thus it never blocks or breaks the tool. The daemon checks the token of the Session, gives the event to the adapter, and the adapter reports the status.

nomux hooks install <tool> prints the change that the hooks need in the settings file of the tool. It writes the file only with --apply. In this version a hook gets no answer from nomux: nomux decides no permission request yet.

The adapter of Claude Code is in the extensions repository and has release 0.1.0: the extensions page says what exists. The guides Agent status, Agent adapters and hooks and Claude Code adapter show the commands.

A new Session must open in less than 10 ms, and a shell with its start files can need 200 ms or more. Thus the daemon keeps a few holders ready: 2 by default. Each pooled holder has started the shell of the user in the home directory. A new Session with the shell takes the oldest pooled holder, and no process starts. Performance targets has the measured times.

  • The pool starts at the first request of a client. A daemon that gets no request runs no pooled holder.
  • After 10 minutes without a new Session, the pool empties. pool.size (0 to 8) and pool.idle_time in config.toml change the pool. With 0, the pool is off.
  • A pooled holder is not a Session. nomux ls does not show it, and it has no state directory and no journal. Its standard input is a pipe from the daemon: when the daemon ends, also after kill -9, the pooled holder and its shell end. A new daemon takes no pooled holder of an earlier daemon.
  • If the Session has a working directory that is not the home directory, the shell changes to it before its first prompt, and nothing is typed into the terminal. This works for bash, zsh and fish: the daemon starts them with a start file of nomux, which reads the directory from a named pipe of the holder. A Session in a different directory with another shell gets a new holder.
  • A Session with a command always gets a new holder. The pool is off if the shell of the user is not sh, bash, zsh, dash, ksh, mksh or fish, and while sessions.memory_limit is set.
  • A pooled holder and its shell use memory while they wait: approximately 1 MB for the holder with the musl build, and the memory of the shell.

The guide Holder pool shows the pool with real commands.

The holder makes the environment of the command. It starts with the environment of the daemon and sets these variables:

Variable Value
TERM xterm-256color
COLORTERM truecolor
NOMUX_SESSION_ID The session identifier
NOMUX_SOCK The socket of the daemon
NOMUX_TOKEN A random token of 128 bits for each start of the holder. A restore gives a new token
  • TERM is the terminal of nomux, not the terminal of a client: a Session has clients with different terminals at different times.
  • If the daemon has no locale (LC_ALL, LC_CTYPE and LANG have no value), the command gets a UTF-8 character set. The variables COLUMNS, LINES, TERM_PROGRAM and TERM_PROGRAM_VERSION are never passed.
  • Nothing comes from the client. A client with another locale, or with SSH_AUTH_SOCK, does not give them to its Session.
  • A program in the Session uses the three NOMUX_ variables to tell the daemon which Session it is in, for example nomux status set and nomux hook. The token proves that a request comes from a process of the Session. No file has it. It does not protect against another process of the same user, which can read the environment too.

The guide Environment of a Session has the details.

nomux ls --memory shows the memory of the processes of each Session: the command and each process that descends from it, the number of these processes, and the holder as a separate value. The measure is pss on Linux. It is rss on macOS, and on Linux for a Session that has a process whose pss the kernel does not give.

  • The daemon measures only when a client asks. It has no timer and keeps no value between two requests, thus an idle daemon uses no CPU time.
  • A Session without a process has no values.
  • A process that left the process tree of the holder, as a program that makes itself a daemon does, is not counted.
  • sessions.memory_limit limits the memory of a Session. On Linux with a systemd user manager and control groups of version 2, the kernel applies the limit. On other hosts, the limit is only a threshold of the hibernation.

The guide Memory of Sessions explains the two measures.

An idle agent Session uses memory for nothing. The daemon can stop its agent and keep the Session: its output, its last Agent run and the resume command that its adapter reported. The Session is then hibernated, and nomux ls shows it as hibernated. nomux attach or nomux wake starts the resume command again.

  • A Session hibernates only if its adapter gave a resume command, nothing runs and nothing waits for you, no client shows it, and you did not pin it. A Session that works, or that waits for a permission, a question or a login, never hibernates.
  • The triggers are the number of live agent Sessions (12 by default), a memory threshold and, on Linux, the memory pressure of the Host.
  • One task of the daemon applies the triggers. It does not poll: an idle daemon uses no CPU time.

The guide Hibernation and the memory limit has the commands, the settings and the platform differences.

A Unix socket path has 107 bytes at most on Linux and 103 bytes at most on macOS. If the longest socket path of ~/.nomux/run has more than 103 bytes, which a home directory of more than 73 bytes causes, nomux opens the runtime directory through the symbolic link /tmp/nomux-<hash>. The files stay in ~/.nomux/run. The link gives them a short path, and NOMUX_SOCK has that path. nomux makes the link again if a cleanup of /tmp removed it. The rule uses the limit of macOS on each host, thus a client knows the socket of a remote Host from its home directory only.

The guide Long home directories has the details.

A restart ends each process, also each holder and each command. The state directory stays. When the daemon starts again, it reads the state directory. A Session whose description says that its command ran, and that has no holder, is dormant: nomux ls shows it with its command and without a process.

A restore starts the command of a dormant Session again: the daemon starts a new holder with the same session identifier, the same command, the same working directory and the same window size. The new holder writes to the same journal, and the Session gets the next epoch. The restore policy of the Session decides when this happens: when the daemon starts, at the first attach, or only with nomux start.

The processes of the Session from before the restart do not come back. The new command starts from the beginning. The output from before stays in the journal, and an attach shows its end above the new screen.

The same thing happens when a holder is killed with SIGKILL, or when it fails: the Session becomes dormant. After a restart shows it with real commands.

  • Its command ends, or you end it with nomux kill. The daemon keeps the ended Session, its exit status and its journal for the retention time, 24 hours by default. nomux ls --all shows it. The daemon keeps its last Agent run too: the kept run.
  • You remove a dormant Session with nomux kill. Its journal is removed too.
  • A service manager stops all the processes of the daemon together. The service file of nomux daemon install-service has KillMode=process, thus a stop of that unit stops only the daemon. With the default KillMode=control-group of systemd, a stop of the unit ends the holders too, and the Sessions become dormant.
Data Where Lifetime
The PTY and the command The holder process Until the command ends, or the holder ends
The current screen and the most recent 256 KiB of output The memory of the holder Until the holder ends
The reports of the programs: 64 program status records at most, the last prompt mark and the last 16 notifications The memory of the holder Until the holder ends
The list of the Sessions The memory of the daemon A new daemon makes it again from the runtime directory and the state directory
The agent status of each Session, the kept runs (64 at most) and the events (1024 at most) The memory of the daemon Until the daemon ends. A new daemon reads the program reports from the holders again and starts with no event
nomuxd.sock, nomuxd.lock, nomuxd.log ~/.nomux/run/ The socket, the lock and the log of the daemon. The log stays empty if there is no problem
pid, sock, ready ~/.nomux/run/<session identifier>/ The files of one holder. The holder removes them when it ends
pid, sock, ready ~/.nomux/run/<session identifier>.pool/ The files of a pooled holder. The directory has the plain session identifier when a Session takes the holder
The socket link /tmp/nomux-<hash> Only for a long home directory. nomux makes it again if it is gone
session, restore-policy, name, hibernation, pinned, holder-panic, journal/ ~/.local/state/nomux/sessions/<session identifier>/ on Linux, ~/Library/Application Support/nomux/sessions/<session identifier>/ on macOS The description, the restore policy, the name, the hibernation, the pin and the journal of one Session. Only the files that apply exist: a Session without a name has no name, and holder-panic exists only after a failure of the holder. They stay after a restart, until nomux kill of a dormant Session or the end of the retention time of an ended Session
workspace.json ~/.local/state/nomux/ on Linux, ~/Library/Application Support/nomux/ on macOS The Groups and the Projects of the Host: Projects and Groups. The daemon reads it when it starts
The installed extensions ~/.local/share/nomux/extensions/ on Linux, ~/Library/Application Support/nomux/extensions/ on macOS Until nomux ext rm
The record of the installed hooks of a tool ~/.local/share/nomux/hooks/<tool>/ on Linux, ~/Library/Application Support/nomux/hooks/<tool>/ on macOS nomux hooks install <tool> --apply writes it. It stays after a restart, and nomux hooks uninstall <tool> reads it
The remote Hosts, the restore policy for new Sessions, the retention time, the keys of the holder pool, the memory limits, the hibernation settings and the prefix keys of an attach ~/.config/nomux/config.toml on Linux, ~/Library/Application Support/nomux/config.toml on macOS Until you change the file. nomux host add writes it. The daemon reads it when it starts

This is the state directory of one Session after a restore. The run stopped each nomux process with kill -9, as a restart does, and then ran nomux start mvbu4p5p:

Terminal window
$ ls -A .local/state/nomux/sessions/mvbu4p5p
journal
session
$ ls -A .local/state/nomux/sessions/mvbu4p5p/journal
00000001-0000000000000000.journal
00000002-0000000000000000.journal
$ cat .local/state/nomux/sessions/mvbu4p5p/session
nomux-session 1
epoch 2
started 1795705715
rows 24
columns 80
restore on-focus
profile
directory /home/user/project
command sh
argument -c
argument echo first run; exec sleep 600
status running

Each journal file is one segment. The name has the epoch and the position of the first byte of the segment. The two files are the output of the first run of the command and of the run after the restore. The restore line of the session file is not the restore policy: the daemon keeps the policy in the file restore-policy. This Session has no such file, thus it has the default policy.

The directories have the mode 0700, and the files and each socket have the mode 0600. The daemon and the holders also close a connection that comes from a different user. nomux has no database.

  • An attach shows the current screen of a Session and the output from that moment. It does not show the lines that left the screen. nomux capture prints them with their escape sequences.
  • An attach that starts a dormant Session again shows 1 MiB of the old output at most.
  • The command of a Session gets the environment of the daemon, thus of the shell that started the daemon, with the changes of the environment of a Session. A restore gives the command the environment of the daemon at that time. Its terminal has 24 rows and 80 columns until a client attaches.
  • The Claude Code adapter has release 0.1.0. A tool that sends no OSC 7501 has only the self-report and the two guesses as sources.
  • The size limit of the journal is fixed at 32 MiB for each Session.

The roadmap is the one place for the work that comes next. The reasons for the process model are in ADR-0001. The budgets for disk and memory are in ADR-0009. The terms on this page come from the Glossary.