Skip to content

feat(sidebar): delete all sessions of a project from its menu - #1182

Merged
agegr merged 5 commits into
mainfrom
claude/delete-project-sessions-74046a
Oct 11, 2026
Merged

agegr merged 5 commits into
mainfrom
claude/delete-project-sessions-74046a

Conversation

@agegr

@agegr agegr commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Adds Delete all sessions… · N to a project group's ⋯ menu.

What it does

  • The item sits last in the group menu, after a separator, in red. N is counted live. It is disabled at 0.
  • It deletes every family of the project that has a file: live, pinned and archived ones too. Each family's subagent sessions go with it. It keeps families that are running or waiting for input, because deleting one would stop its run. Transient (unsaved) sessions are skipped.
  • Choosing it turns the menu into a question: "Delete all sessions in X", "Pinned and archived sessions go too. This can't be undone.", a note when running ones are kept, then Delete N and Cancel.
    • Focus starts on Cancel, so Enter never deletes.
    • On a desktop, Cancel goes back to the list. On a phone the sheet's own Cancel takes the focus and closes the sheet.
  • Delete closes the menu. A toast shows "Deleting sessions…", then "Deleted N sessions" (plus "kept M running" when that applies) or the error.
  • Each deleted id goes to onSessionDeleted, so an open session among them falls back to a fresh composer in its cwd.
  • The project's pin, place, display name and expansion are left alone. A current or pinned project keeps its group, now empty.

Server

  • The row delete's code moves from app/api/sessions/[id]/route.ts into lib/session-delete.ts as deleteSessions(ids, { keepRunning? }). DELETE /api/sessions/[id] now calls it with one id and behaves as before.
  • New POST /api/sessions/delete { ids }:
    • Same request checks as Fork (isApiRequestAllowed, JSON content type).
    • At most 500 ids per request. The sidebar sends bigger projects in parts, one request at a time.
    • Answers { deleted, missing, running }. A session that started running after the user confirmed is kept and reported, not stopped.
  • Each request lists the catalogue once and reads each folder once. Sending one DELETE per session would read every file in the folder once per session.
  • A session that stays but whose parent is deleted is re-pointed to its nearest ancestor that stays, even across several deleted levels (before, only one level was handled). Subagent wrappers are shut down before their parents. Pins and archive times of every deleted id are removed.

Tests

  • app/api/sessions/delete-route.test.mjs covers:
    • a bulk delete with a subagent, an idle open wrapper (shut down) and a running one (kept, not shut down)
    • a missing id
    • re-pointing past two deleted ancestors, a header losing its parent when no ancestor stays, and subagent meta following the header
    • request refusals (415, 403, 400s, more than 500 ids)
  • lib/session-tree.test.mjs: familiesToDelete() (pinned, archived, worktree, fork and subagent families are in; running, awaiting and transient ones are out).
  • lib/sidebar-actions.test.mjs: deleteProjectSessions() sends parts in order and sums the answers; a refused part or a network error stops the run and reports what was already deleted.
  • components/SessionSidebar.test.mjs: menu item, question body, focus and the delete flow.
  • lib/rpc-manager.test.mjs: the graceful-shutdown source check now reads lib/session-delete.ts.
  • Typecheck, lint and npm test (2941 pass) all pass after merging current main.
  • Manual check on an isolated dev server (scratch PI_CODING_AGENT_DIR, two projects, one pinned, one archived, one with a subagent):
    • Desktop, mouse and keyboard (End → Enter → Shift+Tab → Enter): all 6 of alpha's files were deleted and both of beta's stayed. The pins and archive entries were cleared. The open alpha session fell back to a fresh composer. Focus landed on the alpha header.
    • Phone sheet at 375px: layout and focus as described above.
    • Not checked by hand: the "running kept" path, since the scratch dir has no model to run. The route test covers it.

Docs: docs/agents/sessions.md (sidebar section) and the AGENTS.md file map.

🤖 Generated with Claude Code

agegr and others added 5 commits October 11, 2026 17:05
A project group's ⋯ menu ends with "Delete all sessions… · N": the menu
turns into a question (Cancel focused, so Enter deletes nothing), then
deletes every family of the project that has a file, pinned and archived
ones included, keeping the ones that run or wait for input. A toast says
how many went; an open session among them falls back to a fresh composer.

The row delete's server code moves to lib/session-delete.ts as
deleteSessions(ids), shared by DELETE /api/sessions/[id] and the new
POST /api/sessions/delete: one catalogue listing and one read of each
folder per request instead of per session, subagents with their parent,
survivors re-pointed at their nearest ancestor that stays, and with
keepRunning a session that started running since the question is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…-sessions-74046a

# Conflicts:
#	AGENTS.md
#	lib/sidebar-actions.ts
…-sessions-74046a

# Conflicts:
#	AGENTS.md
#	components/SessionSidebar.test.mjs
#	lib/rpc-manager.test.mjs
Main now keeps only tests that run code; the route tests above cover the
bulk delete, and runtime-route.test.mjs the row's single delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr merged commit c8182b1 into main Oct 11, 2026
2 checks passed
agegr added a commit that referenced this pull request Oct 11, 2026
#1182 added lib/session-delete.ts to the sessions.md entry in AGENTS.md,
the same line this branch rewords for the Prism languages; keep both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@agegr
agegr deleted the claude/delete-project-sessions-74046a branch October 29, 2026 13:01
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 6, 2026
…1182)

* feat(sidebar): delete all sessions of a project from its menu

A project group's ⋯ menu ends with "Delete all sessions… · N": the menu
turns into a question (Cancel focused, so Enter deletes nothing), then
deletes every family of the project that has a file, pinned and archived
ones included, keeping the ones that run or wait for input. A toast says
how many went; an open session among them falls back to a fresh composer.

The row delete's server code moves to lib/session-delete.ts as
deleteSessions(ids), shared by DELETE /api/sessions/[id] and the new
POST /api/sessions/delete: one catalogue listing and one read of each
folder per request instead of per session, subagents with their parent,
survivors re-pointed at their nearest ancestor that stays, and with
keepRunning a session that started running since the question is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sessions): drop the delete route's source-text assertion

Main now keeps only tests that run code; the route tests above cover the
bulk delete, and runtime-route.test.mjs the row's single delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
windli2018 pushed a commit to aiti-ai/aiti-ai that referenced this pull request Nov 8, 2026
…1182)

* feat(sidebar): delete all sessions of a project from its menu

A project group's ⋯ menu ends with "Delete all sessions… · N": the menu
turns into a question (Cancel focused, so Enter deletes nothing), then
deletes every family of the project that has a file, pinned and archived
ones included, keeping the ones that run or wait for input. A toast says
how many went; an open session among them falls back to a fresh composer.

The row delete's server code moves to lib/session-delete.ts as
deleteSessions(ids), shared by DELETE /api/sessions/[id] and the new
POST /api/sessions/delete: one catalogue listing and one read of each
folder per request instead of per session, subagents with their parent,
survivors re-pointed at their nearest ancestor that stays, and with
keepRunning a session that started running since the question is kept.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(sessions): drop the delete route's source-text assertion

Main now keeps only tests that run code; the route tests above cover the
bulk delete, and runtime-route.test.mjs the row's single delete.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant