# Rust Anything: full documentation
> Every page of https://rustanything.ai/docs in one file. The short index is https://rustanything.ai/llms.txt.
# What is rust-anything
Rewrite your whole app in Rust, one piece at a time. rust-anything records what your Node.js (TypeScript/JavaScript), Python, C, Go, Ruby or Java app does today, then checks every piece of the Rust rewrite against that recording before it moves on, until the app is pure Rust.
It works on CLIs, HTTP servers and libraries. Your coding agent (Claude Code, Codex, Cursor, Gemini CLI) or you write the Rust. PHP and C# are in [preview](https://rustanything.ai/docs/languages/php).
## What it does, and what it doesn't
rust-anything does not translate code. It supplies what an agent cannot guess reliably:
- **where the time goes**: `profile` runs a real workload and ranks the hot functions;
- **what to port first, and in which order**: `analyze` plans units, waves, risks and crates;
- **a bridge** so the rest of the code calls the Rust with its API unchanged (`bridge`);
- **the exact behavior the port must match**: `record` runs the original on edge cases and saves what it returns or throws;
- **a safe way to ship it**: `shadow` runs both side by side;
- **a gate that says when a port is done**: `gate`.
The original stays the source of truth. `diff` replays every recorded case against the Rust, and nothing ships until they all match and `gate` passes.
## Four steps
| Step | What happens |
| --- | --- |
| **Record** | `record` runs the original on generated edge cases, semantic traps and your own inputs, and saves what it returns or throws. |
| **Port** | `bridge` generates the Rust crate and a wrapper, so callers keep the original API. You or your agent write the Rust. |
| **Check** | `diff` replays every recorded case against the Rust, and nothing ships until they all match and `gate` passes. |
| **Lift** | When replay passes with no fallback and every unit passes gate, `app lift` makes it a pure Rust app. The original is never touched. |
## Is Rust always faster?
No, and rust-anything says so. A small function called once per item is often slower in Rust, because each call crosses a bridge; V8, the JVM and Go run such functions in nanoseconds. `profile` finds the loop around it, `--batch` moves the whole loop, and `bench` gives a verdict before you ship. See [Batches and hot paths](https://rustanything.ai/docs/concepts/batches) for measured numbers, the slow ones included.
## It can only catch what the recording covers
Passing means the Rust matches every case that was recorded, nothing more. Read [What it can't catch](https://rustanything.ai/docs/concepts/limits) before you trust a green gate.
::: warning Run it on a copy
`record` and `app record` run your original code, calling each function (or the whole app) on many generated inputs, and `app record` runs every case twice. `diff`, `gate` and `app replay` run the same cases again, on the port or the original. Code that writes files, talks to a database or calls the network does that once per case. Run them on a copy of the project, with a test database and no production credentials in the environment.
:::
## Next steps
- [Quick start](https://rustanything.ai/docs/introduction/quick-start): install it and ask your agent for a first port.
- [The loop](https://rustanything.ai/docs/concepts/the-loop): every step for one unit.
- [Port a whole app](https://rustanything.ai/docs/whole-apps/overview): from the first recording to a pure Rust binary.
- [Real-world ports](https://rustanything.ai/docs/real-world/overview): json-server, Fuse.js, vercel/ms and more, with the slow results next to the fast ones.
---
# Quick start
## Let your agent install it
Paste this into Claude Code, Codex, Cursor or Gemini CLI:
```text
Install rust-anything: run `cargo install rust-anything`, then `rust-anything setup`.
Tell me when to restart you.
```
## Or install it yourself
::: tabs
== cargo
```sh
cargo install rust-anything # from crates.io
rust-anything setup # registers it with Claude Code, Codex, Cursor and Gemini CLI
```
== npm
```sh
npm install -g rust-anything
rust-anything setup
```
:::
No Rust toolchain yet? Prebuilt binaries for macOS, Linux and Windows are attached to each [GitHub release](https://github.com/erkamyaman/rust-anything/releases), and for JavaScript projects npm installs the same binary.
`setup` adds the MCP server to each agent it finds and installs the workflow skill where the agent reads skills. See [Set up your agent](https://rustanything.ai/docs/introduction/agents) for what it changes.
## Ask your agent
- *"Rewrite this CLI in Rust with rust-anything, end to end, and prove it behaves the same."*
- *"This search feels slow. Profile it with rust-anything and move the hot loop to Rust."*
- *"Plan a migration of `src/parser/` to Rust with rust-anything; port the first unit and prove it."*
- *"Bench the Rust port in `rust/text-rs` against the original and tell me whether to ship it."*
## Or run the steps yourself
The steps on x18n's `fuzzyScore`: `profile` finds the hot loop, `bridge --batch` generates the crate, `gate` passes, and the benchmark compares it with the TypeScript.
```sh
rust-anything profile . -- node bench.mjs # what is hot, and who calls it
rust-anything bridge . src/fuzzy.ts --batch fuzzyScore:text
# write src/port.rs (or let your agent), then:
rust-anything record rust/fuzzy-rs && rust-anything build rust/fuzzy-rs
rust-anything diff rust/fuzzy-rs # every recorded case must match
rust-anything bench rust/fuzzy-rs # faster? the verdict says
rust-anything gate rust/fuzzy-rs # done means this passes
```
Each step is explained in [The loop](https://rustanything.ai/docs/concepts/the-loop).
::: tip When something is missing
If a step fails because a runtime, the agent setup or the MCP server is missing or out of date, run [`rust-anything doctor`](https://rustanything.ai/docs/introduction/doctor).
:::
---
# Install
## From crates.io, npm or a release
::: tabs
== cargo
```sh
cargo install rust-anything
rust-anything setup
```
== npm
```sh
npm install -g rust-anything
rust-anything setup
```
:::
npm installs the same binary, for JavaScript projects.
Prebuilt binaries for macOS, Linux and Windows are attached to each [GitHub release](https://github.com/erkamyaman/rust-anything/releases). In Claude Code you can also install it as a plugin (the MCP server and the skill; the CLI must be on your `PATH`):
```text
/plugin install rust-anything --marketplace erkamyaman/rust-anything
```
## From source
```sh
cargo install --path .
```
`record`, `diff` and `bench` run the original in its own runtime: Node 22.6+ for TS (it runs `.ts`
sources directly, adding `--experimental-strip-types` on 22.6 to 22.17), Python 3.9+ for Python
and C (ctypes), Go 1.22+, Ruby 3+, JDK 17+ (`javac` and `java`), `kotlinc` for Kotlin, PHP 8+
with the FFI extension, the .NET SDK (`dotnet`) for C#, and PowerShell 7.4+ (`pwsh`). `profile` passes `--cpu-prof` to a `node` command as arguments when that Node refuses it in `NODE_OPTIONS` (22.14 does); through a wrapper such as `npx` or `npm run` it needs a Node that allows it there (24 does). C also needs a C compiler. wasm bridges also need `rustup target add wasm32-unknown-unknown` and
`cargo install wasm-bindgen-cli --version --locked`; `build` names
the exact version.
## Windows
Native Windows CI uses the `x86_64-pc-windows-msvc` Rust target. Install the stable MSVC
toolchain and Visual Studio Build Tools with the **Desktop development with C++** workload; the
C compiler and linker are required for C bridges and native Rust extensions. Install the runtime
for the source language you are migrating. Python may be available as either `python3` or
`python`; rust-anything detects both. The GNU Windows target is not exercised by CI.
Run the native bridge integration suite from a Developer PowerShell prompt:
```powershell
rustup default stable-x86_64-pc-windows-msvc
cargo test --locked --test native -- --nocapture
```
The suite builds and loads real DLL-backed Node and Python extensions and the supported native
bridges for each runtime present on `PATH`. Missing optional runtimes are reported as skipped;
Cargo, the active Rust standard library, and the MSVC linker are required. If Cargo reports that
it cannot find `std`, reinstall the active target with
`rustup target remove x86_64-pc-windows-msvc` followed by
`rustup target add x86_64-pc-windows-msvc`. If linking fails, run from a Visual Studio Developer
PowerShell and verify that `where.exe link` finds the MSVC linker. Tests use temporary folders,
including a path with spaces and Unicode characters, and remove generated artifacts after a
successful run.
## Update or remove
```sh
cargo install rust-anything # update (Cargo)
npm install -g rust-anything@latest # update (npm)
rust-anything setup # refresh agent settings
rust-anything setup --remove && cargo uninstall rust-anything # remove (Cargo)
rust-anything setup --remove && npm uninstall -g rust-anything # remove (npm)
```
`setup --remove` takes out only rust-anything's entries; the copies it saved
(`.rust-anything.bak`) stay until you delete them.
---
# Set up your agent
```sh
rust-anything setup
```
`setup` adds the MCP server to each agent it finds and installs the workflow skill where the agent reads skills. It keeps your other settings, is safe to run again, and `--remove` undoes it.
## Works with
| Agent | `rust-anything setup` adds |
| --- | --- |
| Claude Code | MCP server in `~/.claude.json`, skill in `~/.claude/skills/` |
| Codex | MCP server in `~/.codex/config.toml`, skill in `~/.codex/skills/` |
| Cursor | MCP server in `~/.cursor/mcp.json` |
| Gemini CLI | MCP server in `~/.gemini/settings.json` |
| Any other MCP client | add `rust-anything mcp` as a stdio server by hand (below) |
**Community integrations** (not maintained by Rust Anything): [dsh-rust-anything](https://github.com/lonyness/dsh-rust-anything) by [@lonyness](https://github.com/lonyness) runs Rust Anything inside DeepSeek Harness. It ships its own pinned copy of the engine (currently 3.3.0).
Before changing a file that exists, `setup` saves a copy beside it (`.rust-anything.bak`). `setup --remove` takes out only rust-anything's entries; the copies it saved stay until you delete them.
## The MCP server
`rust-anything mcp` serves every step as an MCP tool over stdio: `profile`, `analyze`, `bridge`, `refresh`, `record`, `build`, `diff`, `bench`, `shadow`, `gate`, and for a whole app `app_record`, `app_replay`, `app_front_door`, `app_wire`, `app_lift`. Every tool, its parameters and what it may touch: [MCP tools](https://rustanything.ai/docs/reference/mcp-tools). The server also offers two prompts, `port_unit` and `port_whole_app`, built from the skill.
To add the MCP server to one project by hand instead:
**.mcp.json**
```json
{ "mcpServers": { "rust-anything": { "command": "rust-anything", "args": ["mcp"] } } }
```
## The skill
The workflow skill ([`skills/rust-anything/SKILL.md`](https://github.com/erkamyaman/rust-anything/blob/main/skills/rust-anything/SKILL.md)) tells the agent how to run the loop: profile, plan and stop for approval, port one unit, prove it, ship it behind a shadow, and call it done only when `gate` passes. For a whole app it follows [`whole-app.md`](https://github.com/erkamyaman/rust-anything/blob/main/skills/rust-anything/whole-app.md); see [Port a whole app](https://rustanything.ai/docs/whole-apps/overview).
## Claude Code plugin
```text
/plugin install rust-anything --marketplace erkamyaman/rust-anything
```
The plugin brings the MCP server and the skill; the CLI must be on your `PATH`.
---
# Doctor
```sh
rust-anything doctor
rust-anything doctor --json
```
`doctor` checks the language runtimes, the agent setup and the MCP server, and prints the command that fixes each problem. It exits 1 when something required is missing.
Run it when a step fails because a runtime, the agent setup or the MCP server is missing or out of date. The workflow skill tells agents to do the same.
## What each language needs
`record`, `diff` and `bench` run the original in its own runtime: Node 22.6+ for TS (it runs `.ts` sources directly), Python 3.9+ for Python and C (ctypes), Go 1.21+, Ruby 3+, JDK 17+ (`javac` and `java`). `profile` on Node needs Node 24+, which allows `--cpu-prof` in `NODE_OPTIONS`. C also needs a C compiler. wasm bridges also need `rustup target add wasm32-unknown-unknown` and the matching `wasm-bindgen-cli`; `build` names the exact version.
## For contributors
`cargo run -- doctor` lists which runtimes you have, their versions, and the command that installs or updates each one. See [Contributing](https://rustanything.ai/docs/project/contributing).
---
# The loop
Every port, from one hot function to a whole app, goes through the same steps one unit at a time. A port is done only when `gate` passes.
How rust-anything checks a port, what its commands decide, and where its limits are. Back to the [README](https://rustanything.ai/).
## How it works
```
profile ──> analyze ──> bridge ──> record ──> port.rs ──> diff ──> bench ──> shadow ──> gate
where the what to the Rust what the you or every faster? both side done means
time goes port first crate and original your agent recorded the by side in this passes
wrapper does write it case verdict production
```
The original stays the source of truth: `record` runs it on edge cases (and your own inputs) and
saves what it returns or throws; `diff` replays every case against the Rust; nothing ships until
they all match and `gate` passes. Callers keep the original API throughout.
A whole app goes through the same loop unit by unit, inside a frame that proves the whole
program ([Port a whole app](https://rustanything.ai/docs/whole-apps/overview)):
```
analyze --whole-app ──> app record ──> app front-door ──> per unit: the loop above, then app wire ──> app lift
shape, every what the app Rust owns the gate passes, so the unit answers in pure Rust,
dependency, the does from the entry point; the Rust: replay 100%, fallback rate down proved by
decisions to make outside original answers replay
```
## The loop
| Step | Command | What it does |
| --- | --- | --- |
| All in one | `rust-anything go --agent claude -- python3 app.py` | The hot-path loop end to end: profile, pick the outermost portable function (batched where `profile` says so), bridge it into `rust/-rs`, record generated cases plus the calls the run makes, hand `src/port.rs` to the agent (`claude`, `codex`, or any command reading a prompt on stdin; without `--agent` it writes `TASK.md` and stops), then build, diff, gate and bench, and `enable` only when all pass and the port is not slower as its callers call it (otherwise it says where the speed is: the batch class to call from the loop, or the caller to port with it). Run it again after porting by hand: finished steps are kept |
| 0. Profile | `rust-anything profile -- node bench.mjs` | Runs a real workload under the language's profiler (node, cProfile, `go test` pprof, JFR, a Ruby tracer): hot functions by inclusive time, their callers, and which loops to batch; flags code that is already compiled (numba, Cython, JAX), where Rust gains little, and time spent waiting on child processes, which porting does not shorten |
| 1. Plan | `rust-anything analyze ` | Units, port order, risks with `file:line`, bridge per unit, dependency-to-crate fit, best first ports; `--whole-app` adds entry points and shape, every dependency (imported or declared) with its crate, pieces (units that import each other move together) and numbered decisions with a recommended answer |
| 2. Bridge | `rust-anything bridge ` | Crate with the bindings (`lib.rs`, plus the wrapper the source language loads) and stubs to port (`port.rs`); `--batch fn:param` adds a class that keeps many `param` values in Rust; `--as-json T` bridges a type parameter the app only fills with data as JSON values |
| 3. Record | `rust-anything record ` | Runs the original on generated edge cases (non-ASCII, emoji, `-0`, `NaN`, ints where floats are expected, ...) and on every semantic trap in every parameter (string length and case, signed division, overflow edges, float printing, map and sort order), and saves `cases.jsonl`; `--from-tests -- npx jest` (or `-- pytest`) also records every call the original's own test suite makes; `--float-tolerance 1e-9` lets floats match within that share for numeric code; `--pin-clock` (TS/JS, Python) fixes the clock and random numbers during record and diff, and `src/port/pinned.rs` gives the port the same ones |
| 3. Build | `rust-anything build ` | Builds the Rust side: `.node`, wasm package, Python extension or shared library |
| 3. Diff | `rust-anything diff ` | Replays the recorded cases against Rust, called the way the original's callers call it; lists mismatches, each with where it first differs (`return`, `throw` or `call N`, the JSON path such as `$.items[2].name`, the kind of difference, and for text the character with a little context), and the distinct differences with how many cases each covers under a short stable id, so 40 failing cases from one bug read as one line; `--redact` prints all of it as shapes only (types, lengths and hashes, no values or arguments), safe to paste into an issue or hand to another agent |
| 3. Fuzz | `rust-anything fuzz ` | Fresh inputs from a new seed (`--seed`, `--cases`, `--time`) through the original and Rust; reports what the recording missed, and `--keep` adds those cases to it |
| 3. Bench | `rust-anything bench ` | Times the recorded cases on the original and on Rust, bridge included |
| 4. Shadow | `rust-anything shadow ` | Drop-in that runs both, returns the original's result, reports mismatches; `RUST_ANYTHING_MODE=old\|shadow\|new` |
| 5. Gate | `rust-anything gate ` | fmt, clippy `-D warnings`, tests, `unsafe` audit, nothing unported, a recorded failing case for every error path of the original, no `unwrap`/`expect`/`panic!` where the original returns an error (unless marked `// INFALLIBLE: `), build, API, behavior (no `known-diffs.jsonl` entry that no longer differs), a recording that is neither stale (the original changed since `record`) nor altered (a recorded case edited or removed; cases `fuzz --keep` appended are fine), size (no more than 3x the original's lines plus 50), and the [cheat guard](#what-gate-refuses-to-count). It also reports coverage (how many of the original's lines the recorded cases ran), and only warns, without failing, about a missing or out-of-date `Cargo.lock` and about advisories from `cargo deny` or `cargo audit` when one is installed |
| 6. Switch | `rust-anything enable ` / `disable ` | Turns a gated TS/JS, Python or PowerShell port on for every caller, and off again byte for byte ([Switch a port on and off](https://rustanything.ai/docs/concepts/switch)) |
| 7. Report | `rust-anything report ` | `report/REPORT.md` and `report/card.svg` for a pull request: recorded cases matched, speedup from `bench`, fallback rate, on or off, the machine and its cores |
| Cache | `rust-anything clean` | Removes the build folder every port and bridge shares ([One build cache](https://rustanything.ai/docs/concepts/switch)) |
| Agents | `rust-anything setup` | Registers the MCP server (`rust-anything mcp`, every step as a tool) and the workflow skill ([`skills/rust-anything/SKILL.md`](https://github.com/erkamyaman/rust-anything/blob/main/skills/rust-anything/SKILL.md)) with your coding agents |
## Hot paths: keep the data in Rust
A port called once per item pays the bridge once per item, and loses to a JIT. What wins is
moving the loop: `profile` finds it, and `--batch` generates a class that takes the items once
and runs the function over all of them per call, on all cores, with typed-array results.
```sh
rust-anything profile ../x18n -- node --experimental-strip-types $PWD/demo/x18n-search/search.ts .
# -> fuzzyScore: a quarter of the run, called per key by `matched`: batch it
rust-anything bridge ../x18n packages/core/src/fuzzy.ts --batch fuzzyScore:text
```
```js
const search = new FuzzyScoreBatch(keys) // once
const order = search.rank(query, 0) // per keystroke: indexes, best first
```
A `FuzzyScoreIndex` struct in `port.rs` replaces the default loop with one that prepares the
items once, and can rank by itself (`rank`): it keeps the keys lowercased with a character mask
each, a table of each key's first position of every common character (a one-letter query is one
column), and the last query's matches (typing `se` after `s` rescores only what `s` matched). On
x18n's sidebar search over 50,000 keys, typed letter by letter, with identical results:
| | Per query | vs TS |
| --- | ---: | ---: |
| TS: `map(fuzzyScore)`, filter, sort | 10 ms | 1x |
| TS with the same narrowing as the index | 4.1-5.4 ms | 2x |
| The same port, called per key | - | 0.2-0.4x |
| `FuzzyScoreBatch`, default index (4 cores) | 5.1 ms | 1.7x |
| `FuzzyScoreBatch` with `FuzzyScoreIndex` (napi, 4 cores) | 0.45-0.56 ms | **18-22x** |
| The same with wasm (one thread) | 0.95 ms | **11.5x** |
Against TS doing the same narrowing, Rust is still 7-12x faster (wasm 5x). Turn the returned
indexes into keys with a plain loop: `Array.from(order, i => keys[i])` cost 20x more, 0.4 ms.
Every language gets batches. Below, the Rust batch runs on 4 cores and the original on one
thread, as the original code is written. Identical results and errors (benchmarks in each demo
folder):
| Language | Workload | Original (1 thread) | Per-call port vs original | Batch (4 cores) vs original |
| --- | --- | ---: | ---: | ---: |
| TS | x18n search, 50,000 keys | 10 ms | 0.2-0.4x | **20x** |
| Python | `slugify`, 20,000 strings | 98 ms | - | **17x** |
| Ruby | `slugify`, 20,000 strings | 110 ms | - | **12.7x** |
| Ruby | `shellescape` (stdlib), 50,000 mixed values | 88 ms | - | **11.8x** |
Go and Java are left out: they can run the original on 4 threads just as easily, and measured
that way the Java original beats the Rust batch ([#110](https://github.com/erkamyaman/rust-anything/issues/110)). Batch crates allocate with
mimalloc: with the system allocator the Go batch was slower than one thread. `bridge --allocator
rusty_alloc` opts into a pure-Rust allocator instead. Demo: [`demo/x18n-search`](https://github.com/erkamyaman/rust-anything/blob/main/demo/x18n-search/README.md).
## Switch a port on and off
Every way to switch, in one place:
| What | On | Off |
| --- | --- | --- |
| A TS/JS, Python or PowerShell unit, in place | `rust-anything enable `: one marked block in each original file rebinds the ported functions to the Rust module, so every caller gets Rust and no import changes. It refuses while a recorded case differs (`--force` skips that check); `go` runs it only after diff and gate pass | `rust-anything disable `: removes exactly the lines `enable` added, so the files are byte for byte what they were |
| That unit, for one run | (on by default once enabled) | `RUST_ANYTHING_UNIT_=original` (`` is the crate name without `-rs`, upper case: `RUST_ANYTHING_UNIT_DEDUPE`), or `RUST_ANYTHING_MODE=old` for every unit |
| A shadow module (any language) | Import it where the app imported the original; `RUST_ANYTHING_MODE=new` runs only Rust | `RUST_ANYTHING_MODE=old`; the default, `shadow`, returns the original's result and compares Rust |
| A unit wired into a front door (`app wire`) | Wired units answer in Rust | `RUST_ANYTHING_UNIT_=original` sends that unit's commands to the original |
| An installed package (`package`) | The platform's binary | `RUST_ANYTHING_MODE=old` runs the original it depends on |
The `enable` block names the crate by a path relative to the source file, so it holds no path
of your machine, and it falls back to the original when the module does not load (with
`RUST_ANYTHING_MODE=new` that is an error instead). `record`, `diff`, `bench` and `fuzz` set the
unit's switch to `original` for the original's side, so an enabled unit is still measured
against the original. Other languages switch through the shadow module.
## One build cache
Ports and bridges build into one cargo target folder: `CARGO_TARGET_DIR` when it is set, else
`rust-anything/target` in your cache folder (`~/Library/Caches` on macOS, `$XDG_CACHE_HOME` or
`~/.cache` on Linux, `%LOCALAPPDATA%` on Windows). napi-rs, PyO3, serde and the rest compile once
for every crate instead of once per crate. `rust-anything clean` removes the folder
(`--dry-run` prints its size; a folder named by `CARGO_TARGET_DIR` needs `--force`, since other
projects may build there).
Cargo names a crate's library after its package name alone, so two crates with one name would
replace each other's library in a shared folder (see `docs/pitfalls.md`). Each package name
belongs to one crate folder there (`owners.json`, written under a lock); another crate with the
same name builds in its own `target/` as before, and gets the name back once the first folder is
gone. Each crate's libraries are copied to its own `target/release`, where every loader reads
them. Front doors (`rust/app`) keep their own `target/`, since every app's binary would have the
same name.
## What `bridge` decides
- Exports that cannot cross a bridge stay in the source language, with the reason, and the shadow
module re-exports the original. For TS:
functions that take or return functions, generators and iterators, RegExp, `instanceof` checks,
generics (`--as-json T` bridges one the app only fills with data), and values whose types (followed through imports, re-exports and `extends`) hold
functions. `--keep "name: reason"` keeps more, e.g. code that depends on `Intl` data.
- TS types map to Rust types, with type aliases resolved through imports and parameter types
inferred from default values; structured values cross as a generated binary wire (JSON only
as a fallback for shapes the wire does not model).
- JSON cannot express `undefined`, NaN, Infinity, -0 or lone surrogates: structured values carry
markers (`{"$undefined": true}`, `{"$num": "NaN"}`, `{"$utf16": [...]}`) that the generated
`index.cjs` translates, with helpers in the crate's `js.rs`.
`record` runs TS sources as they are: a Node resolve hook follows bundler-style imports
(`./errors` to `./errors.ts`), `--resolve-from` supplies npm packages when the repo has none
installed, and TS that needs transforming (enums, parameter properties) is retried with
`--experimental-transform-types`.
## What `analyze` looks at
- Packages (`package.json`) and source files; skips `node_modules`, build output, fixtures,
playgrounds, tool configs. Vue/Svelte/Astro `