Skip to content

feat(cli): add --delete flag to /exit command for session deletion#19332

Open
AbdulTawabJuly wants to merge 22 commits intogoogle-gemini:mainfrom
AbdulTawabJuly:feat/exit-delete-flag
Open

feat(cli): add --delete flag to /exit command for session deletion#19332
AbdulTawabJuly wants to merge 22 commits intogoogle-gemini:mainfrom
AbdulTawabJuly:feat/exit-delete-flag

Conversation

@AbdulTawabJuly
Copy link
Copy Markdown
Contributor

Summary

Add an optional --delete flag to the /exit (and /quit) command that allows users to delete the current session's history and temporary files when exiting the CLI. This provides a privacy-focused workflow for users who want to ensure their session data doesn't persist after they quit.

Details

Implementation:

  • Extended the QuitActionReturn interface with an optional deleteSession?: boolean field
  • Modified quitCommand.ts to parse the --delete flag from command arguments
  • Updated slashCommandProcessor.ts to detect the flag and call ChatRecordingService.deleteSession() before quitting
  • Reused existing session deletion logic from session browser for consistency
  • Implemented silent error handling to ensure deletion failures don't block the exit flow

Testing:

  • Added 2 unit tests in quitCommand.test.ts to verify flag parsing
  • Added 3 integration tests in slashCommandProcessor.test.tsx to verify session deletion behavior
  • All 44 tests passing, TypeScript compilation clean

Documentation:

  • Updated docs/cli/commands.md with flag documentation
  • Added "Exiting without leaving traces" scenario to docs/cli/tutorials/session-management.md

Related Issues

Fixes #18871

How to Validate

Manual Testing:

  1. Start the CLI in a project directory:
    npm start

@AbdulTawabJuly AbdulTawabJuly requested review from a team as code owners February 18, 2026 01:31
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @AbdulTawabJuly, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a significant privacy enhancement to the CLI by allowing users to delete their session data upon exit. By adding a --delete flag to the /exit and /quit commands, users can now ensure that their conversation history and temporary files are removed, which is particularly useful for sensitive tasks or one-off interactions. The change provides greater control over data persistence and improves the overall user experience for privacy-conscious individuals.

Highlights

  • New --delete flag for /exit and /quit commands: Introduced an optional --delete flag for the /exit and /quit commands, allowing users to permanently delete the current session's history and temporary files upon exiting the CLI. This enhances privacy by ensuring no traces are left behind after a session.
  • Session Deletion Logic Integration: Integrated existing session deletion logic from the ChatRecordingService into the command processing flow. When the --delete flag is used, the system now identifies the current session's file path, extracts its ID, and calls the deleteSession method to remove associated data.
  • Robust Error Handling for Deletion: Implemented silent error handling for the session deletion process. If an error occurs during file deletion, it will not prevent the CLI from exiting, ensuring a smooth user experience even in unexpected scenarios.
  • Comprehensive Testing and Documentation: Added new unit tests for flag parsing in quitCommand.test.ts and integration tests for session deletion behavior in slashCommandProcessor.test.tsx. The CLI documentation (docs/cli/commands.md and docs/cli/tutorials/session-management.md) has been updated to reflect the new flag and its usage for privacy-focused exiting.
Changelog
  • docs/cli/commands.md
    • Added documentation for the new --delete flag under the /quit and /exit commands, detailing its description and usage.
  • docs/cli/tutorials/session-management.md
    • Added a new tutorial scenario titled 'Exiting without leaving traces' to explain how to use the --delete flag for privacy-sensitive exits.
  • packages/cli/src/ui/commands/quitCommand.test.ts
    • Modified an existing test to pass an empty string as an argument to the quitCommand.action.
    • Added a new test case to verify that deleteSession is set to true when the --delete flag is provided.
    • Added a new test case to confirm that deleteSession is not set when unrecognized arguments are provided.
  • packages/cli/src/ui/commands/quitCommand.ts
    • Modified the action function to accept an args parameter.
    • Implemented logic to parse the args and set the deleteSession property in the QuitActionReturn object if --delete is present.
  • packages/cli/src/ui/commands/types.ts
    • Extended the QuitActionReturn interface with an optional deleteSession?: boolean property and its JSDoc comment.
  • packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx
    • Added an integration test to confirm that the current session is deleted when the quit action includes the deleteSession flag.
    • Added an integration test to verify that the session is not deleted when the quit action does not include the deleteSession flag.
    • Added an integration test to ensure that the CLI still quits even if the session deletion process fails.
  • packages/cli/src/ui/hooks/slashCommandProcessor.ts
    • Imported the path module for file path manipulation.
    • Modified the quit case within the handleSlashCommand function to conditionally delete the session if result.deleteSession is true.
    • Implemented logic to retrieve the ChatRecordingService, get the conversation file path, extract the session ID, and call deleteSession.
    • Added a try-catch block around the deletion logic to prevent deletion failures from blocking the exit flow.
Activity
  • Extended the QuitActionReturn interface with an optional deleteSession field.
  • Modified quitCommand.ts to parse the --delete flag from command arguments.
  • Updated slashCommandProcessor.ts to detect the flag and call ChatRecordingService.deleteSession() before quitting.
  • Reused existing session deletion logic from the session browser for consistency.
  • Implemented silent error handling to ensure deletion failures don't block the exit flow.
  • Added 2 unit tests in quitCommand.test.ts to verify flag parsing.
  • Added 3 integration tests in slashCommandProcessor.test.tsx to verify session deletion behavior.
  • All 44 tests are passing, and TypeScript compilation is clean.
  • Updated docs/cli/commands.md with flag documentation.
  • Added 'Exiting without leaving traces' scenario to docs/cli/tutorials/session-management.md.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a --delete flag to the /exit and /quit commands, allowing users to delete the current session's data upon exiting. The implementation correctly parses the flag and triggers the session deletion logic. However, the deletion implementation in slashCommandProcessor.ts uses synchronous I/O, which can make the CLI unresponsive on exit. Additionally, the method for identifying the session to be deleted is fragile and tightly coupled to the implementation details of the ChatRecordingService. I've provided feedback on how to make this more robust and performant.

Comment thread packages/cli/src/ui/hooks/slashCommandProcessor.ts
@gemini-cli gemini-cli Bot added priority/p3 Backlog - a good idea but not currently a priority. area/core Issues related to User Interface, OS Support, Core Functionality area/security Issues related to security labels Feb 18, 2026
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Mar 15, 2026

Hi there! Thank you for your interest in contributing to Gemini CLI.

To ensure we maintain high code quality and focus on our prioritized roadmap, we have updated our contribution policy (see Discussion #17383).

We only guarantee review and consideration of pull requests for issues that are explicitly labeled as 'help wanted'. All other community pull requests are subject to closure after 14 days if they do not align with our current focus areas. For this reason, we strongly recommend that contributors only submit pull requests against issues explicitly labeled as 'help-wanted'.

This pull request is being closed as it has been open for 14 days without a 'help wanted' designation. We encourage you to find and contribute to existing 'help wanted' issues in our backlog! Thank you for your understanding and for being part of our community!

@cocosheng-g
Copy link
Copy Markdown
Contributor

@AbdulTawabJuly, apologies for the bot closing this PR! We have reopened it. Please sync your branch to the latest main and we will have someone review it shortly.

@gemini-cli gemini-cli Bot added the help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! label Apr 9, 2026
@AbdulTawabJuly
Copy link
Copy Markdown
Contributor Author

@cocosheng-g I’ve synced this branch with main and resolved all conflicts. Could you please review it now? Thanks!

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Exiting should be something users do not have to think about, adding this --delete could have consequences so need to make sure we avoid certain elements.

Right now typing /ex and hitting Enter on the suggestion autofires the exit command. We would than this behavior to be untouched. Sometimes adding flags or subcommands can cause this behavior to change to adding the /exit command to the prompt window on first Enter and forcing users to hit Enter again to send it. We don't want this to be the case so let's verify this doesn't happen.

Comment thread docs/cli/tutorials/session-management.md Outdated
Comment thread docs/reference/commands.md Outdated

- **Description:** Exit Gemini CLI.
- **Flags:**
- **`--delete`**: Exit and permanently delete the current session's history
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearly state this is optional please

await tool.buildAndExecute(result.toolArgs, abortSignal, undefined, {
shellExecutionConfig: {
sanitizationConfig: DEFAULT_SANITIZATION_CONFIG,
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we adding all of these?

@AbdulTawabJuly
Copy link
Copy Markdown
Contributor Author

Hey @jackwotherspoon , thanks for the review, I've addressed all your feedback

Autofire behavior : I tested the /exit command and the single Enter autofire still works as expected. The --delete flag is parsed purely inside the action callback [args.trim() === --delete, so autoExecute: true is completely untouched and the autocomplete behavior is identical to before.

Docs : Updated the section title in session-management.md to Delete session on exit and added (optional) to the --delete flag description in commands.md.

Unrelated eslint-disable comments : Removed them all. I had added those initially because after syncing with main, the pre commit hook was failing with lint errors across several files. I suppressed them to unblock the merge, but I understand those belong to pre existing issues in those files and shouldn't be in this PR. They're now cleaned up.

@AbdulTawabJuly
Copy link
Copy Markdown
Contributor Author

Hi @jackwotherspoon , could you review this PR again? I’ve implemented all the suggestions and changes you recommended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality area/security Issues related to security help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p3 Backlog - a good idea but not currently a priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Add a command to delete current session upon exit

4 participants