Session Tree
The /tree command provides visual navigation through your session's branching history. Sessions form a tree structure where each message is a node, and branching creates alternate paths from any point.
Overview
When you type /tree in interactive mode, a tree selector opens showing all entries in your session. You can navigate to any point in the tree, effectively rewinding to that state and starting a new branch from there.
This is different from /fork, which creates a new session file containing only the path up to the selected point. /tree stays in the same session file and simply moves the leaf pointer, creating a new branch within the existing tree.
Navigation
The tree selector uses depth-first traversal to display the session tree. Each entry is shown with its type and a preview of its content.
Keyboard Controls
Selection Behavior
The behavior when selecting an entry depends on its type:
When navigating to a user message's parent, the original user message text is pre-filled in the editor. This lets you modify and re-send the message, creating a new branch from that point.
Branch Summarization
When navigating away from an existing branch, you have options for handling the abandoned branch's context:
- Skip - Navigate without summarizing. The abandoned branch remains in the session but its context is not carried forward.
- Auto-summarize - The LLM generates a structured summary of the abandoned branch. This summary is stored as a
BranchSummaryEntryand injected into the LLM context on future turns. - Custom instructions - Provide specific instructions for the summarizer to focus on particular aspects of the abandoned branch.
BranchSummaryEntry
When summarization is chosen, a BranchSummaryEntry is appended to the session:
The summary follows a structured format including:
- Goal - What the conversation was trying to accomplish
- Progress - What was completed
- Key Decisions - Important choices made
- Critical Context - Information needed going forward
- read-files / modified-files - File operations tracked
This summary is injected into the LLM context as a BranchSummaryMessage, prefixed with:
Difference from /fork
Extension Hooks
Extensions can intercept and customize tree navigation via two events:
session_before_tree
Fired before tree navigation begins. Extensions can cancel or modify the navigation.
session_tree
Fired after tree navigation completes. Extensions can react to the navigation result.
Programmatic Navigation
Use AgentSession.navigateTree() for programmatic tree navigation:
You can also get the tree structure programmatically: