Install
Install with PiG
pig install npm:@fahrizkyputra/pi-delete-sessionInstall with Pi
pi install npm:@fahrizkyputra/pi-delete-sessionPackages 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": [
"./extensions/delete-session.ts"
]
}README
Written by the package's publisher, shown as published in version 0.4.0 (README.md). PiG does not review it.
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-session
Or try it for one run:
pi -e npm:@fahrizkyputra/pi-delete-session
Usage
| 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, and recorded screenshots, whose 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: clear
What 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. - Screenshots the session made go with it. Photos saved under
~/.agent-browser/shots(by theagent-browserCLI, a UI-screenshot skill, or any tool call) are recorded for the session that made them, at the moment they are made: the folder is compared before and after each tool call, and an image counts only when that call itself names it. A photo is removed with a session only when every session that made it is being deleted (a shared photo waits for its last owner) and it is unchanged since it was recorded. Photos made before this version, by another program, or changed since are never touched, and neither is anything that is not an image or lies outside that folder. The confirmation dialog shows how many photos go and how many stay. Records live in~/.pi/agent/delete-session/shots/. - 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 gone
npm 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-session
src/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