How to use the Pi coding agent
Explore with AI
To use Pi, install it with the installer script or npm, run pi in your project and use /login to connect a subscription or API key. Choose a model with /model, branch a session with /tree, /fork or /clone to try another approach, and use /compact when the history grows. For scripts, pi -p runs once and prints the reply.
To use Pi, install it, run pi in your project, connect a model with /login, and learn the session commands: /tree, /fork and /clone to try another approach, /compact when the history gets long. For scripts, pi -p runs once and prints the answer.
Pi is a minimal, extensible coding agent harness for the terminal. It ships with strong defaults and deliberately leaves out features such as sub-agents and plan mode: you add what you need, or install it as a package. The steps below follow Pi’s documentation.
1. Install Pi
Pi needs Node.js 22.19 or newer. On macOS and Linux:
curl -fsSL https://pi.dev/install.sh | sh
Or with npm:
npm install -g --ignore-scripts @earendil-works/pi-coding-agent
2. Start it and sign in
cd ~/code/my-app
pi
Run /login inside Pi to connect a subscription or an API key for a built-in provider. The startup header lists the instructions and resources Pi loaded, which is the quickest way to check it picked up what you expected.
3. Pick a model and how hard it thinks
| Command | What it does |
|---|---|
/model | Select a model |
/thinking | Select how much reasoning the current model uses |
/settings | Change common preferences |
/logout | Remove a provider’s access |
From the command line, --model selects a model by exact or fuzzy name, and --provider limits the lookup to one provider.
4. Work in sessions
Pi saves every session. The commands that make that useful:
/newstarts a fresh session for a new task./namegives the current session a name you will recognise later./resumeopens another saved session;pi --continuefrom the same folder resumes the most recent one./tree,/forkand/clonelet you explore another approach without losing the work you have./compactreduces the conversation history sent to the model when a long session starts to slow down./sessionshows the session’s file, ID, message count, token usage and cost.
Branching is Pi’s answer to a wrong turn: fork before a risky change, and if it goes badly, go back to the branch that worked.
5. Script it
pi -p "summarise the changes on this branch"
pi --mode json "list the failing tests"
-p runs the prompt once, prints the final reply and exits. --mode json streams JSONL events instead, for a program that wants to follow each step.
Give Pi production context
Pi works from your repository. It can read the code that failed, but not the logs, traces and deploys that show how it failed. Polylane gives Pi that context: it connects to the platforms you already run on, so Pi can see when something breaks there.
Using Pi? See how to give Pi production context with Polylane.
Common questions.
What is Pi?
A minimal, extensible coding agent harness for the terminal. It ships with strong defaults and leaves out features such as sub-agents and plan mode, which you can add yourself or install as packages.
What does Pi need to run?
Node.js 22.19 or newer. Install it with the installer script, or with npm as @earendil-works/pi-coding-agent.
How do I resume a Pi session?
Run pi --continue in the same folder to resume the most recent session, or /resume inside Pi to open another saved one.
How do I try a different approach without losing my work?
Use /tree, /fork or /clone. Each lets you explore another direction while the existing session stays intact.
Can I run Pi from a script?
Yes. pi -p runs the prompt once, prints the final reply and exits, and --mode json streams JSONL events instead.
Boris Tane is the founder of Polylane. He previously founded Baselime, observability for the future of the cloud, which Cloudflare acquired. At Cloudflare he built and led the Workers observability team.
More in this series
Related
- Railway activity feed filters and cron jobs in the CLI Railway's 16 October 2026 update: filter the activity feed by service, list and trigger cron runs with railway cron, and migrate railway.json to IaC.
- Cloudflare Tunnel: 50,000 routes and Tunnels for Platforms Cloudflare raised Tunnel routes to 50,000 per account on 16 October 2026 and launched Tunnels for Platforms at $4.50 a tunnel. Limits, setup and gotchas.
- How to deploy Vite apps to Cloudflare with Void Void, announced by Cloudflare on 15 October 2026, deploys Vite apps to Workers in one command. Setup steps, secrets, migrations, CI and the gotchas.
- CloudWatch log centralisation: GovCloud and 13 new Regions AWS added CloudWatch log centralisation to GovCloud (US) and 13 commercial Regions on 16 October 2026. Setup steps, pricing, limits and gotchas.
- How to Monitor a Next.js App on Render Monitor a Next.js app on Render: a health route that checks the database, JSON logs with Rndr-Id, onRequestError, OpenTelemetry traces, streams and alerts.