Build a coding agent from scratch in 600 lines of TypeScript: pi-from-scratch shows you the guts
What this project actually does
pi-from-scratch is an interactive tutorial and source repository whose goal is to hand-write a coding agent from absolute zero. It does not posture; it directly walks you through building a miniature programming agent — internally called nano-pi — in roughly 600 lines of TypeScript, and that tiny agent can read files, edit code, and execute commands. The ambition is not to ship a production tool but to take the well-known pi project, tear apart its data flow, strip away the heavy engineering boilerplate, and keep only the core idea: how an agent receives a task, how it calls tools, how it reads and edits files, and how it loops until the job is done. The most delightful twist is that the article and the source live together — as you scroll down, the editor on the right progressively fills in the code, so by the time you finish reading, the complete nano-pi implementation is sitting right there in the editor, not hidden behind a link.
Why it blew up recently
It was only created on August 9 and already pulled over 500 stars within days, riding the wave of "everyone wants to know how agents are actually built." Today's agent frameworks keep getting heavier; a beginner is immediately intimidated by terms like LangGraph, Tool Calling, and Memory. pi-from-scratch goes the opposite direction. It says "relax, this is an article, not a book" and explains the skeleton of an agent in the plainest possible way. This "de-magicked" narrative is exactly what the AI community loves — people are tired of black boxes and want to touch the wheels and see how they turn. On top of that, the author deliberately emphasizes "hand-typed the old-fashioned way, as AI-free as possible," which only stokes curiosity further and makes the writing feel like a real person teaching you rather than a generated doc.
Technical highlights
It is organized along pi's data flow: whenever a component is needed, it is built on the spot, and every module stays intuitive without piling on abstractions. nano-pi is small but complete — it can read files, edit code, and run shell commands, which is the core loop of any coding agent. The project also ships a dedicated Trace feature that lets you set breakpoints and single-step through the code line by line, laying bare the agent's execution flow: which step called which tool and what it returned. For anyone learning to hand-write an agent, this is practically microscope-level visualization, the kind you wish every framework shipped with. Running it is trivial too: Node.js 22 or newer plus an OpenAI-compatible API key (NANOPI_API_KEY), then npm install and npm run dev brings nano-pi to life. Want a different model or endpoint? Just change the NANOPI_MODEL and NANOPI_BASE_URL environment variables; it defaults to the standard OpenAI endpoint, so swapping in a local model or a compatible provider is a one-line change.
Who it is for
It is a great fit for frontend developers, TypeScript enthusiasts, and any AI learner who has "used a bunch of agent frameworks but never understood what's under the hood." If you know a little TypeScript and want to truly grasp how tool calling and the agent loop are implemented — rather than just calling someone else's SDK — this project is the best live teaching material you can find. It is not for people who want to ship something to production tomorrow; it is explicitly educational, and the trace on the live demo is pre-generated static data that does not actually fire requests. But as the first step from "framework user" to "wheel builder," the barrier to entry is touchingly low, and the payoff in intuition is disproportionately large compared with the small time investment.
Quick start
Clone the repo, install dependencies, set your API key, and run the dev server. Open the local address in a browser and you can read the article while watching the code complete itself on the right. If you only want the teaching website, go into the web directory, npm install, and npm run dev. There are no heavy dependencies, so you can clone it and have it running in a few minutes, which lowers the commitment enough that even the curious-but-busy will actually finish it.
How it compares
Compared with those "batteries-included" agent frameworks, pi-from-scratch occupies a completely different niche. LangChain and LangGraph give you a huge pile of abstractions and components — convenient, but black-boxed and steep to learn. CrewAI and AutoGen emphasize multi-agent collaboration, which adds even more engineering detail. pi-from-scratch flips that: it does not chase feature completeness, it only chases comprehension. It is more like a living textbook than a Swiss Army knife. If you need productivity, go use a ready-made framework; if you need the moment of "oh, now I finally get how an agent runs," this 600-line mini implementation beats any documentation out there, because you have written the wheels yourself instead of merely trusting that they exist.