Porting Grok Rust Code to WebAssembly Using Claude Fable
Simon Willison extracted a self-contained terminal Mermaid diagram-to-Unicode renderer from the open-sourced Grok CLI coding agent. He successfully compiled the Rust code to WebAssembly using Claude Code for web (Fable 5) to run it in a browser.
Impact: Medium
Why it matters
This demonstration shows how useful open-source components from complex CLI programs can be quickly ported to run entirely client-side inside web browsers using AI coding tools.
TL;DR
- 01Simon Willison discovered 'xai-grok-markdown/src/mermaid.rs' within the open-sourced Grok CLI coding agent.
- 02The module is a self-contained Rust renderer that outputs Mermaid diagrams as Unicode box art.
- 03Willison ran a prompt in Claude Code for web (Fable 5) to compile the Rust utility to WebAssembly to run in a browser.
Key facts
- Source module
- xai-grok-markdown/src/mermaid.rs
- AI Tool used
- Claude Code for web (Fable 5)
- Target format
- WebAssembly
Extracting the Mermaid Renderer
During an exploration of the newly open-sourced Grok CLI coding agent, Simon Willison discovered the module xai-grok-markdown/src/mermaid.rs. This component serves as a self-contained terminal renderer written in Rust designed for converting declarative Mermaid diagrams to Unicode box art.
Compiling to WASM with Claude Code
To run this Rust-based utility inside a browser, Willison turned to Claude Code for web (Fable 5). He ran a prompt in the tool targeting WebAssembly, successfully creating a browser-based utility that performs the terminal diagram rendering entirely client-side.
✓ When to use
- When you want to port specific CLI Rust components to web browsers quickly.
- When experimenting with AI coding assistants for client-side code conversion.
✕ When NOT to use
- When the Rust codebase relies on heavy system APIs that cannot compile to standard WASM.
- When a full visual SVG rendering of Mermaid is required instead of Unicode terminal art.
What to do today
- Examine the 'xai-grok-markdown/src/mermaid.rs' source in the Grok CLI agent code.
- Try using Claude Code for web to port your own lightweight Rust utilities to WASM.
Sources