pi-code-rollback
Git-backed restore for Pi that can rewind code, conversation, or both to prompt boundaries
Built a restore system for Pi that makes agent sessions safely reversible. As you work, it automatically captures git-backed snapshots at the boundaries that actually matter — just before a prompt runs and just after a completed run. Later, /restore lets you recover the code, the conversation, or both.
Why this exists
Coding agents can move fast enough that a normal git history is not always the right recovery interface. A single prompt can touch many files, run tools, follow a mistaken assumption, or produce a direction you want to abandon. Manual commits are too coarse, and editor undo only sees the code, not the conversation that led there.
pi-code-rollback treats each agent turn as a recoverable unit. Before a prompt runs, it captures the current code and conversation state. After a successful run, it captures the result. That gives you stable restore points around the moments where intent changes.
What /restore can rewind
The restore flow lets you choose what kind of rollback you actually need:
- Code only - keep the conversation, but put the workspace back at a previous snapshot
- Conversation only - keep the current files, but return the chat to an earlier point
- Code and conversation - fully rewind the session to a prompt boundary
This matters because not every mistake is the same. Sometimes the code is wrong but the reasoning is still useful. Sometimes the files are fine but the chat context has drifted. Sometimes you want the whole branch of work gone.
Implementation
The system is git-backed, but it is not asking the user to manually manage commits while the agent works. It creates internal snapshots at predictable boundaries, tracks the conversation state alongside the code state, and exposes the restore operation as a Pi command.
The important design constraint was making rollback feel native to the agent loop. You should not need to know which files changed, which command caused the bad state, or whether the issue started before or after the last assistant turn. You pick the restore point and the scope, and Pi rewinds the right layer.
Result
The extension makes experimentation much cheaper. You can let the agent attempt a risky refactor, explore an alternate implementation, or recover from a bad prompt without treating the session as disposable. The work becomes reversible at the same granularity that it was created: one prompt at a time.