Pi School

Lesson 9

Branching

Compare approaches and rewind mistakes without losing either, using Pi's session tree.

A session isn’t just a straight line of messages — it’s a tree. Every response you get is a branch point, and Pi keeps every path you’ve explored, not just the one you’re currently on.

Why bother

Two situations come up constantly:

  • Comparing approaches. You ask Pi to solve something one way, then wonder if a different approach would be better — without throwing away the first attempt.
  • Rewinding a mistake. Pi goes down the wrong path, and you want to go back to right before that happened, without starting an entirely new session and losing everything that came before it.

Both are the same underlying feature: every entry in a session has an id and a parentId, and the current position is just the active leaf of that tree. Jumping to any earlier point doesn’t create a new file or lose anything — it just moves where you’re standing.

├─ user: "Hello, can you help..."
│  └─ assistant: "Of course! I can..."
│     ├─ user: "Let's try approach A..."
│     │  └─ assistant: "For approach A..."
│     │     └─ user: "That worked..."  ← active
│     └─ user: "Actually, approach B..."
│        └─ assistant: "For approach B..."

Type /tree to open the tree view.

KeyAction
/Navigate visible entries
/Page up/down
Ctrl+←/Ctrl+→ or Alt+←/Alt+→Fold/unfold, or jump between branch segments
Shift+LSet or clear a label on the selected entry
Ctrl+OCycle filter mode

Filter modes are: default, no-tools, user-only, labeled-only, and all — handy for cutting through a long tree to find the branch point you actually want.

A subtlety worth knowing

What happens when you select an entry depends on what kind of entry it is:

  • Selecting a user (or custom) message moves the leaf to that message’s parent, and puts the message’s original text back in the editor. You can edit it and resubmit — this creates a new branch from that point.
  • Selecting an assistant, tool, compaction, or other non-user entry moves the leaf there directly, with an empty editor. You just continue from that point — no new branch, no text to edit.

In short: pick a user message to change what was asked; pick anything else to jump ahead and keep going.

Branch summaries

Branch summaries are offered when you leave one branch for another, not just when you open or browse /tree. They help carry useful context from the branch you’re leaving into the branch you’re switching to, without replaying the whole thing. You’ll be asked to choose: no summary, a default summary, or a summary with custom focus instructions.

/tree vs. /fork vs. /clone

Three related commands, three different outputs:

/tree/fork/clone
OutputSame session fileNew session fileNew session file
ViewFull treeUser-message selectorCurrent active branch
Typical useExplore alternatives in placeStart a new session from an earlier promptDuplicate current work before continuing

Use /tree when you want to keep every alternative together in one place. Reach for /fork or /clone when you’d rather split off into a completely separate session file.

Exercise: compare two approaches