Rust Anything
Port TypeScript, Python, C, Go, Ruby, or Java code to Rust with profiling and testing.
Installation
- Make sure Claude is on your device and in your terminal.
Skills load from
~/.claude/skills/when Claude Code starts up — so you need it on your machine first. If you don't have it yet, install it once with the command below, then runclaudein any terminal to verify.One-time setupnpm i -g @anthropic-ai/claude-codeAlready have it? Skip ahead.
- Paste into Claude Code or into your terminal.
This copies the whole skill folder into
~/.claude/skills/rust-anything-erkamyaman/— the SKILL.md plus any scripts, reference docs, or templates the skill ships with. Works for every skill.What this command does
- Makes a new, empty temporary folder.
- Downloads the skill's folder,
directory/skills/rust-anything, fromgithub.com/erkamyaman/rust-anything(branchmain), the GitHub repository it's listed from. You get the version that is there now, not a copy we keep. - Copies that folder to
~/.claude/skills/rust-anything-erkamyaman/. - Deletes the temporary folder.
Installing runs none of the skill's files; it only downloads and copies them. When you later use the skill, Claude follows its SKILL.md and may run scripts that come with it. Read them first.
Faster alternative (instruction-only skills)
Skips the clone and grabs only the SKILL.md file. Don't use this if the skill ships Python scripts, reference markdowns, or asset templates — they won't be downloaded and the skill will fail when it tries to load them.
Quick install (SKILL.md only)Sign up to copy - Restart Claude Code.
Quit and reopen Claude Code (or any other agent that loads from
~/.claude/skills/). New skills are picked up on startup. - Just ask Claude.
Skills auto-activate when your request matches the skill's description — no slash command needed. Trigger phrases live in the skill's own frontmatter; you can read them in the “What this skill does” section above.
Prefer to read the source first? Open on GitHub.
When Claude uses it
Port TypeScript/JavaScript, Python, C, Go, Ruby or Java to Rust with the rust-anything CLI or MCP tools, from one hot function up to a whole app rewritten as a pure Rust app - profile, plan, bridge one unit at a time, record the original's behavior, port, diff, bench, shadow and gate; batch hot loops so they run in Rust on all cores. Use when asked to rewrite, port or migrate code or an app to Rust, to plan such a migration, or to make slow code faster with Rust.
What this skill does
Migration to Rust with rust-anything
rust-anything gives you ground truth; you write the Rust. Port one unit at a time, even when the
goal is the whole app, and call a port done only when gate passes.
Whole app to a pure Rust app (the user wants the app rewritten in Rust, with the original kept only as reference): read whole-app.md first and follow it. It grills the user on the decisions, researches the dependencies, records the whole app, puts a Rust front door in front of the original, runs the steps below for every unit, then lifts the app to a standalone Rust binary (or, for a library, one pure Rust crate). CLIs, HTTP servers and libraries.
Languages: TypeScript/JavaScript, Python, C, Go, Ruby, Java. The language is detected; --lang
overrides it. The steps are the same everywhere; only the bridge differs (napi-rs or wasm for
TS, PyO3, a C ABI, cgo, a magnus extension, JNI), and the original's callers keep their API.
For PHP: analyze, and for a whole app app record, app replay and
app front-door (CLIs, and servers run with php -S 127.0.0.1:{port} router.php); bridge does not
take PHP units yet, so tell the user before planning a PHP port past the front door. C# works
the same way: record a built app (dotnet out/app.dll, servers with
--urls http://127.0.0.1:{port}); bridge does not take C# units yet.
Tools: the rust-anything CLI, or the same steps as MCP tools (rust-anything mcp): go,
profile, analyze, bridge, refresh, record, build, diff, bench, shadow, gate,
enable, disable, report, and for a whole app app_record, app_replay, app_front_door, app_wire, app_lift.
If the MCP tools are not available, use the CLI; if rust-anything is not installed, ask the user
to install it (cargo install rust-anything) and run
rust-anything setup, then restart the agent. When a step fails because a runtime, the agent
setup or the MCP server is missing or out of date, run rust-anything doctor: it checks each one
and prints the command that fixes it.
Only the slow part: go
When the user wants one slow command faster rather than a migration, go runs steps 0 to 5 for
the top hot function in one call:
rust-anything go -- python3 app.py # profile, bridge, record, write rust/<fn>-rs/TASK.md
# port src/port.rs as TASK.md says (build, diff, gate), then the same command again:
rust-anything go -- python3 app.py # build, diff, gate, and enable when all pass
It picks the outermost exported function of a portable unit that takes arguments, batched where
profile advises it (--function picks another), and records generated cases plus the calls the
workload makes. You are the agent: port only that function, and do not pass --agent (that hands
the port to another agent process). go switches the unit on only when every case matches, gate
passes and bench shows it is not slower as its callers call it; a slower stage names the
batch class to call from the loop or the caller to port with it. Report its stage and next step
to the user. rust-anything report <crate> then writes
report/REPORT.md and report/card.svg with measured numbers for the pull request.
0. Profile: find what is worth moving
When the goal is speed, measure before choosing anything:
rust-anything profile <repo> -- node bench.mjs # or: python3 bench.py, ruby bench.rb,
# java -cp out Main, go test -run X -bench . ./pkg
It runs a real workload under the runtime's own profiler and lists hot functions with their
callers and advice. Go profiles only through go test; C is not supported (use perf).
- A small function called once per item is not worth porting alone: one call into Rust costs more than its work, and JITs (V8, the JVM, Go) run it in nanoseconds. Port it together with its callers, or batch it (step 2b). The advice line says which, with the exact command.
- Code that is already compiled (numba
@njit, Cython,@jax.jit) runs as machine code: a Rust port gains little speed.profilelists it under "Already compiled" and says so in the advice of every hot function that calls it; tell the user before porting it for speed. - If the user only wants a migration, skip to step 1.
1. Plan, then stop
rust-anything analyze <repo> -o plan.md # people
rust-anything analyze <repo> --json # you: schema rust-anything/analyze@1
- Present the
start_hereunits (best first ports) and the order by package and wave. - Call out
keepunits (UI, editor code: they stay in the source language),blockedunits and their reason, and dependencies with fitnoneorunknown. Do not hand-roll a missing crate silently: flag it. - Wait for the user's approval of the plan and of the first unit.
2. Port one unit
rust-anything bridge <repo> <unit-id> # crate in <repo>/rust/<name>; never overwrites
rust-anything record <crate> # the original's behavior on edge-case inputs -> cases.jsonl
- If the original has tests, record their calls too:
record <crate> --from-tests -- npx jest(TS/JS, any runner) or-- pytest(Python). Every call the suite makes to the unit's exported functions becomes a case; the source is restored afterwards. Exports that are not function declarations (export const f = () => ...) are listed as not captured. - Add real-world inputs with
--inputs cases.jsonl({"fn": name, "args": [...]}per line) when the generated ones cannot reach the interesting paths (structured arguments, domain strings). - TS that cannot run directly in Node (extensionless imports, path aliases): record from built
output with
--module dist/x.mjs, or pass--node-arg=--import=tsx. - If the original has no tests,
recordis the characterization suite: keepcases.jsonl.
Write the port in src/port.rs only; src/lib.rs and the wrappers are generated. After changing
a signature in port.rs, run rust-anything refresh <crate>.
- Read each risk the plan lists for the unit, at its
file:line, before writing code. - String offsets: JS and Java index UTF-16 code units, Rust UTF-8 bytes: use
src/utf16.rs. - Errors: return
Err("TypeName: message"); it becomes that exception in Python, Ruby and Java, and theerrortext in Go. Insideport.rs, a small error enum is clearer; turn it into that string only in the exported function. - Letters and digits: Rust's
char::is_alphanumerictakes more than Java'sCharacter.isLetterOrDigit(letters and decimal digits, per UTF-16 unit, so nothing beyond U+FFFF) or Python'sstr.isalpha(letters only). Match the original's rule by general category. - Numbers in Python and Ruby: ints that the original passes through must come back as ints;
in Python ports use
crate::pynum::Numfor int-or-float, notserde_json::Value. - C: inputs recorded as
crash:are undefined behavior; any result passes. - C pointers: a byte pointer with a length parameter is
&[u8](or&mut [u8]when the function writes it), a pointer to one scalar isOption<&mut T>, and a returned pointer into a parameter is its offset (Option<usize>). In--inputs, give buffers as hex text (a number means that many zero bytes,nullisNULL) and leave length parameters out; recorded results then hold the return value and what the function wrote. A struct of scalar fields passed or returned by value is a#[repr(C)]struct at the crate root (crate::AVRational), and an object of its fields in cases. Achar **/const char **the function points into the firstcharstring argument isOption<&mut Option<usize>>(the offset into it); in cases give the starting offset,truefor aNULLstart, ornullfor aNULL**. Contexts, other structs and other**stay blocked: bridge a small wrapper with plain arguments, and say so. Pass the project's build flags inCFLAGS(-DHAVE_CONFIG_H,-I<root>) when its sources need them. - C strings:
const char *isOption<&[u8]>, which costs astrlenper argument. Where that dominates (short-string helpers), type the parameterOption<crate::CChars<'_>>inport.rsand runrefresh: the port reads the bytes as it goes (next,peek,to_bytes). - Ordered maps and object keys:
indexmapwhere order reaches output. - Regex lookaround or backreferences:
fancy-regex, notregex. Either way,\w,\b,\dand case-insensitive matching treat non-ASCII text differently from the source language's engine: passing the recorded cases is not enough.recordadds regex traps (Turkish i, Kelvin sign, joiners, non-ASCII digits and spaces) to functions in files that use regexes; ask the user for real text the patterns see, record it with--inputs, and setunicode(false)or spell out ASCII classes ([A-Za-z0-9_]) where the original's\wis ASCII-only (JS withoutu, Java). - No
unsafe. If truly needed: minimal, isolated, with a// SAFETY:comment. - Add Rust unit tests in
port.rsfor the cases you reason about.cargo testpassing with no tests proves nothing: the recorded cases are the proof. - To silence a lint, use
#[expect(lint, reason = "...")], not#[allow], so it is flagged once it no longer applies.
2b. Batch a hot loop
For a function called over many items (search, scoring, formatting a list):
rust-anything bridge <repo> <unit> --batch fn:param # or: rust-anything refresh <crate> --batch fn:param
This generates a class that takes the param values once and keeps them in Rust:
new FnBatch(items) (TS, Python, Java), Mod::FnBatch.new(items) (Ruby), NewFnBatch(items)
(Go). Per query, run(<other args>) returns every result as one array, and rank(<other args>, min) returns the item indexes, best first. It runs on all cores, and errors are the original's.
Close the batch when done in Go and Java (finalizers are only a fallback).
- Make the caller build the batch once, not per query. Map returned indexes back to items with a
plain loop; in JS,
Array.from(order, fn)costs 20x more. - To prepare items once (lowercase, masks, position tables), define
pub struct FnIndexinport.rswithnew(items)andrun(<other args>) -> Result<Vec<R>, String>. It must give the same result as the function, item by item: test it against the function over every item. - When ranking can skip work, give the index its own
rank(<other args>, min) -> Result<Vec<u32>, String>(narrowing to the last query's matches as the user types, table lookups). It must match ranking the function's results: score high to low, ties in item order. - A batch multiplies the port's per-item speed by the cores. Against compiled originals (Go,
Java) the port itself must be fast: handle ASCII without Unicode tables, build each result in one
pre-sized
String, avoid intermediate copies. Keepdiffpassing. - Items and other arguments: numbers, booleans and strings (Ruby: any value); results: numbers, booleans or strings. Not for C.
- Batch crates allocate with mimalloc, which is built from C. Pass
--allocator rusty_alloctobridgeif the target has no C compiler.
3. Prove it
rust-anything build <crate>
rust-anything diff <crate> # must be N/N
rust-anything bench <crate> # original vs Rust, bridge included, with a verdict
A mismatch is a behavior difference: fix the port, never the recording. If the difference is
intended (the user wants the port to fix a bug of the original), ask the user first, then add one
line per case to <crate>/known-diffs.jsonl: {"fn", "args", "actual", "reason"}, with fn,
args and actual copied from diff --json. That case then passes only with exactly that result,
and gate fails once it no longer differs, so remove the line then. If gate says the recording
is stale, the original changed: record again before porting further. After pulling upstream
changes, run rust-anything map (the map tool): every port marked changed needs record, then
diff, and the new mismatches are what changed upstream.
When diff says the port is stalled (its trend.stalled: three changes to port.rs in a row
gained no matching case), stop editing. Show the user the remaining mismatches and ask: they may
know the rule you are missing, or decide to keep those functions in the original for now. Each
failed gate check carries a fix: run that first.
Numeric code (physics, statistics, graphics) rarely gives bit-identical floats once ported:
operation order, fused multiply-add and the math library differ. When the user accepts that,
record with --float-tolerance 1e-9 (their number): floats then match within that share of the
larger value (absolute below 1), and diff and gate use it. Integers, strings and the same
value written differently (3 and 3.0) still must match exactly. Never widen a tolerance to make
a mismatch go away: a difference beyond it is a bug in the port.
Follow bench's verdict: ship, keep the slower functions in the source language, or port a
bigger unit (batch or include the callers). Do not ship a port that makes callers slower without
saying so.
4. Ship it safely
rust-anything shadow <crate> # drop-in with the original's API
Load the shadow where the app loaded the original. RUST_ANYTHING_MODE=shadow (default) returns the
original's results and reports Rust mismatches; new switches to Rust; old turns Rust off.
The public API does not change.
For TS/JS and Python, rust-anything enable <crate> switches a gated unit on in place instead: one
marked block in the original files rebinds its functions to Rust for every caller.
rust-anything disable <crate> removes it byte for byte; RUST_ANYTHING_UNIT_<NAME>=original
runs the original for one run. Ask the user before enabling: it edits their source files.
5. Done means gate passes
rust-anything gate <crate>
fmt, clippy with warnings as errors, cargo tests, unsafe only with SAFETY comments, nothing
unimplemented!, every place the original fails on purpose (throw, raise, an error result)
reached by a recorded failing case (add one with record --inputs when gate names it), no
unwrap, expect or panic! in a function whose original returns an error (return Err; for a
state the original also treats as impossible, a // INFALLIBLE: <why> comment), the port at most
3x the original's lines plus 50 for imports and signatures (over that, use the crates analyze lists and fold repeated code), the
module builds, every export present, every recorded case matches. A Rust panic never matches a
recorded error: return Err where the original throws.
Then report to the user, and wait for their go-ahead before the next unit:
- what changed (files, functions, bridge, batches),
- gate output, diff counts and bench numbers,
- behavior differences or risks left (e.g. error messages differ, a napi
Stringrefuses lone surrogates), and what is left in the plan.
Related skills
Generative Code Art
anthropics
Create algorithmic art with p5.js using randomness and interactive parameters.
Poster & Visual Design
anthropics
Create original posters and visual art in PNG and PDF formats.
Claude API Helper
anthropics
Build, debug, and optimize Claude API applications with caching and model migration support.
MCP Server Builder
anthropics
Build protocol servers that connect language models to external APIs and services.