What happened?
--list-sessions never tags the active session as current, so the delete guard never fires and --delete-session can remove the live session.
The interactive Session Browser does this correctly. The CLI path does not.
SessionBrowser passes the active session ID:
// packages/cli/src/ui/components/SessionBrowser.tsx
const sessionData = await getSessionFiles(
chatsDir,
config.getSessionId(),
);
However, SessionSelector.listSessions() does not:
// packages/cli/src/utils/sessionUtils.ts
async listSessions(): Promise<SessionInfo[]> {
const chatsDir = path.join(this.storage.getProjectTempDir(), 'chats');
return getSessionFiles(chatsDir);
}
getAllSessionFiles() only sets isCurrentSession when currentSessionId is passed. Without it, every session has isCurrentSession: false.
--list-sessions (packages/cli/src/utils/sessions.ts) therefore never prints , current.
--delete-session uses the same listing, so this guard never fires:
ts if (sessionToDelete.isCurrentSession) { writeToStderr('Cannot delete the current active session.'); return; }
The existing sessions.test.ts mocks isCurrentSession: true, so it does not exercise the real listSessions() path.
There is also a related matching issue in the same area: current-session detection uses:
ts file.includes(currentSessionId.slice(0, 8))
while sessionExists() already uses the correct suffix-based match:
ts endsWith(`-${shortId}.jsonl`)
Using includes() can incorrectly match another session whose filename happens to contain the same short ID.
Reproduction
- Start an interactive session so that chat history exists for the project.
- In another terminal, from the same project, run:
gemini --list-sessions
]
3. The active session is listed, but no row shows , current.
4. Run:
gemini --delete-session <index-of-that-session>
- The active session is deleted instead of printing:
Cannot delete the current active session.
Verified on current main. Platform: macOS.
What did you expect to happen?
--list-sessions should mark the active session with , current, matching the interactive Session Browser.
--delete-session on the current active session should print:
Cannot delete the current active session.
and leave the session file on disk.
listSessions() should pass config.getSessionId() into getSessionFiles(), and isCurrentSession should use the same suffix-based match as sessionExists() (endsWith(\-${shortId}.jsonl`)) rather than includes()`.
### Client information
<details>
<summary>Client Information</summary>
Run `gemini` to enter the interactive CLI, then run the `/about` command.
```console
> /about
About Gemini CLI │
│ │
│ CLI Version 0.57.0 │
│ Git Commit 6b0ae9a6c │
│ Model Auto │
│ Sandbox no sandbox │
│ OS darwin │
│ Auth Method gemini-api-key
Login information
Not auth-related. The issue is entirely local to session listing/deletion.
Anything else we need to know?
No response
cli version has been mentioned
What happened?
--list-sessionsnever tags the active session as current, so the delete guard never fires and--delete-sessioncan remove the live session.The interactive Session Browser does this correctly. The CLI path does not.
SessionBrowserpasses the active session ID:However, SessionSelector.listSessions() does not:
getAllSessionFiles() only sets isCurrentSession when currentSessionId is passed. Without it, every session has isCurrentSession: false.
--list-sessions (packages/cli/src/utils/sessions.ts) therefore never prints , current.
--delete-session uses the same listing, so this guard never fires:
ts if (sessionToDelete.isCurrentSession) { writeToStderr('Cannot delete the current active session.'); return; }The existing sessions.test.ts mocks isCurrentSession: true, so it does not exercise the real listSessions() path.
There is also a related matching issue in the same area: current-session detection uses:
ts file.includes(currentSessionId.slice(0, 8))while sessionExists() already uses the correct suffix-based match:
ts endsWith(`-${shortId}.jsonl`)Using includes() can incorrectly match another session whose filename happens to contain the same short ID.
Reproduction
gemini --list-sessions]
3. The active session is listed, but no row shows , current.
4. Run:
gemini --delete-session <index-of-that-session>Cannot delete the current active session.
Verified on current main. Platform: macOS.
What did you expect to happen?
--list-sessionsshould mark the active session with, current, matching the interactive Session Browser.--delete-sessionon the current active session should print:Login information
Not auth-related. The issue is entirely local to session listing/deletion.
Anything else we need to know?
No response
cli version has been mentioned