Skip to content

feat(cli): Safeguard embedded shell exit flow with Ctrl-C confirmation#12637

Closed
0xlakshan wants to merge 4 commits intogoogle-gemini:mainfrom
0xlakshan:feat/confirm-quit
Closed

feat(cli): Safeguard embedded shell exit flow with Ctrl-C confirmation#12637
0xlakshan wants to merge 4 commits intogoogle-gemini:mainfrom
0xlakshan:feat/confirm-quit

Conversation

@0xlakshan
Copy link
Contributor

@0xlakshan 0xlakshan commented Nov 6, 2025

Summary

#11291 - Add a confirmation step before quitting gemini-cli when pressing Ctrl-C inside the embedded shell.

Details

Add a confirmation step before quitting gemini-cli when pressing Ctrl-C inside the embedded shell. Right now, double Ctrl-D and double Ctrl-C both exit gemini-cli as expected, but in the new 0.9.0 interactive shell flow, users can easily get frustrated and spam Ctrl-C to cancel the embedding shell. That often ends up quitting the entire CLI and wiping out the conversation history.

This PR makes that flow safer by detecting Ctrl-C presses inside the embedded shell and showing a confirmation prompt before actually exiting, so quick or repeated Ctrl-C hits won’t accidentally terminate the whole session.

image

Related Issues

#11291

How to Validate

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker
@0xlakshan 0xlakshan requested a review from a team as a code owner November 6, 2025 13:40
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @0xlakshan, 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 enhances the Gemini CLI's interactive shell by adding a confirmation prompt when a user attempts to exit using Ctrl-C. This prevents unintended session terminations and the associated loss of conversation history, making the interactive experience more forgiving and user-friendly.

Highlights

  • Ctrl-C Exit Confirmation: Implemented a confirmation step when a user presses Ctrl-C inside the interactive shell, preventing accidental exits and loss of conversation history.
  • New React Hook: Introduced a new React hook, useEmbeddedShellExitConfirmation, to encapsulate the logic for managing the exit confirmation prompt.
  • Improved User Experience: The change makes the interactive shell more robust against rapid or accidental Ctrl-C presses, enhancing the overall user experience by safeguarding ongoing sessions.
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
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 confirmation step to prevent accidental exits from the embedded shell via Ctrl-C, which is a great usability improvement. The implementation uses a new custom hook to manage the confirmation dialog state. The logic seems well-thought-out. I've found one potential issue regarding a stale closure in the new hook that could lead to unpredictable behavior, which I've detailed in a specific comment. Addressing this will make the implementation more robust.

Comment on lines +32 to +47
useEffect(() => {
if (triggerEmbeddedShellExit) {
setTriggerEmbeddedShellExit(false);
setEmbeddedShellExitConfirmationRequest({
prompt: createElement(
Text,
null,
'Are you sure you want to quit? Any unsaved conversation history will be lost.',
),
onConfirm: (answer) => {
setEmbeddedShellExitConfirmationRequest(null);
if (answer) quit();
},
});
}
}, [triggerEmbeddedShellExit, quit]);
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The onConfirm callback defined inside this useEffect creates a stale closure over the quit function. The quit function depends on the handleSlashCommand prop, which can change during the component's lifecycle. If handleSlashCommand changes while the confirmation dialog is displayed, onConfirm will call an outdated quit function. This could lead to unpredictable behavior.

To ensure the latest quit function is always called, you can store it in a ref. This is a common pattern in React to handle callbacks that depend on props or state that may change.

Here is a suggested implementation:

import { useState, useEffect, createElement, useCallback, useRef } from 'react'; // ... const quit = useCallback(() => { handleSlashCommand('/quit'); }, [handleSlashCommand]); const quitRef = useRef(quit); useEffect(() => { quitRef.current = quit; }); useEffect(() => { if (triggerEmbeddedShellExit) { setTriggerEmbeddedShellExit(false); setEmbeddedShellExitConfirmationRequest({ prompt: createElement( Text, null, 'Are you sure you want to quit? Any unsaved conversation history will be lost.', ), onConfirm: (answer) => { setEmbeddedShellExitConfirmationRequest(null); if (answer) quitRef.current(); }, }); } }, [triggerEmbeddedShellExit]);

Note that you will need to add useRef to your imports from react.

@0xlakshan 0xlakshan changed the title feat(cli): Add Ctrl-C exit confirmation for interactive shell feat(cli): Safeguard embedded shell exit flow with Ctrl-C confirmation Nov 10, 2025
@gemini-cli gemini-cli bot added status/need-issue Pull requests that need to have an associated issue. priority/p1 Important and should be addressed in the near term. and removed status/need-issue Pull requests that need to have an associated issue. labels Jan 7, 2026
@bdmorgan
Copy link
Collaborator

Hi @0xlakshan, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

Thank you for your understanding and for being a part of our community!

@bdmorgan
Copy link
Collaborator

Thank you for submission to the Gemini CLI project. At this time, we are closing this pull request in order to allow us to better triage and support more recent pull requests against the latest code changes. If you feel like this pull request is a critical contribution to the Gemini CLI project, please associate the pull request with an existing GitHub issue (instructions here: https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue) before reopening. After Monday January 26 2026, any pull requests submitted by contributors without an associated issue will be automatically closed (more information here: #16706). If you do choose to reopen and submit this pull request, please ensure you rebase your changes onto the current main branch before resubmitting. This will help avoid merge conflicts and ensure your contribution is compatible with the latest codebase.

@bdmorgan bdmorgan closed this Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/p1 Important and should be addressed in the near term.

2 participants