szn

Build, Run, and Test

Prerequisites

Build

zig build                                    # -> zig-out/bin/szn (Debug)
zig build -Doptimize=ReleaseFast --prefix ~/.local   # -> ~/.local/bin/szn
zig build run                                 # build + run
zig build test                                # run the test binary

Build options are the standard Zig flags (b.standardTargetOptions and b.standardOptimizeOption): -Dtarget=<triple> (default host) and -Doptimize=<Debug|ReleaseSafe|ReleaseFast|ReleaseSmall> (default Debug).

Release behaviour: for non-Darwin + non-Debug, lto = .thin and use_lld = true are applied to both the executable and the test binary, and the executable is stripped. macOS release builds skip thin-LTO/lld (guarded by !is_darwin).

Run

szn is both client and server. With no socket it auto-spawns the daemon (creates a default session at 80×23 and runs $SHELL); otherwise it attaches.

Command Purpose
szn Start default session (auto daemon) + attach
szn new -d <name> Create a detached session
szn attach Attach to running session
szn split-window -v / -h Split pane vertically / horizontally
szn new-window [name] New window
szn list-sessions (ls) List sessions
szn kill-session [name] Kill session
szn send-keys <keys> Send keystrokes to active pane
szn resize-pane -L/-R/-U/-D Resize pane
szn set-option -g/-w <k> <v> Set session/window option
szn source-file ~/.szn.conf Load config
szn help [cmd] Help

Config lives at ~/.szn.conf (tmux-style). Debug logging is off by default; enable with set -g server-log-file default → $XDG_STATE_HOME/szn/szn.log (log-file is still accepted as an alias). The client logs separately via client-log-file.

Nested szn is blocked (env SZN set → detectNested returns true).

Test

src/test.zig is a comptime aggregator that @imports every module so their top-level test {} blocks compile into one test binary (see the b.addTest call in build.zig). There is no separate tests/ directory — tests live next to the code they cover. As of 2026-10-30 the suite is 1082 tests, all passing on a clean tree under both Zig 0.16.0 and 0.17.0 (-Doptimize=ReleaseFast, fresh cache).

zig build test

To check both toolchains from one tree, give each its own cache directory:

rm -rf .cache .zig-cache
zig build test -Doptimize=ReleaseFast --summary all --cache-dir .cache/bt16                 # 0.16.0
/opt/zig/0.17.0/zig build test -Doptimize=ReleaseFast --summary all --cache-dir .cache/bt17 # 0.17.0

Notes:

Allocator differences between 0.16 and 0.17

std.testing.allocator is a DebugAllocator on 0.16.0 but a SafeAllocator on 0.17.0. The test runner configures it with check_write_after_free = true on page_allocator. SafeAllocator never reuses memory and returns freed pages to the OS. So a test that reads a pointer after freeing it can pass on 0.16, where the stale bytes are still mapped, and crash with SIGSEGV on 0.17. Bug #562 was exactly this. If a test passes on 0.16 but crashes on 0.17, look for a use-after-free first.

Socket tests

Older revisions left szn.sock behind after zig build test, and the next run then failed three socket tests. That no longer happens. The tests clean up the default socket path, and as of 2026-10-30 the suite also passes when a stale socket is already there before the run.

Dev script: bench.sh

bench.sh builds szn with ReleaseFast and benchmarks startup time and create/destroy throughput (and RSS memory) against tmux -u using hyperfine. Requires hyperfine and tmux on PATH. It does not correspond to a zig build bench step.

Dependencies

None beyond libc. build.zig.zon declares no .dependencies; everything is in-tree under src/.