Sessions in Pi are stored as JSONL (JSON Lines) files with a tree structure. Each entry has anDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/badlogic/pi-mono/llms.txt
Use this file to discover all available pages before exploring further.
id and parentId, enabling in-place branching without creating new files.
Session Storage
Sessions auto-save to:<path> is your working directory with / replaced by -.
Example:
Session Commands
- CLI Flags
- Interactive Commands
Session Naming
Set a display name to identify sessions:Branching
Sessions use a tree structure where you can branch from any point in the conversation.Tree Navigation (/tree)
Navigate the full conversation tree and switch between branches:
Search and Filter
- Type to search messages
- ←/→ to page through results
- Ctrl+O to cycle filter modes:
- Default (user + assistant + tools)
- No-tools (user + assistant only)
- User-only
- Labeled-only
- All (includes compaction, fork entries)
- All history is preserved in the file
- Context switches to that branch
- Continue the conversation from there
- Create new branches without limits
Forking (/fork)
Create a new session file from the current branch:
Use cases:
- Experiment with different approaches
- Create a clean session from a checkpoint
- Share a conversation up to a certain point
- Start fresh but keep relevant context
Labeling Entries
Mark important points in the conversation:- Appear in tree view for easy navigation
- Persist across sessions
- Help you find checkpoints
- Can be filtered with “labeled-only” mode
Compaction
Long sessions exhaust context windows. Compaction summarizes older messages while keeping recent ones.Manual Compaction
Trigger compaction manually:- Sends conversation history to the LLM
- Receives a summary
- Replaces old messages with the summary
- Keeps recent messages unchanged
Automatic Compaction
Enabled by default. Triggers in two scenarios:- Context Overflow
- Proactive
When the prompt exceeds the model’s context window:
- Request fails with context error
- Pi automatically compacts
- Retries the request
- User sees a notification
Configuration
Configure via/settings or settings.json:
enabled- Enable/disable automatic compactionreserveTokens- Space reserved for the model’s response (default: 16384)keepRecentTokens- How many recent tokens to preserve verbatim (default: 20000)
Compaction Behavior
What gets summarized?
What gets summarized?
Messages older than
keepRecentTokens are sent to the model for summarization. The model produces a concise summary covering:- Key decisions made
- Problems encountered and solutions
- Important context about the codebase
- State of the work at that point
Is the full history lost?
Is the full history lost?
No. The full JSONL file retains all entries. Use
/tree to navigate back to any point and see the original messages.Compaction only affects what’s sent to the LLM in future turns.Can I customize summarization?
Can I customize summarization?
Yes, via extensions:This lets you implement custom summarization logic or use a different model.
What about branch summaries?
What about branch summaries?
When switching branches via
/tree, Pi can optionally summarize the abandoned branch. This creates a compact record of what you tried before switching directions.Configure in settings.json:Compaction Events
Extensions can hook into compaction:Session File Format
Sessions are JSONL files where each line is a JSON object.Entry Types
- Header
- Message
- Custom
- Compaction
Tree Structure
Entries link viaid and parentId:
Deleting Sessions
Delete sessions by:-
Removing files:
-
Interactive deletion:
- Use
/resumeto open the session selector - Select a session
- Press Ctrl+D
- Confirm deletion
When available, Pi uses the
trashCLI to avoid permanent deletion.
- Use
Session Manager API
Extensions can access session data:packages/coding-agent/src/core/session-manager.ts for the full API.
Migration
Old session formats are automatically migrated:- Version 1 (legacy linear): Migrated to tree structure
- Version 2 (tree structure): Migrated to version 3
- Version 3 (current): Renamed
hookMessagerole tocustom
Best Practices
Use Descriptive Names
Set session names with
/name to identify work later:Label Checkpoints
Use labels to mark important points:
- Before major refactors
- After completing features
- At decision points
Branch Freely
Don’t hesitate to try different approaches:
- Use
/treeto experiment - Keep the original branch
- Compare results
Let Auto-Compaction Work
Keep automatic compaction enabled:
- Prevents context overflow
- Maintains performance
- Full history remains accessible
Next Steps
Customization
Configure session settings and behavior
Extensions
Build extensions that hook into session events