pi-rewind-unwind

Undo Pi write/edit file changes via /undo, and restore those files when you jump with /tree.

Packages

Package details

extension

Install pi-rewind-unwind from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:pi-rewind-unwind
Package
pi-rewind-unwind
Version
0.2.0
Published
Aug 16, 2026
Downloads
993/mo · 292/wk
Author
vincentplus
License
MIT
Types
extension
Size
39.1 KB
Dependencies
1 dependency · 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 Rewind Unwind

Undo recent changes made through Pi’s write and edit tools, and restore those files when you jump with /tree.

What it does

Pi’s built-in /rewind and /tree only move conversation history. They do not restore files on disk. This package fills that gap:

  • Tracks successful write and edit tool changes.
  • /tree can restore captured files to match the node you jump to, or leave files alone.
  • /undo lets you preview and undo the latest change, or several steps.
  • Restores previous file contents, or deletes a file that did not exist before.
  • Keeps undo limited to changes it captured itself.

The slash command is /undo. The model-facing tool is undo_files. Undo state stays in ~/.pi/agent/state/rewind-unwind. Existing files in ~/.pi/agent/state/reverse-last are still read.

Source: github.com/itisvincent/pi-rewind-unwind

Install

pi install npm:pi-rewind-unwind

Or from a local checkout:

pi install ./pi-rewind-unwind

Restart Pi if the package does not appear in your current session.

How to use it

Jump in the session tree

/tree always moves the conversation. If captured files would change, it asks whether to restore those files or leave the disk as-is. Later edits on the branch you left are reverted only if you choose restore. Jumping back to that later node can reapply them the same way.

It only knows about write / edit captures. If a file on disk no longer matches either captured snapshot — for example after an editor or bash edit — /tree asks before overwriting it. If you keep those untracked files, snapshots are updated to match disk so that warning stays quiet. Saying no to restoring tracked files only skips the checkout; the snapshots stay so a later jump can still restore them. Shell-only changes are not restored.

Manual undo

  • /undo — preview and undo captured file changes on the active branch
  • /undo [count] — undo that many recent captured steps

Before you start

No setup is required. Undo history is kept only for the current Pi session unless you configure another state directory.

The optional PI_REWIND_UNWIND_STATE_DIR setting overrides the state folder. PI_REVERSE_LAST_STATE_DIR is still accepted.

Technical details

Undo state is stored under ~/.pi/agent/state/rewind-unwind by default. Each capture stores the file’s before and after text plus the session-tree entry ID. On session_tree, /tree asks before writing captured files. If you restore, captures on the new branch are replayed and captures that no longer belong are reverted. Conversation-only jumps leave disk and snapshots unchanged.