google-gemini / google-gemini/gemini-cli
Bug: --list-sessions never marks the current session, so --delete-session can delete it
- Dominant language
- TypeScript
- Stars
- 107k
- Forks
- 14.6k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 45
Description
### 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:
```ts
// packages/cli/src/ui/components/SessionBrowser.tsx
const sessionData = await getSessionFiles(
chatsDir,
config.getSessionId(),
);
```
However, SessionSelector.listSessions() does not:
```ts
// packages/cli/src/utils/sessionUtils.ts
async listSessions(): Promise {
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
1. Start an interactive session so that chat history exists for the project.
2. 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 `
5. 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:
```text
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
Client Information
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
Contributor guide
Research direction
Start in packages/cli/src/utils/sessionUtils.ts and packages/cli/src/utils/sessions.ts, comparing listSessions() with SessionBrowser.tsx and the existing sessions.test.ts. Trace how getSessionFiles() determines isCurrentSession and how --delete-session consumes it. Done means the active session is marked current, deletion is refused with the stated message, and the suffix-based matching case is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100