Move hot code to Zig one function at a time, with every step checked against the original's recorded behavior.
Functions in JavaScript, TypeScript and Python. Command-line programs in any language.
Documentation: Guide · Architecture · Changelog
| 20.7× faster 134.6 ms → 6.5 ms |
253 / 253 recorded cases identical |
6 platforms Linux, macOS, Windows · x86_64 and arm64 |
levenshtein from examples/levenshtein-py: Python 3.12 vs its Zig port, wall time for a fresh process running all 253 recorded cases once, median of 5 runs. Ryzen 7 5700X, Windows 11. Methodology and the other results, including slower ones, are in Measured results.
Rewrites usually fail in the gap between "the new code compiles" and "the new code does what the old code did". zig-anything closes that gap with a behavior-verified migration, not a rewrite:
- Record. The original function runs in its own runtime (Node.js or Python) on generated edge cases, semantic traps and your own inputs. Every result, including thrown errors, is stored.
- Port. You or your coding agent write the Zig version of that one function.
- Verify. Every recorded case is replayed against the port and compared semantically.
gatepasses only when all of them match. - Integrate. Callers switch to the port through a native bridge, your test suite runs, and the source rolls back automatically if anything fails.
You move one function at a time, hottest first, and the application keeps working after every step.
$ zig-anything diff fuzzyScore
case 22: different value
args ["🎉","emoji 🎉 ok"]
expected {"ok":0.75}
got {"ok":0.7}
285/288 cases match [zig-port/fuzzyScore]
A real mismatch: the first port counted UTF-8 bytes, but JavaScript counts UTF-16 code units. The recording caught it before any caller did.
Paste this into your coding agent:
Install zig-anything with npm i -g https://github.com/Layfate/zig-anything/releases/download/v0.3.0/zig-anything-0.3.0.tgz, then run zig-anything setup-agent. Run zig-anything plan, port each function in that order until zig-anything gate passes for it, then switch callers to it with zig-anything integrate.
Or install it yourself:
npm i -g https://github.com/Layfate/zig-anything/releases/download/v0.3.0/zig-anything-0.3.0.tgz
zig-anything setup-agent # registers the MCP server with Claude Code, Cursor and VS CodeEach release also ships Python wheels and standalone binaries for Linux, macOS and Windows on x86_64 and arm64. The binary is a single static executable of about 1 MB with no runtime dependencies.
zig-anything plan src/ # what to port, in what order
zig-anything init src/text.mjs slugify # scaffold zig-port/slugify
zig-anything record slugify # record what the original does
zig-anything coverage slugify # lines no recorded case executes
$EDITOR zig-port/slugify/src/port.zig # write the port
zig-anything diff slugify # repeat until every case matches
zig-anything gate slugify --min-coverage 90 # done means this passes
zig-anything bench slugify # measure both sides on the same inputs
zig-anything integrate slugify -- npm test # switch callers to the port, verified- Semantic comparison.
1,1.0and1e0are equal, object key order is ignored, NaN and ±Infinity survive the round trip, and thrown errors match returned Zig errors. - Native bridge. A finished port is callable from Node through a Node-API addon (WebAssembly fallback) and from Python through a CPython extension (
ctypesfallback). TypedArrays and numpy arrays pass without copying, and--targets allcross-compiles both for every platform from one machine, so you can use the port before the rest of the migration is done. - Coverage you can see.
coveragelists the lines of the original that no recorded case executes, so you know where the port is unchecked.gate --min-coveragemakes a minimum part of done. - Any module style.
integraterewires ES modules, CommonJS, TypeScript and Python, and keeps async functions async. - Agent-ready.
zig-anything mcpexposes every command as a Model Context Protocol tool.
The guide covers every command, configuration, the bridge, program units and limitations.
zig-anything bench <unit> times both sides on the same recorded inputs and reports the result even when the port is slower. Numbers from one machine (Ryzen 7 5700X, 32 GB, Windows 11, Zig 0.17.1, Node.js 24.21, Python 3.12.10), median of 5 runs:
| Unit | Original | Per call | One process, all cases |
|---|---|---|---|
levenshtein (253 cases) |
Python 3.12 | 51.1 µs → 0.31 µs (164×) | 134.6 ms → 6.5 ms (20.7×) |
fuzzyScore (288 cases) |
Node.js 24, V8 JIT | 61.3 ns → 32.5 ns (1.9×) | 43.6 ms → 6.9 ms (6.3×) |
How to read these:
- "One process" is wall time for a fresh process that loads the code and runs every case once, so it includes interpreter startup. "Per call" excludes startup and uses calibrated timed passes after a warm-up.
- Calling a port from the original language costs something. Through the native Python extension,
levenshteingoes from 48.2 µs to 0.42 µs per call: 115×, not 164× (thectypesfallback manages 7×). Through the Node addon,fuzzyScoreis slower than calling it in place, because a 70 ns function in a JIT is cheaper than any language crossing. Port whole hot paths, or use the batch entry points. - A JIT is a strong baseline. The first
fuzzyScoreport matched every case but ran 2.6× slower than V8. Profiling found the cause, and the recorded cases stayed green through the fix. The story is in examples/fuzzy-js.
Every number has a reproduce command in the guide's benchmark section. Your numbers will differ.
zig-anything targets Zig because of what a gradual migration needs: small, self-contained native code that any runtime can call and that builds for every platform from one machine.
| Zig | Rust | Cython | |
|---|---|---|---|
| Callable from Node and Python | Yes, through the C ABI, Node-API and WebAssembly | Yes, through napi-rs, PyO3 and WebAssembly | Python (CPython) only |
| Cross-compiling | Built into the compiler, including libc; one machine builds all six release targets | Good, but targets with a C toolchain or libc usually need extra setup (cross, zigbuild) | One build per platform and Python version, or the stable ABI |
| Memory safety | Runtime checks in Debug and ReleaseSafe builds; no compile-time guarantee | Guaranteed at compile time outside unsafe |
Python's guarantees, until you use C-level types and pointers |
| Learning curve for a one-function port | Small language, explicit allocation, no hidden control flow | Ownership and lifetimes take longer to learn | Lowest for Python developers: start from the Python code |
| Stability and ecosystem | Pre-1.0: releases contain breaking changes, smaller package ecosystem | Stable since 2015, large ecosystem (crates.io) | Mature and stable, tied to CPython |
Choose Rust when you need compile-time memory safety, are writing a large, long-lived native component, or need a mature library ecosystem. Choose Cython when the code only ever runs inside CPython and you want to speed it up without leaving Python's syntax. zig-anything is built for the case in between: replacing hot functions in JavaScript, TypeScript or Python codebases with small native ports, verified one at a time, that work from either runtime and ship to every platform without per-platform toolchains.
Verification partly offsets the lack of compile-time memory safety. diff and gate build ports in ReleaseSafe mode by default, so bounds violations and integer overflow on any recorded input fail verification instead of reaching production. It is a test, not a proof: inputs that were never recorded are not checked.
Zig has not reached 1.0, and each minor release can break existing code. zig-anything therefore pins one Zig version instead of supporting a range:
| zig-anything | Zig | Status |
|---|---|---|
| 0.3.x | 0.17.1 | Current. Tested in CI on Linux, macOS and Windows (x86_64 and arm64) |
| 0.2.x | 0.17.1 | Previous |
- The pinned version is the contract. The tool, its scaffolded ports, harnesses and bridge code all target the version above.
build.zig.zondeclares it asminimum_zig_version, and CI builds and tests with exactly that version. - Use the pinned version for your ports. zig-anything runs
zigfrom yourPATH, or the compiler named by theZIGenvironment variable or the"zig"setting inzig-anything.json. Other versions may work but are not tested. - Upgrades happen in a minor release. Moving to a new Zig version is a single change that updates the CI matrix,
build.zig.zonand the scaffolding thatinitandbridgegenerate together, passes the full unit and end-to-end suite on every platform, and is recorded in the changelog with any edits your existing ports need. - Your recordings survive upgrades. Recorded cases are plain JSON lines that don't depend on Zig. After upgrading Zig, run
zig-anything gateon each unit to confirm every port still matches the original exactly.
| Needed for | Tool |
|---|---|
| building and verifying ports | Zig 0.17.1 |
| recording JavaScript | Node.js 22.6+ |
| recording TypeScript | Node.js 23.6+ (native type stripping), or a configured loader |
| recording Python | Python 3.8+ |
A passing gate means "equal on every recorded case", not "proven equal", so the quality of a port depends on the quality of its inputs. coverage shows which lines of the original no case executes, fuzz searches for inputs the recording missed, and domain-specific inputs belong in inputs.jsonl. Function units take and return JSON-representable values. File, network and database side effects are not compared. The full list is in Scope and limitations.
MIT © zig-anything contributors. Ports and generated code in your repository are yours.

