@grrrck/pi-clear0.2.0
Pi extension that starts a fresh session with /clear while keeping your current model and thinking level
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-clear
A pi extension that adds a /clear command: start a fresh session without losing your model.
Why?
Pi's built-in /new command starts a new session, but the new session resolves its model from pi's defaults chain — CLI arguments, scoped models, the saved default in settings, then the first available model with auth.
If you switched models mid-session — with /model, model cycling, or an extension — that choice is recorded as a model_change entry in the current session transcript, so /new never sees it. Your carefully chosen model quietly reverts to the default.
/clear starts an equally fresh session, then restores the model and thinking level you were using.
Install
pi install npm:@grrrck/pi-clear
Or try it without installing:
pi -e npm:@grrrck/pi-clear
Usage
/clear
Behavior
When /clear runs, the extension:
- waits for the agent to become idle if needed, notifying you that it's waiting
- captures the active model and thinking level
- starts a new session via
ctx.newSession() - restores the captured model and thinking level in the new session
- shows a warning if clearing is cancelled or the captured model can no longer be applied (e.g. its auth was removed)
Because the model is applied with pi.setModel(), it's recorded in the new session's transcript — so it also survives /resume.
Notes
/clearonly registers the slash command; it does not bind a keyboard shortcut, so it won't conflict with other extensions (such aspi-mono-clear, which usesCtrl+Shift+L).- The model handoff is in-process only: it never touches the filesystem, is invisible to other pi processes, and is discarded if pi exits between clearing and restoring.
- Like
/new,/cleardoes not carry over conversation history, compaction summaries, or session name.
How it works
pi tears down the current runtime when a session is replaced, and extension instances are recreated for the new session. Session-bound objects can't be reused across that boundary, and the post-switch context has no model setter — but the replacement happens within the same process. So /clear captures the model as plain data in a globalThis property, and the new session's extension instance consumes it on session_start (reason new) and applies it with pi.setModel(). The handoff is consumed exactly once, so it can never leak into a later session.
Development
Load the extension directly for local testing:
pi -e ./index.ts
There's also an RPC smoke test that verifies the core behavior end-to-end: it starts pi in RPC mode, switches to a different model and thinking level, runs /clear, and asserts both survive the new session:
python3 scripts/rpc-smoke-test.py
Related extensions
pi-mono-clear— a/clearalias for/new(does not preserve the model)