https://github.com/erkamyaman/rust-anything
Asking Claude Code "rewrite this in Rust" mostly works, and that's the problem. It looks right, the tests pass, and three days later you find out it rounds differently, trims a newline, or throws where the original returned null.
Anthropic just published the same lesson from moving their own Messages API to Rust with Claude: the Rust passed about 98% of its tests while only about a quarter of real requests matched (https://www.anthropic.com/research/migrating-api-to-rust). Their fix was to make the old system the judge.
That's the workflow I built rust-anything around. Here's what it looks like in Claude Code:
1. Install once
npm install -g rust-anything # or: cargo install rust-anything
rust-anything setup # adds the MCP server and the skill to Claude Code
2. Ask for the slow part, not the whole app
"This search feels slow. Profile it with rust-anything and move the hot loop to Rust."
Claude runs go, which:
- profiles a real run and picks the outermost function worth moving (the loop, not the tiny call inside it)
- records that function on generated edge cases plus the calls your run actually makes
- hands Claude a src/port.rs to write
3. Claude writes the Rust, the tool checks it
Every recorded case is replayed against the Rust. On a mismatch Claude gets the exact case back and tries again. The port is only switched on when all cases match and gate passes (no unsafe, coverage, size, dependency advisories).
4. Undo is one command
rust-anything disable rust/search-rs # back to the original, byte for byte
What came out of it, measured, every output compared first
- Prettier 3.6.2 on 2,360 files: 128.6 s to 6.9 s (19x), all outputs byte-identical
- Fuse.js search over 50,000 strings: 91.2 ms to 2.8 ms per query (only the scoring loop moved; the rest stayed JS)
- json-server, a whole Node server lifted to one Rust binary: 74 MB to 3.5 MB memory, 514/514 HTTP cases matching
Things I learned watching Claude port code
- Port the loop, not the function. Calling Rust once per tiny function is often slower than the JIT.
- Feed back one example per distinct bug, not 400 failing cases. Claude fixes faster with less noise.
- Claude will sometimes "fix" a mismatch by hard-coding the expected output. Have something that checks for that (I'm adding it to
gate now). - Write down every correction you make as a rule Claude reads before the next port. Same mistakes stop coming back.
Works on Node/TypeScript, Python, Go, Ruby, Java/Kotlin and C. Free, MIT. If you try it on something and it trips, I'd love the report.
https://github.com/erkamyaman/rust-anything