CLI — complete manual
Reference (complete). Learning path: CLI → CLI reference for every-command tables.
Installation
Section titled “Installation”cargo install --path crates/zz_cliCommands
Section titled “Commands”zz (REPL)
Section titled “zz (REPL)”Start the interactive REPL:
zzOutput:
ZZ REPL — type :help for commands, Ctrl+D to exitzz>REPL Features
Section titled “REPL Features”- Multi-line continuation on trailing operators, open parens, or incomplete statements
- Bindings persist across snippets
- Each snippet is type-checked before execution
- Continuation prompt:
|
zz> x := 4242zz> x + 143zz> func add(a: int, b: int) -> int { return a + b }<func add>zz> add(3, 4)7zz run <file.zz>
Section titled “zz run <file.zz>”Type-check and run a ZZ source file (e.g. the hello.zz from
Getting started):
zz run hello.zzInside a project with [features], select optional features with
--features a,b (repeatable) or --all-features; the manifest’s default
feature is always active. zz build, zz check, and zz install accept the
same flags. A gated import names the exact feature and how to enable it.
zz eval <source>
Section titled “zz eval <source>”Evaluate a source string and print the result:
zz eval "1 + 2"3
zz eval "println('hello')"hello()zz build [FLAGS] [<file.zz>]
Section titled “zz build [FLAGS] [<file.zz>]”Single Clang backend. Every zz build produces a real native binary and
requires clang (18+) or zig on PATH — except in a release zip, which
bundles both a zig binary and its lib/, so no external compiler is
needed. (zz run without --native is the only VM path, and it leaves
no build artifacts.)
# Static (default): self-contained -O3 -flto=thin, stripped, DCE.# System libs link conditionally: programs that never fetch skip# libcurl, programs that never query skip libsqlite3 (no phantom# DT_NEEDED). A program needing neither links fully static with no# static syslibs required; fetch/query programs need libcurl.a /# libsqlite3.a for explicit `--static`, otherwise the default build# downgrades to dynamic with a note.zz build main.zz # standalone: produces ./mainzz build # inside a project: builds src/main.zz # (then main.zz) to <root>/bin/<pkg-name>
# Release: native Clang -O3 -flto=thin, stripped, dynamic, cached under ~/.zz/cachezz build -p main.zz# Max optimization: full LTO (-O3, DCE, stripped); with `-- <args>` adds a PGO training runzz build -p --full main.zzzz build -p --full main.zz -- fast representative workloadzz build --static main.zz # self-contained, explicit (not on macOS)zz build --dynamic main.zz # fast dynamic debug build -O0 -gzz build -o server main.zz # name the output binary (project bin/server or ./server)zz build --pgo main.zz # profile-guided, native host onlyzz build --target aarch64-unknown-linux-gnu main.zz # cross (implies -p)zz build -p --cc zig main.zz # use `zig cc` as the providerzz build -p --verbose main.zz # print the exact clang command linezz build --embed ./assets main.zz # bake static files into the binaryzz run --embed ./assets main.zz # serve them in the VM insteadzz run --native --embed ./assets main.zz # bake + run nativelyStatic assets (--embed <dir>) are readable at runtime through
fs.embedfs() (same *_at operations as every provider; read-only):
import std.fs
match fs.embedfs() { .ok(e) => match fs.read_to_string_at(e, "index.txt") { .ok(c) => println(c), .err(x) => println(x), }, .err(x) => println(x),}Asset edits invalidate the build cache (content-hashed), and app.c
manual builds include the same tables.
Output paths (3-line rule): standalone file → ./<stem> in CWD;
project file → <project-root>/bin/<name>; --target adds
-<triple> suffix. -o <name> renames (bare name stays in the
resolved directory, a path is used as-is).
Output details (entry, discovery, sidecars, atomicity)
Project builds (any source under a project, or zz build with no
argument inside one) publish to <project-root>/bin/, named after
[package] name for the entry point or the file stem for explicit
non-entry files — never src/bin/. Byte-identical src/bin/ twins
left by previous versions are reaped on publish (logged to stderr);
anything else there is left alone. Sidecars (app.c, build.sh,
build.bat: reproducible manual build with a single clang line) sit
next to the binary.
Entry point: src/main.zz, then main.zz — or [package] entry to
override (e.g. entry = "src/cli.zz"; must stay inside the package
and exist, else the build fails loudly). The entry also decides the
default binary name ([package] name).
Project discovery: zz build with no argument discovers the project
from the current working directory. With an explicit source path, the
file’s owning project (nearest ancestor holding zz.toml) decides the
output directory — even when invoked from another directory. A file
outside any project builds standalone into the current directory.
zz clean operates on the discovered project root too. Builds into a
project root ensure bin/ is gitignored (append-only, silent), so
pre-redesign checkouts stay clean.
Concurrent builds to one destination publish atomically (last writer
wins, never a half-written binary); zz run --native executes a
private staged copy, so a parallel publish can never swap the binary
mid-exec.
Cross-compilation rules:
| Rule | Behavior |
|---|---|
--target |
Clang uses the triple’s safe baseline CPU (no host-specific flags anywhere) |
--pgo --target <foreign> |
Rejected: Error: --pgo requires a native build target |
--static on apple-darwin |
Rejected: Error: Static binaries are not supported on macOS targets |
| Cross link | Adds -fuse-ld=lld; Windows triples also link -lws2_32 |
All builds compile with -fwrapv (defined wrapping integer arithmetic)
and -fno-strict-aliasing, and without -ffast-math or
-march=native: VM and native binaries must agree bit-for-bit on
integers and floats (see the IR spec). If no Clang provider is
installed,
the build (debug or release) fails after still emitting app.c +
build scripts next to the planned destination so the program can be
built manually on a machine with Clang.
zz run [--native|--bytecode] [<file.zz>]
Section titled “zz run [--native|--bytecode] [<file.zz>]”zz run executes through the VM and leaves no build artifacts.
zz run --native builds through the cached Clang pipeline (publishing
to the same authoritative destination as zz build, -o overrides
like build) and executes the binary. The file argument defaults to
the project entry inside a project.
| Flag | Effect |
|---|---|
--bytecode |
Compile to IR and execute the chunk VM, never the tree walker; also accepts a .zzc file to load directly |
--embed <dir> |
Expose a static asset directory to the program (fs.embedfs()) |
-o, --output <name> |
Name the published binary (--native only) |
--watch |
Hot reload (see below; VM only) |
-h, --help |
Print the flags, engines and run-cache controls |
Arguments after the file are passed to the program.
The run cache: which engine executes your file
Section titled “The run cache: which engine executes your file”zz run keeps a content-addressed cache of compiled IR, and cache
state selects the engine:
| Cache | Engine | Work done |
|---|---|---|
| hit | chunk VM (decode → raise → run_loaded_chunk) |
key check, scoped native rebuild, execute |
| miss | tree walker (run_typed) |
parse, check, HIR, execute; then compile and store IR for next time |
So the same file can run on either engine from one invocation to the
next. Both are gated for semantic equality (dual_engine_parity), but a
benchmark that does not pin the engine is measuring “whichever the cache
had”. Pin the chunk VM with --bytecode; pin the tree walker with
ZZ_RUN_CACHE=0.
The key covers the entry bytes and canonical path (namespace), every
.zz source under the project directory, live path-dependency content,
the vm-run target string, a toolchain fingerprint (CLI version, IR
format version, build identity, sorted plugin manifest names), and
--embed asset bytes. Script arguments are runtime-only and excluded.
Entries live in <build-cache>/run-v2 (ZZ_HOME relocates the build
cache), one directory per slug holding meta.json and one .zzc per
module in execution order; stores are atomic, the tree is bounded at 256
entries (LRU by mtime), and no-change runs validate a stat-signature
sidecar instead of re-hashing every source.
A miss is never an error: cold caches, unreadable entries, and toolchain changes fall back to the full pipeline and re-store. Levers:
ZZ_VERBOSE=1 zz run main.zz # print hit/miss and stage linesZZ_RUN_CACHE=0 zz run main.zz # force the tree walker (benchmark this)ZZ_VM_STATS=1 zz run main.zz # op counters + fused share, on stderrzz cache clean # wipe ~/.zz/cache, run entries includedzz cache gc # collect unused CAS entries onlyZZ_VM_STATS=1 counts every dispatched op in the chunk VM and prints a
per-class summary (fused, int-op, stack, …) to stderr at exit;
stdout is untouched, so it composes with the benchmark harnesses. The
static counterpart is zz dis --vm [--stats] <file.zz>, which prints the
loader-path chunk (ops with line:col sites) — the only reliable view of
what the VM is actually handed.
zz run --watch [<file.zz>]
Section titled “zz run --watch [<file.zz>]”Hot reload for VM runs: re-checks and restarts the program on every save.
zz run --watch server.zzzz run --watch --clear --debounce 200 --watch-ignore '*.gen.zz' src/main.zzEach generation is a fresh zz run child, so restarts leak no sockets,
threads, or interpreter state. The loop:
- Watches the owning project tree (
*.zz,zz.toml/zz.lock) — or the entry’s own directory for standalone files — plus--embedassets.vendor/,.git/,bin/,build/,target/are never watched. - On change, waits for
--debouncems of quiet (default 150), then runszz check. A broken edit never replaces a running server: diagnostics print and the previous generation keeps serving. - Restarts print
generation N; the child sees its number inZZ_WATCH_GEN.--clearclears the screen per restart.
Flags: --clear, --debounce <ms>, repeatable --watch-ignore <glob>
(* spans directories, matched against path and file name). --watch
rejects --native / --bytecode (native rebuilds are minutes, not
milliseconds). In-memory state resets on every restart by design.
Roots over 20,000 entries refuse with a hint (create a zz.toml
project or narrow with --watch-ignore) instead of statting the
world every tick.
zz clean / zz cache
Section titled “zz clean / zz cache”zz clean # remove project outputs (bin/, build/, src/bin/)zz clean --deps # ... plus vendor/ + zz.lock (re-fetch with zz install)zz cache clean # wipe the global build cache (~/.zz/cache)zz cache gc # garbage-collect unused package downloadszz clean operates on the discovered project root from any subdir and
always reports the global build cache with a reclaim hint when it is
non-empty. The cache holds native binaries, precompiled runtime
archives, and per-module objects — everything rebuildable, keyed by
content, honoring ZZ_HOME. When disk runs low, zz cache clean is
the reclaim command (next builds just take a little longer).
zz toolchain <install|use|uninstall|status>
Section titled “zz toolchain <install|use|uninstall|status>”Manage the Zig C backend. zz build needs a C backend (system clang
or zig cc); toolchain install downloads a pinned Zig release into
~/.zz/toolchain so builds work with no system toolchain and stay
reproducible across machines:
zz toolchain install # latest stable Zig, verified + pinnedzz toolchain install --version 0.17.0 # pin an exact release insteadzz toolchain status # installed versions, pin, active backendzz toolchain use 0.17.0 # switch the pin among installed versionszz toolchain uninstall 0.17.0 # remove an installed versionDetails:
- Sources are official
ziglang.orgreleases viadownload/index.json(URLs are never constructed — asset naming changed between eras); every download is sha256-checked against the index. - A pin is explicit opt-in: once present, provider probing prefers the
managed
zigover everything on PATH (--cc=clang/--cc=zigstill force their provider), and the precompiled-runtime cache key includes the pin so switching toolchains rebuilds instead of reusing. - Set
ZZ_TOOLCHAIN_ROOTto relocate the toolchain dir (hermetic CI).
zz check [FLAGS] [PATH]
Section titled “zz check [FLAGS] [PATH]”Scan files for errors and warnings:
# Check current directoryzz check
# Check specific filezz check src/main.zz
# Check directory recursivelyzz check src/Check Flags
Section titled “Check Flags”| Flag | Description |
|---|---|
--fix / -f |
Apply safe auto-fixes |
--hard |
Apply all fixes including ambiguous (no prompts) |
--interactive / -i |
Prompt for ambiguous fixes |
--stats |
Print per-file and total check stats (modules, cache hits/misses, seed size, wall time) |
--format json |
Emit machine-readable diagnostics ({"files": [{"file", "diagnostics"}]} on stdout); exit codes unchanged; cannot combine with --fix |
-h, --help |
Print usage and exit — never checks, never writes |
Note:
--check/-cis azz fmtflag only.zz check --checkis rejected —zz checkalready checks without writing; usezz fmt --checkfor a formatting dry-run.
Note:
--helpis read-only.zz check --fix --helpprints usage and exits 0 without applying a single fix.
Check Performance Budget
Section titled “Check Performance Budget”zz check stays fast by construction (per-module seed key-set restore
instead of O(seed) clones, plus the S1 content-addressed check cache):
- Cold
zz checkon a single file: well under 0.5s (measured ~40ms). - Warm (no edits): served from cache —
0 checkedin--statsoutput. - Budget: p50 ≤ 0.5s on a 10k-line project cold, ≤ 50ms warm per file.
Verify with
zz check --stats <path>(run twice: the second run should showcachedinstead ofchecked).
$ zz check --stats src/main.zzstats: src/main.zz: 1 modules (0 cached, 1 checked), seed 878 funcs, 38.1msstats: 1 files, 1 modules (0 cached, 1 checked), seed 878 funcs, 39.0ms totalzz fix [FLAGS] [PATH]
Section titled “zz fix [FLAGS] [PATH]”Shortcut for zz check --fix:
zz fix src/
# Apply all fixes without promptingzz fix --hard src/
# Usage only — prints help, changes nothingzz fix --helpzz fix --help (and -h) prints the command usage and exits 0 without
touching a single file — asking for documentation never rewrites the
project.
zz fmt [FLAGS] [PATH]
Section titled “zz fmt [FLAGS] [PATH]”Format ZZ source files in-place:
# Format current directoryzz fmt
# Format specific filezz fmt src/main.zz
# Check formatting without writingzz fmt -c src/
# Format directory recursivelyzz fmt src/
# Usage only — prints help, changes nothingzz fmt --helpzz fmt --help (and -h) prints the command usage and exits 0 without
reformatting any file.
| Flag | Short | Scope | Description |
|---|---|---|---|
--check |
-c |
fmt only |
Check formatting without writing (exit 1 if changed) |
--dry-run |
setup, upgrade |
Report status without changing anything (--check deprecated alias) |
|
--fix |
-f |
check, fix |
Apply safe auto-fixes |
--hard |
check, fix |
Apply all fixes including ambiguous | |
--interactive |
-i |
check, fix |
Prompt for ambiguous fixes |
--help |
-h |
all | Show usage |
--version |
-V |
all | Show version |
Diagnostics
Section titled “Diagnostics”ZZ provides rich diagnostic output with context:
Error Output Format
Section titled “Error Output Format”error[E001]: type mismatch --> src/main.zz:5:12 | 5 | x: int = "hello" | ---- ^^^^^^^^ expected int, found str | = help: cast string to int with `int()` functionDiagnostic Features
Section titled “Diagnostic Features”- Source context: Shows the offending line with underline
- Location: File path, line number, column
- Error code: Categorized error (E001, E002, etc.)
- Help text: Suggestions for fixing the error
- Multiple errors: Reports all errors in a pass, not just the first
Auto-Fix
Section titled “Auto-Fix”Some diagnostics offer automatic fixes:
warning[W001]: unused variable --> src/main.zz:3:5 | 3 | x := 42 | ^^^^^^^ | = help: prefix with `_` to suppress: `_x := 42` = fix: `_x := 42`Run zz fix to apply fixes:
zz fix src/main.zzExit Codes
Section titled “Exit Codes”| Code | Meaning |
|---|---|
0 |
Success |
1 |
Errors found, or formatting check failed |
File Loading
Section titled “File Loading”The CLI resolves imports relative to the source file’s directory:
project/├── main.zz // println("hi")├── utils/│ ├── mod.zz // import std.math│ └── helper.zz // import .utils as utilimport std.*loads from the built-in standard libraryimport .nameloads from the current directoryimport utils.helperloadsutils/helper.zzrelative to the source fileimport <package>.path(package name from the nearestzz.toml) loads<project-root>/src/path.zz, from anywhere in the project — includingtests/files importingsrc/modules. A bareimport <package>loads<project-root>/src/main.zzunder the package name. Resolution precedence:std> package > registry dependency > relative file.-and_spellings of the package name both match (my-app⇔my_app).
Circular imports
Section titled “Circular imports”Circular imports are rejected (a imports b, b imports a):
circular import: `a.zz` imports `b.zz`, which (transitively) imports `a.zz`hint: circular imports are not allowed; consider restructuring your code to break the cycleRestructure by extracting shared types into c.zz, then both a and b
import c with no cycle. Cyclic imports remain unsupported by design
(use a shared leaf module to break the cycle).
One file, several namespaces
Section titled “One file, several namespaces”One file may be imported under several namespaces in the same program
(import a as x in one file, import a as y in another composes):
the first binding wins as canonical and alias references rewrite
through it, so struct identity stays qualified under one namespace
(x.T and y.T would diverge, so they never both exist). Two
different files under one namespace stay an error — alias one side.
Dependency sources
Section titled “Dependency sources”A dependency name has exactly one source: whatever zz.toml declares
("1.2.3" → registry, { git = …, rev = … } → git, { path = … } →
path). The manifest always wins — a lock pin from another source (left
over from before the manifest flipped, e.g. registry → path during
local development) is stale by definition: the resolver ignores it,
re-resolves from the manifest, and prints
note: <name>: manifest declares <source>, ignoring stale <source> pin.
zz install rewrites the lock and recreates vendor/ links, so
flipping a dep between path and registry needs no manual cleanup.
zz install also verifies materialization: on a fresh clone (lock
matches, vendor/ missing) it fetches and links instead of reporting
“up to date”. Same-name declarations across workspace members stay
unsupported until [workspace] ships — keep dependency names unique
per workspace until then.
REPL Commands
Section titled “REPL Commands”In the REPL, these special commands are available:
| Command | Description |
|---|---|
:help |
Show help |
:quit |
Exit REPL |
:type expr |
Show the type of an expression |
:clear |
Clear all bindings |
Examples
Section titled “Examples”Run a Complete Program
Section titled “Run a Complete Program”zz run hello.zzQuick Evaluation
Section titled “Quick Evaluation”zz eval "range(1, 6) |> map(|x| x * 2) |> str"[2, 4, 6, 8, 10]Check for Errors
Section titled “Check for Errors”$ zz check src/error[E001]: type mismatch --> src/main.zz:5:12 | 5 | x: int = "hello" | ---- ^^^^^^^^ expected int, found strFormat Code
Section titled “Format Code”$ zz fmt src/main.zzFormatted 1 fileAuto-Fix Errors
Section titled “Auto-Fix Errors”$ zz fix src/main.zzFixed 2 issues in src/main.zz