Sessions, Trees & the TUI
Lesson 2: Sessions, Trees & the TUI
Pi treats every conversation as a session: a JSONL file with a tree structure, auto-saved to ~/.pi/agent/sessions/ and organized by working directory. Because sessions are trees, you can jump back to any earlier turn and branch from there โ like git for your conversation.
Session commands and flags
pi -c # continue the most recent session
pi -r # browse and pick a past session
pi --no-session # ephemeral: do not save anything
pi --name "Refactor auth" # human-readable session name
pi --session <path|id> # resume a specific session
pi --fork <path|id> # fork a session into a new one
Inside the TUI, the big ones are /tree (navigate the session tree), /fork (new session from a previous user message), /clone (duplicate the current branch), /resume (picker), /new, /session (show file, ID, message count, tokens, and cost), /export (HTML/JSONL), /import, and /share (private GitHub gist with a shareable HTML link).
Editor features that save you (and the model) time
@โ fuzzy-search project files to referenceTabโ path completionShift+Enterโ multi-line input!commandโ run a shell command and send its output to the model!!commandโ run a shell command without sending output to the modelCtrl+Xโ copy the last assistant messageCtrl+Gโ open an external editor (e.g.code --wait)Ctrl+Vโ paste images directly into the terminal
The message queue
You don't have to wait for the agent to finish: Enter queues a steering message (delivered after the current tool calls), Alt+Enter queues a follow-up (delivered after all work completes), Escape aborts and restores queued messages, and Alt+Up pulls them back. Delivery order is configurable via steeringMode and followUpMode settings.
/sessionshows tokens and cost for the current session โ check it before committing to a long task.!!commandis a quiet token win: run setup/verification commands without dumping their output into context.--no-sessionis perfect for one-off questions you'll never resume โ nothing saved, nothing to compact later./forkor/clonelets you explore an alternative path in a fresh context instead of dragging exploratory turns through the main session.
- Learn 90% Of Pi Agent in Under 17 Minutes โ Brandon Melville โ a fast hands-on tour of the TUI, sessions, and daily workflow.
Further Reading
- Using Pi โ interactive mode, commands, CLI reference
- Sessions โ storage, branching, resuming
- Keybindings
๐ง Knowledge Check
1. What shape do pi sessions have on disk?
2. Which command runs a shell command WITHOUT sending its output to the model?
3. How can you see the token count and cost of the current session?