@fillumina/pi-clear
pi extension: /clear starts a new session keeping the current model and thinking level
Package details
Install @fillumina/pi-clear from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:@fillumina/pi-clear- Package
@fillumina/pi-clear- Version
0.1.1- Published
- Sep 5, 2026
- Downloads
- 267/mo · 31/wk
- Author
- fillumina
- License
- MIT
- Types
- extension
- Size
- 5.4 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-clear
A pi extension that adds a /clear command that starts a fresh session with a completely empty context while keeping the model and thinking level you are currently using.
Install
From a local checkout:
pi install /path/to/pi-clear
It works as a regular pi package:
pi install npm:@fillumina/pi-clear
Restart pi (or run /reload) so the extension is loaded.
Usage
/clear
- a new session is started (fresh context, new session file),
- the new session picks up the model and thinking level of the previous one,
- the configured default model in your settings is left untouched.
How it works
A new session always initializes from the configured default model — pi does not carry the previous session's model over, and extensions are not allowed to use the captured pi API after ctx.newSession() (it goes stale once the old session is disposed). pi-clear bridges the gap using only documented extension APIs:
- The
/clearhandler stores the current model reference and thinking level in module-level state, then calls ctx.newSession(). - pi re-runs the extension factory for the replacement session, creating a fresh, active ExtensionAPI bound to the new session.
- The session_start handler (reason "new") registered by that factory run resolves the stashed model with ctx.modelRegistry.find() and applies it on the new session via pi.setModel() and pi.setThinkingLevel().
This is the pattern pi prescribes for post-replacement work: act on the replacement session's own extension API instead of the old one.
Requirements
- pi coding agent >= 0.82.1 (peer dependency)
- The model must be resolvable in the new session (available + authenticated)
License
MIT