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. Praxen Inc. 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 Praxen Inc..
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.
About the author
Founder of Praxen Inc.
More in this series
Related
- How to correlate incidents with deploys using evidence Learn how to correlate incidents with deploys using release markers, metrics, logs and verified GitHub, Vercel, Cloudflare and Kubernetes change events.
- What is change intelligence? A production safety guide What is change intelligence? Learn how deploys, config, flags, infrastructure and dependency changes connect to incidents, using tools you already have.
- Turn your app into a context graph Agents that run software need a context graph of the app: every resource, what it connects to, the repository that deploys it and the team that owns it. How we built one on Durable Objects, keep it fresh across every provider without polling AWS, decide what counts as a change, and delete from it safely.
- How to use Claude Code to debug production issues Debug production issues with Claude Code: get logs and traces into the session, test hypotheses against evidence, stay read-only and ship a verified fix.
- Is it safe to give an AI SRE read access to production? Read access for an AI SRE is a sound first step if you scope it. The risks are secrets, customer data and exfiltration. Here are the controls and a checklist.