← Catalog

@fahrizkyputra/pi-delete-session

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. Screenshots the session saved in ~/.agent-browser/shots go with it.

Extension

Install

Install with PiG

pig install npm:@fahrizkyputra/pi-delete-session

Install with Pi

pi install npm:@fahrizkyputra/pi-delete-session
Review before installing

Packages 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

CommandWhat it does
/delete-sessionDeletes the active session after a confirmation, then starts a fresh session
/delete-session listOpens a searchable checklist of sessions in the current project
/delete-session list --allSame checklist, across every project
/delete-session <query>Opens the checklist with the search already filled in
/delete-session orphansRemoves subagent data, and recorded screenshots, whose session is already gone (--all for every project)
/delete-session helpPrints the usage summary

Checklist keys

KeyAction
type anythingFilters as you type: matches session name, first message, transcript text, or cwd
↑ / ↓Move the highlight
tabSwitch between searching and selecting
spaceToggle the highlighted session (select mode)
aToggle every session the current search shows (select mode)
enterDelete the selected sessions
escClear 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 ★ (see pi-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 the agent-browser CLI, 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 shared subagent-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 trash CLI 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 /export if you might want the transcript later.
  • /delete-session list reads sessions through Pi's own SessionManager, so custom sessionDir settings and project grouping behave exactly like /resume.
  • Favorite detection is a plain check on the ★ name prefix, so this package works whether or not pi-session-favorites is installed.
  • The search field is Pi's own Input component, 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