A non-official Chinese learning handbook for the Pi Coding Agent terminal harness, covering setup through Skills, Extensions, Subagents and long-running workflows.
SaladDay/pi-from-scratch
A step-by-step tutorial that builds a minimal TypeScript coding agent from scratch, able to read files, edit code and run commands.
- Stars
- 1,304
- Forks
- 109
- Open issues
- 1
- Last commit
- 14 days ago
What is it?
PI from Scratch is a hands-on tutorial that rebuilds the core ideas of the pi coding agent in about 600 lines of TypeScript, called nano-pi. It follows pi's data flow and implements each component only as far as needed to understand it, leaving out production engineering details.
The project is delivered as a readable article paired with source code. On the companion website, the code in the editor is filled in progressively as you read, and a trace feature lets you step through execution line by line with breakpoints. The agent runs against any OpenAI-compatible API, configured through environment variables for the API key, model name and base URL.
Online traces are pre-generated static data, so browsing the site does not make model requests. Running nano-pi locally requires Node.js 22 or later.
Key features
- 01Builds a coding agent that reads files, edits code and runs shell commands.
- 02Follows pi's data flow, keeping only the core design ideas.
- 03Pairs article text with source code that fills in progressively in the editor.
- 04Includes a trace viewer for stepping through code execution with breakpoints.
- 05Works with any OpenAI-compatible API via environment variables.
Use cases
- Learning how a coding agent loop, tool calling and file editing work internally.
- Building your own small agent as a foundation before studying pi in depth.
- Teaching agent architecture in a workshop or course setting.
Quick start
- 1
Install Node.js 22 or newer and get an OpenAI-compatible API key
- 2
Install dependencies
npm install - 3
Set your API key
export NANOPI_API_KEY=your-api-key - 4
Start the project
npm run dev
Things to know
- Requires an OpenAI-compatible API key to run the agent.
Featured in Repolode Weekly
- Issue #2 · A Rust headless browser for agents, and typed .sql imports
A step-by-step tutorial that builds a minimal TypeScript coding agent able to read files, edit code and run commands. It follows pi's data flow with only the core ideas kept, and the source code fills in progressively next to the text.
In collections
Topics
FAQ
- What is pi-from-scratch?
- A step-by-step tutorial that builds a minimal TypeScript coding agent from scratch, able to read files, edit code and run commands. PI from Scratch is a hands-on tutorial that rebuilds the core ideas of the pi coding agent in about 600 lines of TypeScript, called nano-pi. It follows pi's data flow and implements each component only as far as needed to understand it, leaving out production engineering details.
- Is pi-from-scratch free to use? What license does it have?
- pi-from-scratch is open source under the MIT license. Check the license terms before using it in commercial products.
- Is pi-from-scratch still maintained?
- Actively maintained. The last commit to pi-from-scratch was on Oct 24, 2026.
- What can I use pi-from-scratch for?
- Learning how a coding agent loop, tool calling and file editing work internally. Building your own small agent as a foundation before studying pi in depth. Teaching agent architecture in a workshop or course setting.
- How do I install pi-from-scratch?
- Install Node.js 22 or newer and get an OpenAI-compatible API key Install dependencies: npm install Set your API key: export NANOPI_API_KEY=your-api-key Start the project: npm run dev
- Where can I get pi-from-scratch?
- The source code and installation instructions are on GitHub: https://github.com/SaladDay/pi-from-scratch
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A bilingual tutorial and source-code walkthrough of the Pi-Agent SDK, with a companion code set and an AI-assistant skill for building agents.
A desktop app for macOS, Windows and Linux that packages the Pi AI coding agent into an installable application with a built-in chat window.
A self-hosted, mobile-first web app for running Pi coding agents from your phone or browser, with sessions that survive server restarts.
Remote control for the pi terminal coding agent: mirror live sessions to a browser or phone and send messages or commands over a self-hosted relay.
A project-based course teaching how to build the environment, state, verification, and control mechanisms that make AI coding agents reliable.