@fahrizkyputra/pi-delete-session
v0.3.0
Published
Delete the active Pi session (and start a fresh one), or multi-select saved sessions to clean up. Confirmation first, extra confirmation for favorites, trash-safe deletion.
Maintainers
Readme
pi-delete-session
Delete the Pi session you are in — or multi-select saved sessions and clean them up in bulk — from one slash command.
Pi ships session deletion only inside the /resume picker (Ctrl+D, one file at a time). This extension adds the command people actually reach for.
Install
pi install npm:@fahrizkyputra/pi-delete-sessionOr try it for one run:
pi -e npm:@fahrizkyputra/pi-delete-sessionUsage
| Command | What it does |
|---|---|
| /delete-session | Deletes the active session after a confirmation, then starts a fresh session |
| /delete-session list | Opens a searchable checklist of sessions in the current project |
| /delete-session list --all | Same checklist, across every project |
| /delete-session <query> | Opens the checklist with the search already filled in |
| /delete-session orphans | Removes subagent data whose parent session is already gone (--all for every project) |
| /delete-session help | Prints the usage summary |
Checklist keys
| Key | Action |
|---|---|
| type anything | Filters as you type: matches session name, first message, transcript text, or cwd |
| ↑ / ↓ | Move the highlight |
| tab | Switch between searching and selecting |
| space | Toggle the highlighted session (select mode) |
| a | Toggle every session the current search shows (select mode) |
| enter | Delete the selected sessions |
| esc | Clear the search, then leave the checklist |
Selections survive filtering, so you can search auth, tick one session, search deploy, tick another, and delete both at once.
/delete-session list
Sessions in this project
⌕ deploy▌
────────────────────────────
[x] Deploy script (current) — 5m ago · 18 msg
[ ] deploy hotfix notes — 2h ago · 31 msg
2 of 7 shown
1 selected · searching · ↑↓ move · tab: select mode · enter: delete 1 · esc: clearWhat happens on delete
- Confirmation first. The current-session dialog shows the session file, its entry count, and its size. Bulk delete lists every selected session before touching anything.
- Favorites are protected by a second question. Sessions marked
★(seepi-session-favorites) trigger another confirmation before they are removed; declining it cancels the whole deletion, so nothing is lost by accident. - Subagent data goes with the session. pi-subagents stores child sessions next to the parent (
<session>/<runId>/run-N/session.jsonl) and prompts, outputs, and transcripts in the project's sharedsubagent-artifacts/. Deleting a session removes its own child runs and only the artifacts with its run ids; other sessions' data stays. The confirmation dialog shows how many subagent runs are included. - Trash-safe. Files are moved to the OS trash with the
trashCLI when it is installed, and unlinked otherwise. Same behavior as Pi's built-in picker. - No orphan writes. When the active session is deleted, a new session starts first, so Pi never re-creates the file you just deleted.
- Works without a TUI. In RPC mode the bulk flow falls back to one-by-one selection dialogs.
Notes
- Deleting sessions is permanent from Pi's point of view. Prefer
/exportif you might want the transcript later. /delete-session listreads sessions through Pi's ownSessionManager, so customsessionDirsettings and project grouping behave exactly like/resume.- Favorite detection is a plain check on the
★name prefix, so this package works whether or notpi-session-favoritesis installed. - The search field is Pi's own
Inputcomponent, so typing, pasting, word-delete, and IME behavior match the rest of the terminal UI.
Development
npm install
npm test # node:test, no Pi required
npm run typecheck # tsc --noEmit
npm run test:e2e # real Pi over RPC: runs /delete-session and checks the file is gonenpm run test:e2e needs the pi binary on PATH and a Pi build with the RPC extension UI sub-protocol. It answers the confirmation dialog over the wire and fails on any extension_error event, so stale-context regressions surface in CI instead of in your terminal.
Try it locally without publishing:
pi -e /path/to/pi-delete-sessionsrc/handlers.ts holds the command logic behind an injected host, src/session-files.ts holds the filesystem helpers, and extensions/delete-session.ts is the thin wiring into Pi. Never touch the command context after newSession(): the replacement makes it stale, and Pi throws.
License
MIT
