Skip to content

feat(cli): add /new command to start a fresh session while preserving…#20442

Draft
ActuallyAnson wants to merge 1 commit intogoogle-gemini:mainfrom
ActuallyAnson:feat/new-command
Draft

feat(cli): add /new command to start a fresh session while preserving…#20442
ActuallyAnson wants to merge 1 commit intogoogle-gemini:mainfrom
ActuallyAnson:feat/new-command

Conversation

@ActuallyAnson
Copy link

feat(cli): add /new command to start a fresh session

Introduce a built-in /new command that starts a new conversation
while preserving the current session for later use with /resume.

The command:

  • Executes session end/start lifecycle hooks
  • Assigns a new session ID before reinitializing chat recording
  • Flushes telemetry
  • Resets chat state and UI hints

Includes unit tests covering lifecycle ordering and behavior
when the config service is absent.

Fixes #16848

… current for /resume

Unlike /clear which makes the current session unavailable for resumption,
/new assigns a fresh session ID before reinitializing the recording service,
ensuring the previous conversation remains accessible via /resume.

Closes google-gemini#16835
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @ActuallyAnson, 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 enhancement to the CLI by adding a /new command. This command empowers users to initiate a completely fresh chat session while intelligently preserving their ongoing conversation for future reference or continuation. This improves user workflow by providing flexibility to switch contexts without losing previous work, ensuring a clean slate for new interactions while maintaining the ability to revisit prior discussions.

Highlights

  • New Command Introduction: Introduced a /new command to start fresh conversations within the CLI.
  • Session Preservation: Enabled preservation of the current session, allowing it to be resumed later using the /resume command.
  • Lifecycle Hook Execution: Ensured proper execution of session end and start lifecycle hooks during the new session creation process.
  • Session ID Management: Implemented assignment of a new session ID before reinitializing chat recording to maintain session integrity and enable preservation.
  • Telemetry and UI Reset: Added logic to flush telemetry, reset chat state, and clear UI hints for a clean and consistent new session experience.
  • Unit Tests: Included comprehensive unit tests to cover lifecycle ordering, behavior when the config service is absent, and overall functionality of the /new command.
Changelog
  • packages/cli/src/services/BuiltinCommandLoader.ts
    • Imported and registered the new newCommand.
  • packages/cli/src/ui/commands/newCommand.test.ts
    • Added unit tests for the newCommand covering chat reset, session ID assignment, recording reinitialization, telemetry reset, and UI clearing.
    • Verified the order of session ID assignment and recording initialization.
    • Tested behavior when the config service is unavailable.
  • packages/cli/src/ui/commands/newCommand.ts
    • Implemented the newCommand logic, including firing session end/start hooks, resetting the Gemini client chat, clearing user hints, assigning a new session ID, reinitializing chat recording, flushing telemetry, and clearing the UI.
Activity
  • No human activity has been recorded on this pull request yet.
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 /new command to start a fresh chat session while preserving the current one. The implementation includes the command logic, unit tests, and integration into the CLI's command loader.

My review found a critical issue in the implementation of the /new command's action. The logic for creating a new session recording is flawed due to a stale object reference, which prevents the command from working as intended. I have provided a detailed comment and a code suggestion to correct the sequence of operations.

Comment on lines +38 to +57
if (geminiClient) {
context.ui.setDebugMessage(
'Starting new session and preserving current conversation.',
);
await geminiClient.resetChat();
} else {
context.ui.setDebugMessage('Starting new session.');
}

// Reset user steering hints
config?.userHintService.clear();

// Assign a new session ID before re-initializing the recording service.
// This ensures the previous session's recording is preserved on disk under
// its original session ID and remains available via /resume.
if (config && chatRecordingService) {
const newSessionId = randomUUID();
config.setSessionId(newSessionId);
chatRecordingService.initialize();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

critical

The current logic for starting a new session is flawed. The chatRecordingService variable is captured before geminiClient.resetChat() is called. Since resetChat() creates a new service instance internally, the chatRecordingService variable becomes a stale reference. Calling initialize() on this stale reference doesn't affect the active session, and the old session is not preserved as intended.

To fix this, set the new session ID on the config object before calling resetChat(). This allows resetChat() to use the new ID when it initializes the new session recording.

The chatRecordingService variable (defined on lines 27-30) will become unused with this change and should be removed.

    if (geminiClient && config) {
      context.ui.setDebugMessage(
        'Starting new session and preserving current conversation.',
      );

      // Assign a new session ID before resetting the chat. `resetChat` will then
      // use this new ID to initialize the new session recording.
      const newSessionId = randomUUID();
      config.setSessionId(newSessionId);

      await geminiClient.resetChat();
    } else {
      context.ui.setDebugMessage('Starting new session.');
    }

    // Reset user steering hints
    config?.userHintService.clear();

@gemini-cli gemini-cli bot added priority/p3 Backlog - a good idea but not currently a priority. area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt 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.

1 participant