Install
Install with PiG
pig install npm:@nicknisi/pi-stashInstall with Pi
pi install npm:@nicknisi/pi-stashPackages run code with your permissions and influence agent behavior. Catalog inclusion is not a security audit. Review the source before installing a third-party package.
Pi manifest JSON
The pi field of package.json.
{
"extensions": [
"./index.ts"
]
}README
Written by the package's publisher, shown as published in version 0.2.2 (README.md). PiG does not review it.
@nicknisi/pi-stash
Replicates Claude Code's message stash using ctrl+s. Rebind Pi's built-in ctrl+s actions as shown below to avoid shortcut conflicts. Press ctrl+s to stash whatever you've typed in the input editor, go do something else, then press ctrl+s again with an empty editor to pop the most recent stash back. Stashes live on a stack, so multiple drafts can be parked and restored LIFO.
What it adds
- Keybinding:
ctrl+stoggles stash/restore. See the behavior table below. - Widget: a single-line widget above the editor, visible whenever the stash stack is non-empty, showing a 60-char preview of the most recent stash, the count of additional stashes (
(+N more)), and actrl+s to restorehint - Events hooked:
before_agent_start: after you submit a message from the editor and the agent starts, this session's most recent stash is auto-restored into the now-empty editor (mirrors Claude Code). Runs started by other extensions (pi.sendUserMessage(),pi.sendMessage(..., { triggerTurn: true })) don't restore anything.input: records where the last prompt came from, so only prompts typed in the editor trigger the auto-restore.session_start: shows the widget for drafts already saved for this directory.
- No slash commands, no tools, no custom entry types.
Keybinding behavior
Editor state on ctrl+s | Action |
|---|---|
| Contains text | Push text onto the stack, clear the editor |
| Empty (or whitespace) and stack non-empty | Pop the most recent stash into the editor (from any session in this directory) |
| Empty and stack empty | No-op |
Usage
(type a long prompt, then need to ask something else first)
ctrl+s "⧉ stashed: Refactor the auth module to..." · editor cleared
(ask the other question; on submit, the stashed draft is restored automatically)
ctrl+s (with empty editor) pops the stash back manually
Persistence
Drafts are saved per working directory under <agentDir>/stash/<hash of cwd>/ (normally ~/.pi/agent/stash/), one file per draft, so they survive /reload, quitting Pi, and starting a new session in the same directory. The stack keeps the newest 10 drafts and drops the oldest.
No file is ever rewritten, so there is no lock:
- Stashing writes the draft to a temporary file (mode
0600), flushes it to disk, and renames it into place. The editor is cleared only after the rename, so a saved draft survives Pi exiting or crashing. The folder is also flushed after the rename for power-loss protection, but only on a best-effort basis: it's skipped on Windows, and a failed folder flush is ignored. - Restoring claims a draft by deleting its file. Only one window's delete can succeed, so two windows never get the same draft. The draft is put in the editor right after the claim, before anything else that could fail.
Each draft remembers the session that stashed it. Sending a message only auto-restores drafts from the current session, so another Pi window in the same directory never has a draft pulled into its editor. ctrl+s on an empty editor restores the newest draft from any session.
A draft file that can't be read is skipped and left alone. If a draft can't be saved, the extension reports an error and leaves the text in the editor.
Configuration
The stash shortcut is fixed at ctrl+s. Move Pi's built-in actions off that key in ~/.pi/agent/keybindings.json:
{
"app.models.save": ["ctrl+shift+v"],
"app.thinking.save": ["ctrl+shift+v"],
"app.session.toggleSort": ["ctrl+shift+r"]
}
Merge these entries into your existing config, then run /reload. Model-save and thinking-save use separate selectors, so they can share a key. pi-web-access can keep its default ctrl+shift+s curator shortcut.
Dependencies
- Peer:
@earendil-works/pi-coding-agent(*). Uses only the public extension API:pi.registerShortcut,pi.on("before_agent_start" | "input" | "session_start"),getAgentDir(),ctx.sessionManager.getSessionId(),ctx.ui.getEditorText/setEditorText/setWidget/notify/theme,ctx.hasUI, andctx.mode. - Node built-ins:
node:crypto,node:fs,node:path. No runtime npm dependencies, no workspace deps.
Caveats
- TUI-only: every handler checks
ctx.mode === "tui"; the extension is a no-op in RPC, JSON, and print modes (RPC has no editor text to stash or restore into). - Depends on the editor text APIs (
ctx.ui.getEditorText/setEditorText) and the widget system (ctx.ui.setWidget) — these are stable pi extension APIs, but a pi version that changes editor or widget semantics could affect it. - The
before_agent_startauto-restore pops a stash whenever a message is sent with an empty editor. If you intentionally sent a quick command and wanted the stash to stay parked, it will still be restored into the editor (you canctrl+sit back). This matches Claude Code's behavior. - The shifted replacement shortcuts require a terminal that reports them distinctly, for example through the Kitty keyboard protocol. The widget preview uses the Unicode glyphs
⧉and….
Install
pi install npm:@nicknisi/pi-stash
Or from a local checkout of this repo:
pi install ./packages/stash