{"id":33863469,"url":"https://github.com/neurosnap/zmx","last_synced_at":"2026-03-06T19:09:52.060Z","repository":{"id":318984400,"uuid":"1073900202","full_name":"neurosnap/zmx","owner":"neurosnap","description":"Session persistence for terminal processes","archived":false,"fork":false,"pushed_at":"2025-12-09T05:24:40.000Z","size":264,"stargazers_count":486,"open_issues_count":6,"forks_count":10,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-12-09T09:36:53.708Z","etag":null,"topics":["ghostty","tmux","zig"],"latest_commit_sha":null,"homepage":"https://zmx.sh","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neurosnap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2025-10-10T19:51:40.000Z","updated_at":"2025-12-09T08:52:57.000Z","dependencies_parsed_at":"2025-10-17T15:30:01.176Z","dependency_job_id":"687388f3-c969-4eb0-b374-c7426a3b8522","html_url":"https://github.com/neurosnap/zmx","commit_stats":null,"previous_names":["neurosnap/zmx"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/neurosnap/zmx","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neurosnap%2Fzmx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neurosnap%2Fzmx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neurosnap%2Fzmx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neurosnap%2Fzmx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neurosnap","download_url":"https://codeload.github.com/neurosnap/zmx/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neurosnap%2Fzmx/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27725914,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-14T02:00:11.348Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ghostty","tmux","zig"],"created_at":"2025-12-09T11:00:31.925Z","updated_at":"2026-03-06T19:09:52.046Z","avatar_url":"https://github.com/neurosnap.png","language":"Zig","funding_links":[],"categories":["Fundamentals","Zig","Core \u0026 Libraries"],"sub_categories":["Utility"],"readme":"\u003ch1\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./docs/logo.png\" alt=\"Logo\" width=\"128\"\u003e\n  \u003cbr\u003ezmx\n\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  Session persistence for terminal processes.\n  \u003cbr /\u003e\n  \u003ca href=\"https://zmx.sh\"\u003eDocs\u003c/a\u003e\n  ·\n  \u003ca href=\"https://bower.sh/you-might-not-need-tmux\"\u003eYou might not need tmux\u003c/a\u003e\n  ·\n  Sponsored by \u003ca href=\"https://pico.sh\"\u003epico.sh\u003c/a\u003e\n\u003c/p\u003e\n\n## features\n\n- Persist terminal shell sessions (pty processes)\n- Ability to attach and detach from a shell session without killing it\n- Native terminal scrollback\n- Multiple clients can connect to the same session\n- Re-attaching to a session restores previous terminal state and output\n- Send commands to a session without attaching to it\n- Print scrollback history of a terminal session in plain text\n- Works on mac and linux\n- This project does **NOT** provide windows, tabs, or splits\n\n## install\n\n### binaries\n\n- https://zmx.sh/a/zmx-0.4.1-linux-aarch64.tar.gz\n- https://zmx.sh/a/zmx-0.4.1-linux-x86_64.tar.gz\n- https://zmx.sh/a/zmx-0.4.1-macos-aarch64.tar.gz\n- https://zmx.sh/a/zmx-0.4.1-macos-x86_64.tar.gz\n\n### homebrew\n\n```bash\nbrew install neurosnap/tap/zmx\n```\n\n### packages\n\n- [Alpine Linux](https://pkgs.alpinelinux.org/package/edge/testing/x86_64/zmx)\n- [Arch AUR tracking releases](https://aur.archlinux.org/packages/zmx)\n- [Arch AUR tracking git](https://aur.archlinux.org/packages/zmx-git)\n\n### src\n\n- Requires zig `v0.15`\n- Clone the repo\n- Run build cmd\n\n```bash\nzig build -Doptimize=ReleaseSafe --prefix ~/.local\n# be sure to add ~/.local/bin to your PATH\n```\n\n## usage\n\n\u003e [!IMPORTANT]\n\u003e We recommend closing the terminal window to detach from the session but you can also press `ctrl+\\` or run `zmx detach`.\n\n```\nUsage: zmx \u003ccommand\u003e [args]\n\nCommands:\n  [a]ttach \u003cname\u003e [command...]   Attach to session, creating session if needed\n  [r]un \u003cname\u003e [command...]      Send command without attaching, creating session if needed\n  [d]etach                       Detach all clients from current session  (ctrl+\\ for current client)\n  [l]ist [--short]               List active sessions\n  [c]ompletions \u003cshell\u003e          Completion scripts for shell integration (bash, zsh, or fish)\n  [k]ill \u003cname\u003e                  Kill a session and all attached clients\n  [hi]story \u003cname\u003e [--vt|--html] Output session scrollback (--vt or --html for escape sequences)\n  [w]ait \u003cname\u003e...               Wait for session tasks to complete\n  [v]ersion                      Show version information\n  [h]elp                         Show this help message\n```\n\n### examples\n\n```bash\nzmx attach dev              # start a shell session\nzmx a dev nvim .            # start nvim in a persistent session\nzmx attach build make -j8   # run a build, reattach to check progress\nzmx attach mux dvtm         # run a multiplexer inside zmx\n\nzmx run dev cat README.md   # run the command without attaching to the session\nzmx r dev cat CHANGELOG.md  # alias\necho \"ls -lah\" | zmx r dev  # use stdin to run the command\n\nzmx r tests go test ./...   # run your tests in the background\nzmx wait tests              # waits for tests to complete\n```\n\n## shell prompt\n\nWhen 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.\n\nWe recommend checking for that env var inside your prompt and displaying some indication there.\n\n### fish\n\nPlace this file in `~/.config/fish/config.fish`:\n\n```fish\nfunctions -c fish_prompt _original_fish_prompt 2\u003e/dev/null\n\nfunction fish_prompt --description 'Write out the prompt'\n  if set -q ZMX_SESSION\n    echo -n \"[$ZMX_SESSION] \"\n  end\n  _original_fish_prompt\nend\n```\n\n### bash and zsh\n\nDepending on the shell, place this in either `.bashrc` or `.zshrc`:\n\n```bash\nif [[ -n $ZMX_SESSION ]]; then\n  export PS1=\"[$ZMX_SESSION] ${PS1}\"\nfi\n```\n\n### powerlevel10k zsh theme\n\n[powerlevel10k](https://github.com/romkatv/powerlevel10k) is a theme for zsh that overwrites the default prompt statusline.\n\nPlace this in `.zshrc`:\n\n```bash\nfunction prompt_my_zmx_session() {\n  if [[ -n $ZMX_SESSION ]]; then\n    p10k segment -b '%k' -f '%f' -t \"[$ZMX_SESSION]\"\n  fi\n}\nPOWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=my_zmx_session\n```\n\n### oh-my-posh\n\n[oh-my-posh](https://ohmyposh.dev) 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:\n\n```toml\n[[blocks.segments]]\n   template = '{{ if .Env.ZMX_SESSION }} {{ .Env.ZMX_SESSION }}{{ end }}'\n   foreground = 'p:orange'\n   background = 'p:black'\n   type = 'text'\n   style = 'plain'\n```\n\n### Starship\n\n[Starship](https://starship.rs) 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:\n\n```toml\nformat = \"\"\"\n${env_var.ZMX_SESSION}\\\n...\n\"\"\"\n\n[env_var.ZMX_SESSION]\nsymbol = \" \"\nformat = \"[$symbol$env_value]($style) \"\ndescription = \"zmx session name\"\nstyle = \"bold magenta\"\n```\n\n## shell completion\n\nShell auto-completion for `zmx` commands and session names can be enabled using the `completions` subcommand. Once configured, you'll get auto-complete for both local `zmx` commands and sessions:\n\n```bash\nssh remote-server zmx attach session-na\u003cTAB\u003e\n# \u003c- auto-complete suggestions appear here\n```\n\n\u003e NOTICE: when installing `zmx` with `homebrew` completions are automatically installed.\n\n### bash\n\nAdd this to your `.bashrc` file:\n\n```bash\nif command -v zmx \u0026\u003e /dev/null; then\n  eval \"$(zmx completions bash)\"\nfi\n```\n\n### zsh\n\nAdd this to your `.zshrc` file:\n\n```zsh\nif command -v zmx \u0026\u003e /dev/null; then\n  eval \"$(zmx completions zsh)\"\nfi\n```\n\n### fish\n\nAdd this to `~/.config/fish/completions/zmx.fish`:\n\n```fish\nif type -q zmx\n  zmx completions fish | source\nend\n```\n\n## session picker\n\nYou can add an interactive session picker to your shell that lets you fuzzy-find existing sessions, preview their scrollback history, or create new ones — all from a single prompt. This is especially useful for remote SSH workflows: add it to your shell startup so that connecting to a machine immediately presents the picker.\n\nRequires [fzf](https://github.com/junegunn/fzf).\n\n- **Enter** selects a matched session (or creates one if no sessions exist)\n- **Ctrl-N** creates a new session using the typed query, even when a fuzzy match is highlighted\n\n\u003cdetails\u003e\n\u003csummary\u003ebash and zsh\u003c/summary\u003e\n\n```bash\nzmx-select() {\n  local display\n  display=$(zmx list 2\u003e/dev/null | while IFS=$'\\t' read -r name pid clients created dir; do\n    name=${name#session_name=}\n    pid=${pid#pid=}\n    clients=${clients#clients=}\n    dir=${dir#started_in=}\n    printf \"%-20s  pid:%-8s  clients:%-2s  %s\\n\" \"$name\" \"$pid\" \"$clients\" \"$dir\"\n  done)\n\n  local output query key selected session_name\n  output=$({ [[ -n \"$display\" ]] \u0026\u0026 echo \"$display\"; } | fzf \\\n    --print-query \\\n    --expect=ctrl-n \\\n    --height=80% \\\n    --reverse \\\n    --prompt=\"zmx\u003e \" \\\n    --header=\"Enter: select | Ctrl-N: create new\" \\\n    --preview='zmx history {1}' \\\n    --preview-window=right:60%:follow \\\n  )\n  local rc=$?\n\n  query=$(echo \"$output\" | sed -n '1p')\n  key=$(echo \"$output\" | sed -n '2p')\n  selected=$(echo \"$output\" | sed -n '3p')\n\n  if [[ \"$key\" == \"ctrl-n\" \u0026\u0026 -n \"$query\" ]]; then\n    session_name=\"$query\"\n  elif [[ $rc -eq 0 \u0026\u0026 -n \"$selected\" ]]; then\n    session_name=$(echo \"$selected\" | awk '{print $1}')\n  elif [[ -n \"$query\" ]]; then\n    session_name=\"$query\"\n  else\n    return 130\n  fi\n\n  zmx attach \"$session_name\"\n}\n```\n\nYou can call `zmx-select` manually, bind it to a key, or auto-launch it on shell startup when outside a zmx session. With `\u0026\u0026 exit`, the normal flow becomes: connect via SSH → pick a session → work → detach or exit the session → SSH disconnects automatically. Cancelling the picker with **Ctrl-C** drops you into a regular shell as an escape hatch.\n\n```bash\nif command -v zmx \u0026\u003e /dev/null \u0026\u0026 command -v fzf \u0026\u003e /dev/null \u0026\u0026 [[ -z \"$ZMX_SESSION\" ]]; then\n  zmx-select \u0026\u0026 exit\nfi\n```\n\n\u003c/details\u003e\n\n## session prefix\n\nWe allow users to set an environment variable `ZMX_SESSION_PREFIX` which will prefix the name of the session for all commands. This means if that variable is set, every command that accepts a session will be prefixed with it.\n\n```bash\nexport ZMX_SESSION_PREFIX=\"d.\"\nzmx a runner # ZMX_SESSION=d.runner\nzmx a tests  # ZMX_SESSION=d.tests\nzmx k tests  # kills d.tests\nzmx wait     # suspends until all tasks prefixed with \"d.\" are complete\n```\n\n## philosophy\n\nThe 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.\n\nInstead, this tool specifically focuses on session persistence and defers window management to your os wm.\n\n## ssh workflow\n\nUsing `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.\n\nFirst, create an `ssh` config entry for your remote dev server:\n\n```bash\nHost = d.*\n    HostName 192.168.1.xxx\n\n    RemoteCommand zmx attach %k\n    RequestTTY yes\n    ControlPath ~/.ssh/cm-%r@%h:%p\n    ControlMaster auto\n    ControlPersist 10m\n```\n\nNow you can spawn as many terminal sessions as you'd like:\n\n```bash\nssh d.term\nssh d.irc\nssh d.pico\nssh d.dotfiles\n```\n\nThis 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.\n\nNow you can use the [`autossh`](https://linux.die.net/man/1/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:\n\n```bash\nautossh -M 0 -q d.term\n```\n\nOr create an `alias`/`abbr`:\n\n```fish\nabbr -a ash \"autossh -M 0 -q\"\n```\n\n```bash\nash d.term\nash d.irc\nash d.pico\nash d.dotifles\n```\n\nWow! 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.\n\n## socket file location\n\nEach session gets its own unix socket file. The default location depends on your environment variables (checked in priority order):\n\n1. `ZMX_DIR` =\u003e uses exact path (e.g., `/custom/path`)\n1. `XDG_RUNTIME_DIR` =\u003e uses `{XDG_RUNTIME_DIR}/zmx` (recommended on Linux, typically results in `/run/user/{uid}/zmx`)\n1. `TMPDIR` =\u003e uses `{TMPDIR}/zmx-{uid}` (appends uid for multi-user safety)\n1. `/tmp` =\u003e uses `/tmp/zmx-{uid}` (default fallback, appends uid for multi-user safety)\n\n## debugging\n\nWe 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.\n\n## a note on configuration\n\nWe 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.\n\n## a smol contract\n\n- Write programs that solve a well defined problem.\n- Write programs that behave the way most users expect them to behave.\n- Write programs that a single person can maintain.\n- Write programs that compose with other smol tools.\n- Write programs that can be finished.\n\n## known issues\n\n- When upgrading versions of `zmx` where we make changes to the underlying IPC communication, it will kill all your sessions because it cannot communicate through the daemon socket properly\n- Terminal state rehydration with nested `zmx` sessions through SSH: host A `zmx` -\u003e SSH -\u003e host B `zmx`\n  - Specifically cursor position gets corrupted\n- When re-attaching and kitty keyboard mode was previously enable, we try to re-send that CSI query to re-enable it\n  - Some programs don't know how to handle that CSI query (e.g. `psql`) so when you type it echos kitty escape sequences erroneously\n\n## impl\n\n- The `daemon` and client processes communicate via a unix socket\n- Both `daemon` and `client` loops leverage `poll()`\n- Each session creates its own unix socket file\n- We restore terminal state and output using `libghostty-vt`\n\n### libghostty-vt\n\nWe use `libghostty-vt` to restore the previous state of the terminal when a client re-attaches to a session.\n\nHow it works:\n\n- user creates session `zmx attach term`\n- user interacts with terminal stdin\n- stdin gets sent to pty via daemon\n- daemon sends pty output to client *and* `ghostty-vt`\n- `ghostty-vt` holds terminal state and scrollback\n- user disconnects\n- user re-attaches to session\n- `ghostty-vt` sends terminal snapshot to client stdout\n\nIn 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.\n\n## prior art\n\nBelow is a list of projects that inspired me to build this project.\n\n### shpool\n\nYou can find the source code at this repo: https://github.com/shell-pool/shpool\n\n`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.\n\n`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.\n\nThe biggest advantage of this approach is that `shpool` does not break native scrollback or copy-paste.\n\n### abduco\n\nYou can find the source code at this repo: https://github.com/martanne/abduco\n\nabduco 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.\n\n### dtach\n\nYou can find the source code at this repo: https://github.com/crigler/dtach\n\nA simple program that emulates the detach feature of screen.\n\ndtach 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.\n\n## comparison\n\n| Feature                        | zmx | shpool | abduco | dtach | tmux |\n| ------------------------------ | --- | ------ | ------ | ----- | ---- |\n| 1:1 Terminal emulator features | ✓   | ✓      | ✓      | ✓     | ✗    |\n| Terminal state restore         | ✓   | ✓      | ✗      | ✗     | ✓    |\n| Window management              | ✗   | ✗      | ✗      | ✗     | ✓    |\n| Multiple clients per session   | ✓   | ✗      | ✓      | ✓     | ✓    |\n| Native scrollback              | ✓   | ✓      | ✓      | ✓     | ✗    |\n| Configurable detach key        | ✗   | ✓      | ✓      | ✓     | ✓    |\n| Auto-daemonize                 | ✓   | ✓      | ✓      | ✓     | ✓    |\n| Daemon per session             | ✓   | ✗      | ✓      | ✓     | ✗    |\n| Session listing                | ✓   | ✓      | ✓      | ✗     | ✓    |\n\n## community tools\n\n- [zsm](https://github.com/mdsakalu/zmx-session-manager) — TUI session manager for zmx. List, preview, filter, and kill sessions from an interactive terminal UI.\n- [zmosh](https://github.com/mmonad/zmosh) — A fork of zmx that adds encrypted UDP auto-reconnect for remote sessions (like mosh).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneurosnap%2Fzmx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneurosnap%2Fzmx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneurosnap%2Fzmx/lists"}