chat: delete sessions + auto-refresh the /chat list after each turn

DELETE /chat/sessions/:id removes Claude's transcript file; the list gets a
per-row delete button. The list also invalidates on turn-complete so new and
continued sessions surface without a manual refresh.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-24 10:14:27 +00:00
co-authored by Claude Opus 4.8
parent 9565cd9462
commit 4215c8df0a
5 changed files with 83 additions and 33 deletions
+9 -1
View File
@@ -1,5 +1,5 @@
import { createRouter } from '../../create-router';
import { getClaudeSessionsCwd, listClaudeSessions, loadClaudeSession } from './claude-sessions';
import { getClaudeSessionsCwd, listClaudeSessions, loadClaudeSession, deleteClaudeSession } from './claude-sessions';
export const chatRouter = createRouter();
@@ -18,3 +18,11 @@ chatRouter.get('/sessions/:id', (ctx) => {
if (!detail) return ctx.text('Not found', 404);
return ctx.json(detail);
});
// DELETE /chat/sessions/:id — remove a conversation (deletes Claude's transcript file).
chatRouter.delete('/sessions/:id', (ctx) => {
const email = ctx.get('user').email;
const ok = deleteClaudeSession(email, getClaudeSessionsCwd(email), ctx.req.param('id'));
if (!ok) return ctx.text('Not found', 404);
return ctx.json({ ok: true });
});
+9 -1
View File
@@ -1,4 +1,4 @@
import { readdirSync, readFileSync, existsSync, statSync, mkdirSync } from 'node:fs';
import { readdirSync, readFileSync, existsSync, statSync, mkdirSync, rmSync } from 'node:fs';
import { join } from 'node:path';
import { DATA_PATH } from '../../data-path';
@@ -187,6 +187,14 @@ export function loadClaudeSession(email: string, cwd: string, sessionId: string)
return { id: sessionId, model, cwd: sessionCwd, messages };
}
/** Delete a session by removing its transcript file. Returns false if it didn't exist. */
export function deleteClaudeSession(email: string, cwd: string, sessionId: string): boolean {
const filePath = join(claudeProjectsDir(email), projectSlug(cwd), `${sessionId}.jsonl`);
if (!existsSync(filePath)) return false;
rmSync(filePath);
return true;
}
/** List sessions Claude has stored for a given working directory, newest first. */
export function listClaudeSessions(email: string, cwd: string): ClaudeSessionSummary[] {
const dir = join(claudeProjectsDir(email), projectSlug(cwd));