Skip to content
BeeponyBeepony
Back

A Minimal Guide to Pi Agent

Edit post

A Minimal Guide to Pi Agent


1. Start with the Right Mental Model

Pi is a minimal terminal coding harness.

Its core design principle: keep the core minimal and let you extend the workflow yourself (README.md > Philosophy).

The official docs state clearly which built-in features it does not provide, and the alternatives:

Feature others havePi's stanceAlternative
MCPNot includedUse CLI tools + a README (i.e., Skills), or write an extension to add MCP
Sub-agentsNot includedRun several pi instances in tmux, write your own extension, or install a third-party package
Permission promptsNot includedRun it in a container, or customize the confirmation flow with an extension
Plan modeNot includedWrite the plan to a file, or use an extension / package
Built-in to-dosNot includedUse a TODO.md file
Background bashNot includedUse tmux (observable and directly interactive)

What this means: don't wait for Pi to give you a workflow. Turn the workflow you want into a skill / prompt / extension / package yourself.

By default the model gets only 4 tools: read, write, edit, bash. The read-only grep, find, and ls must be enabled explicitly (docs/quickstart.md, docs/usage.md).


2. The 6 Most Frequent Daily Actions

Source: README.md > Interactive Mode, docs/quickstart.md

What you wantHow to do it
Reference a fileType @ in the editor to fuzzy-search project files; from the command line: pi @src/app.ts "review this"
Let the model see command output!command (output goes into context); to run it yourself without polluting context, use !!command
Paste an imageCtrl+V (Alt+V on Windows), or drag the image into the terminal
Multi-line inputShift+Enter (Ctrl+Enter in Windows Terminal)
Write a long prompt in an external editorCtrl+G (uses externalEditor / $VISUAL / $EDITOR)
Copy the last replyCtrl+X

One-off tasks (without the interactive UI):

pi -p "Summarize this codebase"
cat README.md | pi -p "Summarize this text"   # stdin is merged into the initial prompt
pi -p @screenshot.png "What's in this image?"

3. Models and Thinking Levels: Switch by Task Difficulty

Source: README.md, docs/settings.md

Set them once from the command line:

pi --model sonnet:high "Solve this complex problem"   # provider/id + :thinking shorthand
pi --thinking high "Solve this complex problem"
pi --models "claude-*,gpt-4o"                          # limit which models can be cycled

A practical token-saving tip: use a low thinking level + a cheap model for simple changes, and switch to high only for complex refactors. For review tasks that read a lot and write little, enable read-only mode:

pi --tools read,grep,find,ls -p "Review the code"   # read-only: physically cannot modify files

4. Make It "Understand Your Project": AGENTS.md Has the Best ROI

Source: README.md > Context Files, docs/quickstart.md

On startup, Pi automatically loads and concatenates these files:

  1. ~/.pi/agent/AGENTS.md (global)
  2. AGENTS.md or CLAUDE.md in each parent directory walking up from cwd
  3. AGENTS.md or CLAUDE.md in the current directory

If a directory has AGENTS.override.md, only that file is loaded for the directory, and AGENTS.md/CLAUDE.md are ignored.

What to write: project conventions, common commands, safety red lines, preferences.

# Project Instructions
- After changing code, run `npm run check`
- Never run production migrations locally
- Keep replies concise

Key points:


5. Context Costs Money: Sessions / Branches / Compaction

Source: docs/sessions.md, docs/compaction.md

Session Management

Branches: Don't Start Over Just Because the Chat Went Off Track

In one sentence: to compare several approaches in place → /tree; to get a separate file → /fork / /clone.

Compaction (Automatic Compression)

// ~/.pi/agent/settings.json or .pi/settings.json
{ "compaction": { "enabled": true, "reserveTokens": 16384, "keepRecentTokens": 20000 } }

Switching Computers / Sharing


6. Lock In Repetitive Work (The Key to Building Efficiently)

Source: docs/prompt-templates.md, docs/skills.md, README.md > Pi Packages

6.1 Prompt Templates: Reusable Prompts

Put them in ~/.pi/agent/prompts/*.md or .pi/prompts/*.md, and type /filename to expand.

<!-- ~/.pi/agent/prompts/review.md -->
---
description: Review staged git changes
argument-hint: "[focus]"
---
Review the staged changes (`git diff --cached`). Focus on: ${1:-bugs, security, error handling}

Supports $1, $@, $ARGUMENTS, ${1:-default}, and ${@:N:L} slices.

6.2 Skills: On-Demand Capability Packs (Progressive Disclosure)

How it works: at startup only each skill's name + description goes into the system prompt; when a task matches, the model uses read to load the full SKILL.md. So when writing a skill, the description decides whether it gets triggered.

<!-- ~/.pi/agent/skills/my-skill/SKILL.md -->
---
name: my-skill
description: Explain specifically what it does and when it should be used. Be specific.
---

# My Skill
## Steps
1. ...
{ "skills": ["~/.claude/skills", "~/.codex/skills"] }

6.3 Pi Packages: Bundle All of the Above to Share / Reuse

pi install npm:@foo/pi-tools        # also supports git:github.com/user/repo, https://..., ssh://...
pi install npm:@foo/pi-tools@1.2.3  # pin a version
pi list
pi update --extensions              # update packages only
pi update --all                     # update pi + all packages
pi config                           # interactively enable/disable resources in packages

-l installs locally to the project (.pi/). You can enable only some resources from a package (the object form of packages; see docs/settings.md).

Security reminder (from the official docs): Pi packages have full system access, extensions run arbitrary code, and skills can instruct the model to do anything. Read the source before installing third-party packages.


7. Don't Interrupt It: The Message Queue

Source: README.md > Message Queue

You can keep typing while the agent is working:

ActionEffect
EnterQueued as a steering message: delivered after the current assistant turn's tool calls finish (lets you course-correct midway)
Alt+EnterQueued as a follow-up: delivered only after the agent finishes everything
EscapeAbort, and restore queued messages to the editor
Alt+UpPull queued messages back into the editor

steeringMode / followUpMode can be set to "one-at-a-time" (default, waits for a reply) or "all" (sends together).


8. Non-Interactive & Scripted: Put pi in Your Pipeline

Source: README.md > Programmatic Usage, docs/usage.md

ModePurpose
DefaultInteractive
-p / --printPrint the result and exit
--mode jsonOutput all events as JSON Lines
--mode rpcRPC over stdin/stdout for non-Node.js integrations (strict LF framing; don't use Node readline)
SDKimport { createAgentSession, ModelRuntime, SessionManager } from "@earendil-works/pi-coding-agent"

When the bash tool runs, commands receive these environment variables so scripts can look up context (README.md > Environment Variables):

PI_SESSION_ID, PI_SESSION_FILE, PI_PROVIDER, PI_MODEL, PI_REASONING_LEVEL; the CLI/RPC entry points also set AI_AGENT=pi and PI_CODING_AGENT=true so child processes can detect it.


9. Security and Trust Boundaries (Don't Skip This)

Source: README.md, docs/usage.md > Project Trust, docs/security.md


10. Common Commands Cheat Sheet

Source: README.md > CLI Reference

# Sessions
pi -c                          # continue the latest session
pi -r                          # browse past sessions
pi --name "release audit" -p "Audit this repository"
pi --session <path|id>         # open a specific session
pi --fork <path|id>            # fork from a specific session

# Models
pi --provider openai --model gpt-4o "..."
pi --list-models [search]

# Tool control
pi --tools read,grep,find,ls -p "Review the code"   # read-only
pi --exclude-tools ask_question                     # disable a single tool
pi --no-builtin-tools                               # turn off built-ins, keep extension tools

# Resource control (precise loading)
pi --no-extensions -e ./my-extension.ts
pi --no-skills
pi --no-context-files              # or -nc

# Package management
pi install <source> [-l]
pi remove  <source> [-l]
pi update --all | --extensions | --models | --self

Common in-session commands: /model /thinking /resume /new /tree /fork /clone /compact /session /reload /hotkeys /export /share /trust /settings /quit. Use /hotkeys to see all shortcuts; customize them in ~/.pi/agent/keybindings.json, then /reload.


11. An "Efficient Build" Checklist

A recommended setup assembled from the official capabilities:

  1. Write an AGENTS.md at the project root: commands, conventions, red lines. Invest once, save time forever.
  2. Save your default model/thinking level with Ctrl+S instead of switching every time.
  3. Turn repeated prompts into prompt templates instead of retyping them.
  4. Turn repeated multi-step workflows into skills, with a description that clearly states when to trigger them.
  5. Split big tasks into stages: one session per stage; if things go off track, roll back with /tree instead of starting over.
  6. Remember compaction is lossy in long sessions: have key conclusions written to files (TODO.md, design docs), not just left in context.
  7. Need parallel/background work: start multiple pi instances in tmux; don't expect built-in background bash.
  8. Need approvals/guardrails: write an extension or use --tools read-only mode; there are no official prompts.
  9. Read the source before installing third-party packages: they have full system access.
  10. For non-interactive pipelines, use -p / --mode json / --mode rpc / the SDK.

Official Docs Index

Install directory: /opt/homebrew/lib/node_modules/@earendil-works/pi-coding-agent/

To learn aboutRead this
Overview / philosophy / all CLI optionsREADME.md
Getting starteddocs/quickstart.md
Daily interaction, slash commands, CLI referencedocs/usage.md
Sessions / branches / resumingdocs/sessions.md
How context compaction works and how to configure itdocs/compaction.md
Skills spec and locationsdocs/skills.md
Prompt template syntaxdocs/prompt-templates.md
Package management and security notesdocs/packages.md
All settingsdocs/settings.md
All shortcuts and customizationdocs/keybindings.md
Extension development (custom tools/UI/sub-agents/permissions)docs/extensions.md
Custom providers / modelsdocs/custom-provider.md, docs/models.md
Authentication for various providersdocs/providers.md
JSON / RPC / SDK integrationdocs/json.md, docs/rpc.md, docs/sdk.md
Security modeldocs/security.md
Containers / tmux / terminal setupdocs/containerization.md, docs/tmux.md, docs/terminal-setup.md
Environment variablesdocs/environment-variables.md

Pi can do this itself: just ask inside pi, "help me make a skill / prompt template". The official docs explicitly say pi can create skills / pi can create prompt templates.


Edit post
Share this post:

Previous post
Documentation and Sources for Tesla's Direct APIs (Official, Community, and Reverse-Engineered Evidence from TeslaMate)
Next post
Andrew Ng's AI Engineering Skill Map: From "Implementer" to "Shaper"