Pi Agent Core Concepts

Before using Pi Agent officially, understanding its core concepts and working methods can help you get started faster.


Understanding Pi Agent in One Sentence

Pi Agent is an AI programming assistant that runs in the terminal.

After starting, you'll see an interface similar to chat software. Input natural language requirements, and the AI can read your code, execute commands, and modify files.


Four Running Modes

Pi Agent supports four running modes to suit different scenarios:

ModeCommandDescriptionUse Case
Interactive Modepi (default)Terminal TUI interface, real-time conversation, supports all featuresDaily development, interactive programming
Print Modepi -p "prompt"One-shot Q&A, exits after outputting the resultScript integration, quick queries
JSON Modepi --mode jsonAll events are output as JSON lines, suitable for program parsingToolchain integration, data analysis
RPC Modepi --mode rpcIntegrated via JSONL protocol over stdin/stdoutInter-process communication, editor plugins

Interactive mode starts directly into the TUI interface:

$ pi
Pi Agent 0.1.x  |  ~/projects/example-demo
claude-sonnet-4  |  上下文 2%  |  $0.0000
>

Print mode exits after answering, suitable for putting into scripts:

$ pi -p "总结这个项目"
这是一个 TypeScript 命令行工具,核心逻辑位于 src/ 目录,包含会话管理、工具调度和扩展加载三个模块。
Tokens: 1.2k 输入 / 320 输出  |  费用 $0.0081

JSON mode outputs each event as a line of JSON, making it easy for programs to parse:

$ pi --mode json -p "总结这个项目"
{"type":"session","id":"a1b2c3d4"}
{"type":"message_start","role":"assistant"}
{"type":"message_end","usage":{"input":1200,"output":320}}

RPC mode sends and receives JSONL messages via stdin/stdout for editor plugin calls:

$ pi --mode rpc
{"id":1,"method":"prompt","params":{"message":"列出 src 目录"}}
{"id":1,"result":{"state":"idle","messages":2}}

As a beginner, you'll spend most of your time working in interactive mode.

Once you're proficient, Print mode can be used for script automation.


Built-in Tools

After startup, Pi Agent gives the AI the following four built-in tools by default. In addition, three read-only tools—grep, find, and ls—can be enabled optionally:

Tool NameFunctionExampleDefault Status
readRead file contentAI reads src/main.ts to understand the code logicEnabled by default
writeCreate or overwrite filesAI creates a new file or rewrites the entire fileEnabled by default
editReplace content in a file preciselyAI modifies a few lines of code in a functionEnabled by default
bashExecute shell commandsAI runs tests, installs dependencies, and runs lintEnabled by default
grepSearch for text in filesAI searches for which files call a certain functionOptional
findSearch for files by nameAI finds all files named *.test.tsOptional
lsList directory contentsAI views the directory structure to locate modulesOptional

The three read-only tools are enabled via the--toolsparameter manually, for examplepi --tools read,grep,find,ls。


Extension System

Pi Agent extends its functionality in the following five ways:

Extension MethodFile FormatPurposeDifficulty
ExtensionsTypeScript(.ts)Register custom tools, event listeners, commands, and UI componentsRequires programming
SkillsMarkdown(SKILL.md)Provides workflow instructions and scripts for specialized fieldsKnowing how to write Markdown is enough
Prompt TemplatesMarkdown(.md)Reusable prompts with parameter supportSimplest
ThemesJSON(.json)Customize terminal interface color schemeSimple
Packagesnpm/git projectsPackage and share the above four types of resourcesAs needed

As a beginner, you don't need to understand all extension methods immediately.

Start with basic usage first, and gradually explore the extension system as your needs grow.


File Loading Order

When Pi Agent starts, it automatically loads project instruction files, allowing you to define expected behavior for the AI:

LevelPathScopePriority
Global configuration~/.pi/agent/AGENTS.mdAll projectsLowest, serves as a general baseline
Project configurationAGENTS.md or CLAUDE.md in the project directory and parent directoriesCurrent projectHighest, can override global instructions

Project-level configuration is loaded by traversing upward from the parent directory, and is finally merged with the configuration in the current directory.

If you've used Claude Code before, you can directly reuse existing CLAUDE.md files; Pi Agent will automatically recognize and load them.


Sessions and Branches

Pi Agent's session system is one of its most distinctive features.

Each conversation is automatically saved as a session file, stored in~/.pi/agent/sessions/the directory.

Internally, sessions use a tree structure: you can "branch" out new exploration directions from any historical node without losing previous conversations.

Pi Agent 会话树分叉结构示意

This is very useful when you need to experiment with different implementation approaches—each line of thought can be preserved independently and revisited at any time.

Other Extensions