@grrrck/pi-clear

Pi extension that starts a fresh session with /clear while keeping your current model and thinking level

Packages

Package details

extension

Install @grrrck/pi-clear from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@grrrck/pi-clear
Package
@grrrck/pi-clear
Version
0.2.0
Published
Oct 2, 2026
Downloads
452/mo · 25/wk
Author
grrrck
License
MIT
Types
extension
Size
9.6 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: 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:

  1. waits for the agent to become idle if needed, notifying you that it's waiting
  2. captures the active model and thinking level
  3. starts a new session via ctx.newSession()
  4. restores the captured model and thinking level in the new session
  5. 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

  • /clear only registers the slash command; it does not bind a keyboard shortcut, so it won't conflict with other extensions (such as pi-mono-clear, which uses Ctrl+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, /clear does 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 /clear alias for /new (does not preserve the model)

License

MIT