Skip to content

cs01/ChadScript

Repository files navigation

ChadScript

TypeScript, compiled to native code.

ChadScript compiles a statically analyzable subset of TypeScript to native machine code via LLVM — the same backend behind C, Rust, and Swift. No VM, no interpreter, no runtime. The output is a standalone binary: sub-millisecond startup, ~250KB, zero dependencies.

The compiler is self-hosting and the only dependency is itself. Install with curl, not npm.

Status: Beta — self-hosting, 621+ tests, used in production.

Docs · Standard Library · Language Features · Benchmarks


Install

curl -fsSL https://raw.githubusercontent.com/cs01/ChadScript/main/install.sh | sh

No dependencies — everything is bundled in the compiler.


Example: API server

import { httpServe, Router, Context } from "chadscript/http";

const app: Router = new Router();

app.get("/", (c: Context) => {
  return c.html(`<html><body style="font-family:system-ui;max-width:600px;margin:40px auto">
    <h1>ChadScript API</h1>
    <p>A native binary serving this page. Try the endpoints:</p>
    <ul>
      <li><a href="/users/42">/users/42</a> — get user by ID</li>
      <li><a href="/users/alice/posts/7">/users/alice/posts/7</a> — nested params</li>
      <li><a href="/json">/json</a> — JSON response</li>
    </ul>
    <p><code>curl -X POST -d 'hello' localhost:3000/echo</code></p>
  </body></html>`);
});

app.get("/json", (c: Context) => {
  return c.json({ name: "ChadScript", compiled: true });
});

app.get("/users/:id", (c: Context) => {
  return c.json({ id: c.req.param("id") });
});

app.get("/users/:name/posts/:pid", (c: Context) => {
  return c.json({ user: c.req.param("name"), post: c.req.param("pid") });
});

app.post("/echo", (c: Context) => {
  return c.text(c.req.body);
});

httpServe(3000, (req: HttpRequest) => app.handle(req));
chad build app.ts && ./app   # compiles in ~0.3s, starts in <2ms

Hono-style API, C-level performance. One binary, no node_modules. See examples/ for more: weather app (in production at chadsmith.dev/weather), Hacker News clone, WebSocket chat, SQLite, and more.


Benchmarks

ChadScript compiles through LLVM, the same backend behind C and Rust — so it gets the same optimization passes. Compared against C, Go, Node.js, and Bun on Ubuntu (CI):

Benchmark ChadScript Node.js vs Node C
Cold Start 0.6ms 21.8ms 36x 0.6ms
Monte Carlo Pi 0.398s 1.474s 3.7x 0.400s
File I/O 0.089s 0.315s 3.5x 0.088s
JSON Parse 0.005s 0.015s 3.0x 0.004s
Fibonacci 1.424s 2.842s 2.0x 0.725s
Sieve 0.038s 0.054s 1.4x 0.027s
N-Body Sim 1.852s 2.296s 1.2x 1.453s
Quicksort 0.202s 0.249s 1.2x 0.170s
SQLite 0.374s 0.437s 1.2x 0.314s

Full benchmarks with Go and Bun (updated on every PR)


It's Fast

Your code goes through the same LLVM optimization passes as C and Rust — not a JIT, not an interpreter. 0.8ms cold start, native execution speed.

It's Familiar

Classes, interfaces, generics, async/await, closures, destructuring, template literals, JSX, for...of, Map, Set, Promise.all — it's the TypeScript you already write. No new syntax, no new mental model.

It's Friendly

No npm install. Everything ships with the compiler: HTTP server, SQLite, fetch, crypto, WebSocket, JSON, filesystem, regex, child processes, argument parsing. Write your code, compile it, ship a single binary.


Examples

git clone https://github.com/cs01/ChadScript && cd ChadScript

chad run examples/snippets/hello.ts
chad run examples/snippets/parallel.ts          # async/await + Promise.all
chad run examples/snippets/sqlite-demo.ts       # SQLite
chad run examples/apps/http-server/app.ts       # http://localhost:3000
chad run examples/apps/weather/app.ts           # weather app — live at https://chadsmith.dev/weather
chad run examples/apps/hackernews/app.ts        # Hacker News clone

See examples/cli-tools/ for a suite of Unix tool replacements: cgrep, cwc, ccat, ctree, chex, cjq, cql, chttp, and cserve.


Docs