deniz.in

Markets

Weather

Loading weather

· via dev.to (home feed)

Rust CLI urai-ecma claims to prune JS/TS codebases by 80% to cut LLM token waste

A developer-built Rust CLI parses JavaScript and TypeScript into syntax trees and strips markup noise, reportedly cutting a 209,757-token codebase to roughly 36,000 tokens for LLM prompts.

Rust CLI urai-ecma claims to prune JS/TS codebases by 80% to cut LLM token waste

Rust CLI compresses JS/TS repos for LLM prompts

A developer posting on dev.to under the handle sanjaiyan_dev has built urai-ecma, a multi-threaded command-line tool written in Rust that shrinks JavaScript and TypeScript codebases before they are handed to large language models. According to the post, the tool compressed a codebase measuring 209,757 raw tokens down to roughly 36,000 tokens — an 82.7% reduction — in milliseconds.

The author says the motivation came from building an agentic Chrome extension driven by local LLMs. Whole-repository dumps pushed each scan past 200,000 tokens, slowed local inference to a crawl, and, in the author's telling, led the model to hallucinate core functions because key architectural interfaces were buried under repetitive markup and loops.

The cost of dumping a whole repo

The post argues that when a typical React or Next.js repository is concatenated into a prompt, more than 70% of the tokens are dead weight: long strings of static Tailwind utility classes, imperative loops, array mappers and formatting logic that reveal little about application architecture. It frames four resulting costs: attention degradation as critical interfaces get lost in the middle of oversized prompts; time-to-first-token lag because prefill scales with prompt size; paying frontier-model API rates to ingest 80-character class strings, which the author dubs a "Tailwind tax"; and faster exhaustion of tokens-per-minute quotas in CI pipelines.

AST-aware pruning instead of concatenation

Tools such as repomix, gitingest and code2prompt are, in the author's characterisation, file dumpers: they walk a directory, wrap the raw text in fences and forward every line to the model. urai-ecma takes a different route, parsing source files into abstract syntax trees with the swc_ecma parser engine and then applying deterministic transformations.

The pipeline works like this: a Rust ignore-based walk honours .gitignore and skips node_modules and dist; files (.ts, .tsx, .js, .mjs and .) are parsed in parallel across CPU cores using Rayon work-stealing; and a set of AST visitors extracts what matters. A RouteVisitor builds route tables for Next.js, Express and NestJS; a ReactComponentAnalyzer captures props, state, hooks and JSX structure; a ReactJsxPruner strips static class strings; and a FunctionSummarizerVisitor reduces function bodies to stubs. Results pass through a hybrid disk-and-RAM cache (Foyer) with SHA-512/256 hashing and Zstd compression, and the tool emits a Markdown prompt along with a token report counted with the o200k BPE tokenizer.

Structural stubbing as a middle path

The most interesting design decision is what the author calls structural stubbing. Straight minification forces a choice: keep full function bodies and waste tokens on loops and arithmetic, or strip to bare signatures and lose hooks, event listeners and layout. Instead, the stubbing pass inspects AST statements and retains only those that define a component's anatomy — nested function declarations, variables initialised to arrow functions or function expressions, calls to hooks (identifiers beginning with "use"), timers and listeners such as setTimeout, setInterval and addEventListener, and return statements carrying JSX hierarchies. Everything else inside a body is discarded.

The name is a nod to classical Tamil scholarship: urai ezhuthudhal, the tradition of writing dense commentaries on works such as the Thirukkuṛaḷ, where commentators distilled structure and intent without destroying depth. The tool, the author writes, aims to do the same for modern enterprise JavaScript.

Caveats worth noting

All figures come from a single self-reported benchmark on the author's own project, published on dev.to and not independently verified. The reduction will also vary with the shape of the codebase: markup-heavy React components with long class strings compress dramatically, while logic-dense services with few components offer far less to strip. And like any summarisation approach, stubbing discards implementation detail, which matters if the question you ask a model concerns the internals of one function rather than the architecture around it.

Why it matters

As coding agents become routine infrastructure, prompt size is a direct line item: it drives token spend, time-to-first-token latency and rate-limit behaviour. urai-ecma is an early example of repurposing mature compiler tooling — Rust, SWC, parallel parsing — to compress context semantically rather than by truncation, giving models architectural awareness at a fraction of the cost. If reductions in this range hold across real codebases, preprocessing of this kind is likely to become a standard step in agent pipelines, and the approach is one other tool builders can borrow regardless of whether they adopt this particular CLI.

  • #rust
  • #llms
  • #developer-tools
  • #cli
  • #typescript

Related posts