Skip to content

Sessions & Context

PizzaPi sessions are powered by pi’s session engine — a tree-structured conversation format that supports branching, forking, and automatic context compaction. This page covers how sessions work under the hood and the tools available for managing them.


CommandDescription
/newStart a fresh session
/resume [query]Browse and resume a previous session — fuzzy-search by name, ID, or content
/name <name>Give the current session a display name
/sessionShow session info (path, tokens, cost)

Sessions auto-save as JSONL files under ~/.pi/agent/sessions/, organized by working directory.

Each session is a single .jsonl file with a tree structure. Every entry has an id and parentId, enabling in-place branching without creating new files. The file format preserves all history — even when you branch or compact, nothing is deleted.


The /tree command opens a tree-based navigator showing your full conversation history. Unlike linear chat, pi sessions form a tree — every time you go back and try a different approach, a new branch is created.

  • Navigate to any point in the conversation
  • Branch from any message to try a different approach
  • View branches side by side to compare approaches
  • Label important messages as bookmarks

When you select a user message in the tree:

  1. The conversation pointer moves to the parent of that message
  2. The message text is placed in your editor for re-submission
  3. You can edit it and submit, creating a new branch

When you select a non-user message (assistant response, compaction, etc.):

  1. The conversation continues from that point
  2. The editor stays empty

When switching between branches, you’ll be asked whether to summarize the branch you’re leaving. This creates a compact summary that preserves context without keeping every message in the active context window. Options:

  • No summary — switch immediately
  • Summarize — generate a summary with the default prompt
  • Summarize with custom prompt — provide focus instructions for the summary

While /tree branches within the same session file, /fork creates an entirely new session from any point in the current one.

Feature/tree/fork
ResultNew branch in same fileNew session file
HistorySharedCopied (independent)
SummarizationOptionalNever

Use /fork when you want to explore a completely different direction without cluttering the original session’s tree.


Long conversations eventually fill the model’s context window. Compaction summarizes older messages while keeping recent ones, freeing up context space.

Enabled by default. Triggers when:

contextTokens > contextWindow − reserveTokens

When triggered, pi:

  1. Walks backwards from the newest message, keeping recent messages (default: 20,000 tokens)
  2. Summarizes everything older into a structured summary
  3. Continues with the summary + recent messages

Use /compact to trigger compaction manually, optionally with focus instructions:

/compact # Default summarization
/compact focus on the auth module # Guided summarization

This is useful when you want to steer what the summary emphasizes before the context runs out naturally.

Configure in ~/.pi/agent/settings.json (global) or .pi/settings.json (project):

{
"compaction": {
"enabled": true,
"reserveTokens": 16384,
"keepRecentTokens": 20000
}
}
SettingDefaultDescription
compaction.enabledtrueEnable automatic compaction
compaction.reserveTokens16384Tokens reserved for the model’s response
compaction.keepRecentTokens20000Recent tokens to keep (not summarized)

Additional session-related settings:

{
"branchSummary": {
"reserveTokens": 16384,
"skipPrompt": false
}
}
SettingDefaultDescription
branchSummary.reserveTokens16384Tokens reserved for branch summarization
branchSummary.skipPromptfalseSkip the “Summarize branch?” prompt (defaults to no summary)
{
"retry": {
"enabled": true,
"maxRetries": 3,
"baseDelayMs": 2000,
"maxDelayMs": 60000
}
}
SettingDefaultDescription
retry.enabledtrueAuto-retry on transient errors
retry.maxRetries3Maximum retry attempts
retry.baseDelayMs2000Base delay (exponential backoff: 2s, 4s, 8s)
retry.maxDelayMs60000Max delay before failing (prevents multi-hour waits)
{
"sessionDir": "/path/to/sessions"
}

Priority: --session-dir CLI flag → sessionDir in settings → default (~/.pi/agent/sessions/).


CommandDescription
/export [file]Export the current session to an HTML file
/shareUpload as a private GitHub gist with a shareable HTML link
/copyCopy the last assistant message to your clipboard

pi automatically loads context files at startup to give the agent project-specific knowledge. These files are loaded from multiple locations and concatenated:

FileLocationPurpose
AGENTS.md or CLAUDE.md~/.pi/agent/, parent directories, current directoryProject instructions, conventions, common commands
SYSTEM.md.pi/SYSTEM.md (project) or ~/.pi/agent/SYSTEM.md (global)Replace the default system prompt entirely
APPEND_SYSTEM.mdSame locationsAppend to the system prompt without replacing it
  1. Global AGENTS.md from ~/.pi/agent/ (or ~/.pizzapi/)
  2. Walk up from the current working directory, loading each AGENTS.md or CLAUDE.md found
  3. Project-level AGENTS.md in the current directory

All files are concatenated and included in the system prompt. This means you can have repository-wide instructions in the repo root and more specific instructions in subdirectories.