← all repositories
SaladDay/pi-from-scratch

Rebuilding the 'pi' Coding Agent in 600 Lines of TypeScript

An interactive tutorial that rebuilds the 'pi' coding agent in ~600 lines of TypeScript, revealing the source code line-by-line as you read.

1.1k stars TypeScript Coding AssistantsAgents
pi-from-scratch
Collecting fresh signals — velocity needs a few days of history.
collecting data…
star history

What it does This project teaches you how a coding agent ticks by rebuilding the core of pi in roughly 600 lines of TypeScript. The resulting nano-pi handles file reads, code edits, and shell commands through an OpenAI-compatible API, but the deliverable is comprehension, not a framework.

The interesting bit The tutorial lives on a custom site where the article and source code share the stage: scroll through the prose and a side editor progressively writes itself, while a trace viewer lets you step through the agent loop with breakpoints—no local debugger required.

Key highlights

  • ~600 lines of TypeScript, stripped of production engineering noise
  • Reproduces the pi agent’s data flow with “intuitive” hand-built components
  • Website syncs scrolling text with live code generation in an embedded editor
  • Trace viewer uses pre-generated static data, so the tutorial runs offline
  • Needs Node.js 22 and an OpenAI-compatible key to run the agent locally

Caveats

  • The hosted trace is static; you’ll need local setup plus an API key to see live agent behavior
  • Explicitly billed as an article, not a library—expect pedagogy, not plug-and-play automation

Verdict Perfect if you want to understand agent loops by watching one grow from zero. Skip it if you need a mature coding assistant for your day job.

Frequently asked

What is SaladDay/pi-from-scratch?
An interactive tutorial that rebuilds the 'pi' coding agent in ~600 lines of TypeScript, revealing the source code line-by-line as you read.
Is pi-from-scratch open source?
Yes — SaladDay/pi-from-scratch is open source, released under the MIT license.
What language is pi-from-scratch written in?
SaladDay/pi-from-scratch is primarily written in TypeScript.
How popular is pi-from-scratch?
SaladDay/pi-from-scratch has 1.1k stars on GitHub.
Where can I find pi-from-scratch?
SaladDay/pi-from-scratch is on GitHub at https://github.com/SaladDay/pi-from-scratch.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.