pi-session-anchor
Remember your conversation tree position across pi restarts. Drop an anchor with /tree or /rewind, and pi will return to that spot next time you start (unless you chatted past it).
Package details
Install pi-session-anchor from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:pi-session-anchor- Package
pi-session-anchor- Version
0.3.0- Published
- Jul 10, 2026
- Downloads
- 728/mo · 728/wk
- Author
- esso0428
- License
- MIT
- Types
- extension
- Size
- 11.8 KB
- Dependencies
- 0 dependencies · 1 peer
Pi manifest JSON
{
"extensions": [
"./index.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
pi-session-anchor
Drop an anchor in your conversation tree — pi will return to that spot after a restart.
What it does
When you use /tree or /rewind to navigate to an earlier point in your session,
pi-session-anchor saves that position (leafId) to a small sidecar file.
The next time you start pi (or resume the session), it restores the tree position so you pick up exactly where you left off — not at the latest message.
This fills the gap left by pi-rewind (which saves file state but not conversation
tree position) and pi-undo-redo (which only incidentally saves position as a
side-effect of its redo stack).
Resume switching (fixed!)
When you use /resume to switch between sessions and switch back, the anchor is
now correctly restored — including the visual display. This was a two-part
fix:
Never overwrite the anchor with the current position.
Onlysession_tree(explicit navigation) saves the anchor.session_shutdowndoes NOT overwrite it.Apply the anchor at session-file load, before any render.
SessionManager.open()is patched to read the sidecar and callbranch()immediately after_buildIndex()runs. This meansrenderInitialMessages()always sees the correct leafId — no timing gap.
How it works
/tree → navigate to older message
│
├─► pi-session-anchor saves newLeafId → sidecar
│
▼ restart or /resume
│
├─► SessionManager.open() loads the session file
├─► patched open() reads sidecar, calls branch(anchor)
├─► renderInitialMessages() → correct tree displayed
└─► ✅ conversation tree shows the anchored position
No session entries are modified. The anchor is kept in
~/.pi/agent/state/session-anchor/<sessionId>.json — clean, separable, inspectable.
Commands
| Command | Description |
|---|---|
/pin |
Manually save the current tree position as an anchor |
/anchor |
Show the saved anchor for the current session |
The anchor is also auto-saved on every /tree or /rewind navigation.
Edge cases handled
| Situation | Behaviour |
|---|---|
| Target entry compacted away | Silent fallback to latest position |
| Navigation to root (before first message) | Saved as leafId: null, restored via resetLeaf() |
| Sidecar file deleted / corrupted | Treated as "no anchor", normal startup |
| Multiple sessions | Separate sidecar per session ID |
| Anchor then continue chatting | New messages are children of the anchored position; anchor stays until next /tree overwrites it |
/resume switch away and back |
Anchor applied at SessionManager.open() — correct from first render |
| Extension reload | SessionManager.open patch is re-applied; no side effects |
Installation
# If published on npm:
pi install pi-session-anchor
# Or copy to extensions directory:
cp -r pi-session-anchor ~/.pi/agent/extensions/
Then reload pi or restart.
Configuration (optional)
No configuration is required. If you want to disable auto-restore, remove the sidecar file
for that session from ~/.pi/agent/state/session-anchor/.