neurosnap/zmx
{ "createdAt": "2025-10-10T19:51:40Z", "defaultBranch": "main", "description": "Session persistence for terminal processes", "fullName": "neurosnap/zmx", "homepage": "https://zmx.sh", "language": "Zig", "name": "zmx", "pushedAt": "2026-01-10T01:03:45Z", "stargazersCount": 683, "topics": [ "ghostty", "session-persistence", "tmux", "zig" ], "updatedAt": "2026-01-17T23:56:01Z", "url": "https://github.com/neurosnap/zmx"}session persistence for terminal processes
Reason for this tool: You might not need tmux
features
Section titled “features”- Persist terminal shell sessions (pty processes)
- Ability to attach and detach from a shell session without killing it
- Native terminal scrollback
- Multiple clients can connect to the same session
- Re-attaching to a session restores previous terminal state and output
- Send commands to a session without attaching to it
- Print scrollback history of a terminal session in plain text
- Works on mac and linux
- This project does NOT provide windows, tabs, or splits
install
Section titled “install”binaries
Section titled “binaries”- https://zmx.sh/a/zmx-0.2.0-linux-aarch64.tar.gz
- https://zmx.sh/a/zmx-0.2.0-linux-x86_64.tar.gz
- https://zmx.sh/a/zmx-0.2.0-macos-aarch64.tar.gz
- https://zmx.sh/a/zmx-0.2.0-macos-x86_64.tar.gz
homebrew
Section titled “homebrew”brew tap neurosnap/tapbrew install zmx- Requires zig
v0.15 - Clone the repo
- Run build cmd
zig build -Doptimize=ReleaseSafe --prefix ~/.local# be sure to add ~/.local/bin to your PATH[!IMPORTANT] We recommend closing the terminal window to detach from the session but you can also press
ctrl+\or runzmx detach.
Usage: zmx <command> [args]
Commands: [a]ttach <name> [command...] Attach to session, creating session if needed [r]un <name> [command...] Send command without attaching, creating session if needed [d]etach Detach all clients from current session (ctrl+\ for current client) [l]ist List active sessions [k]ill <name> Kill a session and all attached clients [hi]story <name> [--vt|--html] Output session scrollback (--vt or --html for escape sequences) [v]ersion Show version information [h]elp Show this help messageexamples
Section titled “examples”zmx attach dev # start a shell sessionzmx a dev nvim . # start nvim in a persistent sessionzmx attach build make -j8 # run a build, reattach to check progresszmx attach mux dvtm # run a multiplexer inside zmx
zmx run dev cat README.md # run the command without attaching to the sessionzmx r dev cat CHANGELOG.md # aliasecho "ls -lah" | zmx r dev # use stdin to run the commandshell prompt
Section titled “shell prompt”When you attach to a zmx session, we don’t provide any indication that you are inside zmx. We do provide an environment variable ZMX_SESSION which contains the session name.
We recommend checking for that env var inside your prompt and displaying some indication there.
Place this file in ~/.config/fish/config.fish:
functions -c fish_prompt _original_fish_prompt 2>/dev/null
function fish_prompt --description 'Write out the prompt' if set -q ZMX_SESSION echo -n "[$ZMX_SESSION] " end _original_fish_promptendbash and zsh
Section titled “bash and zsh”Depending on the shell, place this in either .bashrc or .zshrc:
if [[ -n $ZMX_SESSION ]]; then export PS1="[$ZMX_SESSION] ${PS1}"fipowerlevel10k zsh theme
Section titled “powerlevel10k zsh theme”powerlevel10k is a theme for zsh that overwrites the default prompt statusline.
Place this in .zshrc:
function prompt_my_zmx_session() { if [[ -n $ZMX_SESSION ]]; then p10k segment -b '%k' -f '%f' -t "[$ZMX_SESSION]" fi}POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=my_zmx_sessionoh-my-posh
Section titled “oh-my-posh”oh-my-posh is a popular shell themeing and prompt engine. This code will display an icon and session name as part of the prompt if (and only if) you have zmx active:
[[blocks.segments]] template = '{{ if .Env.ZMX_SESSION }} {{ .Env.ZMX_SESSION }}{{ end }}' foreground = 'p:orange' background = 'p:black' type = 'text' style = 'plain'philosophy
Section titled “philosophy”The entire argument for zmx instead of something like tmux that has windows, panes, splits, etc. is that job should be handled by your os window manager. By using something like tmux you now have redundant functionality in your dev stack: a window manager for your os and a window manager for your terminal. Further, in order to use modern terminal features, your terminal emulator and tmux need to have support for them. This holds back the terminal enthusiast community and feature development.
Instead, this tool specifically focuses on session persistence and defers window management to your os wm.
ssh workflow
Section titled “ssh workflow”Using zmx with ssh is a first-class citizen. Instead of using ssh to remote into your system with a single terminal and n tmux panes, you open n terminals and run ssh for all of them. This might sound tedious, but there are tools to make this a delightful workflow.
First, create an ssh config entry for your remote dev server:
Host = d.* HostName 192.168.1.xxx
RemoteCommand zmx attach %k RequestTTY yes ControlPath ~/.ssh/cm-%r@%h:%p ControlMaster auto ControlPersist 10mNow you can spawn as many terminal sessions as you’d like:
ssh d.termssh d.ircssh d.picossh d.dotfilesThis will create or attach to each session and since we are using ControlMaster the same ssh connection is reused for every call to ssh for near-instant connection times.
Now you can use the autossh tool to make your ssh connections auto-reconnect. For example, if you have a laptop and close/open your laptop lid it will automatically reconnect all your ssh connections:
autossh -M 0 -q d.termOr create an alias/abbr:
abbr -a ash "autossh -M 0 -q"ash d.termash d.ircash d.picoash d.dotiflesWow! Now you can setup all your os tiling windows how you like them for your project and have as many windows as you’d like, almost replicating exactly what tmux does but with native windows, tabs, splits, and scrollback! It also has the added benefit of supporting all the terminal features your emulator supports, no longer restricted by what tmux supports.
socket file location
Section titled “socket file location”Each session gets its own unix socket file. The default location depends on your environment variables (checked in priority order):
ZMX_DIR=> uses exact path (e.g.,/custom/path)XDG_RUNTIME_DIR=> uses{XDG_RUNTIME_DIR}/zmx(recommended on Linux, typically results in/run/user/{uid}/zmx)TMPDIR=> uses{TMPDIR}/zmx-{uid}(appends uid for multi-user safety)/tmp=> uses/tmp/zmx-{uid}(default fallback, appends uid for multi-user safety)
debugging
Section titled “debugging”We store global logs for cli commands in {socket_dir}/logs/zmx.log. We store session-specific logs in {socket_dir}/logs/{session_name}.log. Right now they are enabled by default and cannot be disabled. The idea here is to help with initial development until we reach a stable state.
a note on configuration
Section titled “a note on configuration”We are evaluating what should be configurable and what should not. Every configuration option is a burden for us maintainers. For example, being able to change the default detach shortcut is difficult in a terminal environment.
a smol contract
Section titled “a smol contract”- Write programs that solve a well defined problem.
- Write programs that behave the way most users expect them to behave.
- Write programs that a single person can maintain.
- Write programs that compose with other smol tools.
- Write programs that can be finished.
known issues
Section titled “known issues”- Terminal state rehydration with nested
zmxsessions through SSH: host Azmx-> SSH -> host Bzmx- Specifically cursor position gets corrupted
- When re-attaching and kitty keyboard mode was previously enable, we try to re-send that CSI query to re-enable it
- Some programs don’t know how to handle that CSI query (e.g.
psql) so when you type it echos kitty escape sequences erroneously
- Some programs don’t know how to handle that CSI query (e.g.
- The
daemonand client processes communicate via a unix socket - Both
daemonandclientloops leveragepoll() - Each session creates its own unix socket file
- We restore terminal state and output using
libghostty-vt
libghostty-vt
Section titled “libghostty-vt”We use libghostty-vt to restore the previous state of the terminal when a client re-attaches to a session.
How it works:
- user creates session
zmx attach term - user interacts with terminal stdin
- stdin gets sent to pty via daemon
- daemon sends pty output to client and
ghostty-vt ghostty-vtholds terminal state and scrollback- user disconnects
- user re-attaches to session
ghostty-vtsends terminal snapshot to client stdout
In this way, ghostty-vt doesn’t sit in the middle of an active terminal session, it simply receives all the same data the client receives so it can re-hydrate clients that connect to the session. This enables users to pick up where they left off as if they didn’t disconnect from the terminal session at all. It also has the added benefit of being very fast, the only thing sitting in-between you and your PTY is a unix socket.
prior art
Section titled “prior art”Below is a list of projects that inspired me to build this project.
shpool
Section titled “shpool”You can find the source code at this repo: https://github.com/shell-pool/shpool
shpool is a service that enables session persistence by allowing the creation of named shell sessions owned by shpool so that the session is not lost if the connection drops.
shpool can be thought of as a lighter weight alternative to tmux or GNU screen. While tmux and screen take over the whole terminal and provide window splitting and tiling features, shpool only provides persistent sessions.
The biggest advantage of this approach is that shpool does not break native scrollback or copy-paste.
abduco
Section titled “abduco”You can find the source code at this repo: https://github.com/martanne/abduco
abduco provides session management i.e. it allows programs to be run independently from its controlling terminal. That is programs can be detached - run in the background - and then later reattached. Together with dvtm it provides a simpler and cleaner alternative to tmux or screen.
You can find the source code at this repo: https://github.com/crigler/dtach
A simple program that emulates the detach feature of screen.
dtach is a program written in C that emulates the detach feature of screen, which allows a program to be executed in an environment that is protected from the controlling terminal. For instance, the program under the control of dtach would not be affected by the terminal being disconnected for some reason.
comparison
Section titled “comparison”| Feature | zmx | shpool | abduco | dtach | tmux |
|---|---|---|---|---|---|
| 1:1 Terminal emulator features | ✓ | ✓ | ✓ | ✓ | ✗ |
| Terminal state restore | ✓ | ✓ | ✗ | ✗ | ✓ |
| Window management | ✗ | ✗ | ✗ | ✗ | ✓ |
| Multiple clients per session | ✓ | ✗ | ✓ | ✓ | ✓ |
| Native scrollback | ✓ | ✓ | ✓ | ✓ | ✗ |
| Configurable detach key | ✗ | ✓ | ✓ | ✓ | ✓ |
| Auto-daemonize | ✓ | ✓ | ✓ | ✓ | ✓ |
| Daemon per session | ✓ | ✗ | ✓ | ✓ | ✗ |
| Session listing | ✓ | ✓ | ✓ | ✗ | ✓ |