Skip to content

feat: add /new command#16848

Closed
sujay-bhandari wants to merge 5 commits intogoogle-gemini:mainfrom
sujay-bhandari:feat-new-command
Closed

feat: add /new command#16848
sujay-bhandari wants to merge 5 commits intogoogle-gemini:mainfrom
sujay-bhandari:feat-new-command

Conversation

@sujay-bhandari
Copy link
Copy Markdown

@sujay-bhandari sujay-bhandari commented Jan 16, 2026

PR Description

Summary of Changes

This Pull Request addresses the following issue:

  1. Issue Add /new command equivalent to starting gemini cli #16835: Add /new command: Implements a new slash command /new that starts a fresh chat session without clearing the terminal history. This allows users to "start over" with the LLM context while preserving the visible history of the previous session, which is also saved to disk for future resumption.

Details

/new Command

  • Use randomUUID() to generate a new session ID.
  • Calls client.resetChat() to clear the in-memory chat context.
  • Re-initializes ChatRecordingService to ensure the new session marks the end of the previous one (which is flushed to disk).
  • Fires SessionEnd (Clear) and SessionStart (Clear) hooks to maintain proper lifecycle management.
  • Does not clear the terminal screen (unlike /clear), fulfilling the user requirement to keep context visible.

Related Issue

Fixes #16835

How to Test

Testing /new Command

  1. Start the CLI: npm start.
  2. Chat with the bot (e.g., "Hello, remember this number: 42").
  3. Run the command: /new.
  4. Verify: The CLI should print "Started a new chat session. Previous session saved." The terminal history should remain visible.
  5. Chat again (e.g., "What was the number?").
  6. Verify: The bot should NOT remember "42", confirming a fresh context.
  7. Exit and run /resume.
  8. Verify: You should see the previous session listed, confirming it was saved.

@sujay-bhandari sujay-bhandari requested a review from a team as a code owner January 16, 2026 16:54
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @sujay-bhandari, 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 CLI's user experience by introducing a /new command, enabling users to initiate a fresh conversational context without losing their terminal history. Additionally, it improves the /extensions update command's error reporting, making it more user-friendly by suggesting available extensions when a requested one is not found. These changes aim to streamline interaction and provide clearer feedback within the command-line interface.

Highlights

  • New Chat Command (/new): Introduced a new command that allows users to start a fresh chat session. Unlike /clear, this command resets the chat history and session ID but retains the previous terminal output, providing a continuous view of past interactions.
  • Improved Extension Update Feedback: The /extensions update command now offers better user guidance. If a specified extension is not found, the command will log a list of currently installed extensions, or indicate if none are installed, to assist the user.
  • Comprehensive Testing: New dedicated test files have been added to ensure the correct functionality of both the new /new command and the enhanced error handling in the /extensions update command.
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

The pull request introduces a new command, /new, which allows users to start a fresh chat session. This includes resetting the chat history, generating a new session ID, and properly firing session end and start hooks. The changes also include a minor enhancement to the update command's error handling, providing more informative messages when an extension is not found. New test files have been added to ensure the correct functionality of the new command and the updated error handling. The code is well-structured and follows existing patterns within the codebase.

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Hi @sujay-bhandari thanks for the contribution! 😄

Please update the PR description above with summary and details on this change. If you can we always recommend an image or screenshot and how to properly test it so we can try it out.

Thanks! Looking forward to it.

@sujay-bhandari
Copy link
Copy Markdown
Author

Thanks @jackwotherspoon! 😄 I've updated the PR description with the full summary and testing steps as requested.

Quick summary of the changes:

  • /new command: This lets you start a fresh conversation context (new session ID) without wiping your terminal history. It's great for when you want to "restart" the bot's memory but keep your previous output visible. The old session is saved and can still be resumed later.
  • Update fix: If you try to update an extension that doesn't exist (e.g., a typo), it now helpfully lists the extensions you do have installed instead of just saying "not found."

I've added unit tests for both features. Let me know if you need anything else!

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Thanks @jackwotherspoon! 😄 I've updated the PR description with the full summary and testing steps as requested.

@sujay-bhandari i don't see the PR description updated... maybe you forget to click "Save" (i do this a lot)

Once you update we can take a proper look 😄

@jackwotherspoon jackwotherspoon changed the title Feat new command feat: add /new command for new session Jan 17, 2026
@sujay-bhandari
Copy link
Copy Markdown
Author

Thanks @jackwotherspoon! 😄 I've updated the PR description with the full summary and testing steps as requested.

@sujay-bhandari i don't see the PR description updated... maybe you forget to click "Save" (i do this a lot)

Once you update we can take a proper look 😄

All done! I've updated the description now. Thanks for the heads up! 😅

@sujay-bhandari sujay-bhandari changed the title feat: add /new command for new session feat: add /new command & list extensions on update failure Jan 17, 2026
@jackwotherspoon
Copy link
Copy Markdown
Collaborator

@sujay-bhandari it seems this pull request addresses two totally different issues...

From a PR review and engineering best practices we like to follow a separation of concerns pattern.

A PR should solve one thing and one thing only. To leave a clean history and in case we have to revert a PR in the future it makes things much cleaner.

Do you mind making this PR focus on only one of the two issues and open a separate PR addressing the second piece.

Copy link
Copy Markdown
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

Overall I really like the direction of this PR @sujay-bhandari 👏

My main feedback is the following:

The logic in newCommand.ts is nearly identical to clearCommand.ts (resetting chat, managing session ID, firing hooks, flushing telemetry).

Can we extract the common "session reset" logic into a shared helper function (maybe in packages/cli/src/utils/sessionUtils.ts or somewhere similar.

This would reduce code duplication and ensure that future changes to session lifecycle management (like telemetry flushing or hook firing) are applied consistently to both commands.

@sujay-bhandari
Copy link
Copy Markdown
Author

Thanks @jackwotherspoon! Great point.

I've refactored the code to extract the common session reset logic into a new shared helper startNewSession in packages/cli/src/utils/sessionUtils.ts.

Both /new and the existing /clear command now use this helper to ensure consistent lifecycle management (hooks, telemetry, etc.). I also verified that the tests for both commands pass.

Ready for another review! 🚀

@jackwotherspoon jackwotherspoon changed the title feat: add /new command & list extensions on update failure feat: add /new command Jan 19, 2026
Copy link
Copy Markdown
Collaborator

@jackwotherspoon jackwotherspoon left a comment

Choose a reason for hiding this comment

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

Overall, looks good to me.

I would look to add SessionStartSource.New and be mindful of license headers

/**
* @license
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
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.

license headers should remain the year the file is created, not updated. Leave this as 2025

it('should reset chat and start a new session', async () => {
await newCommand.action(mockContext, '');

// eslint-disable-next-line @typescript-eslint/no-explicit-any
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 disabling all these checks?

kind: CommandKind.BUILT_IN,
autoExecute: true,
action: async (context, _args) => {
await startNewSession(context, SessionStartSource.Clear, false);
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.

hmm it looks like here we are using SessionStartSource.Clear?

I would recommend adding a SessionStartSource.New that way hooks or logging can easily differentiate between the two..? Does that sound right to you?

  1. Modify packages/core/src/hooks/types.ts:
export enum SessionStartSource {
  Startup = 'startup',
  Resume = 'resume',
  Clear = 'clear',
  New = 'new', // Add this
}
  1. Update the PR to use SessionStartSource.Newhere

@sujay-bhandari
Copy link
Copy Markdown
Author

@jackwotherspoon
Thanks for the review! I've addressed all the feedback:

  • SessionStartSource: Added the new source to the core types and updated the command to use it.
  • License Header: Reverted the year in the existing command file back to 2025.
  • Tests: Refactored the unit tests to remove all lint disables and properly typed the mocks and assertions.

Tests are passing and ready for another look! 🚀

@gemini-cli gemini-cli Bot added area/platform Issues related to Build infra, Release mgmt, Testing, Eval infra, Capacity, Quota mgmt priority/p3 Backlog - a good idea but not currently a priority. labels Jan 19, 2026
@jacob314 jacob314 added the help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! label Jan 22, 2026
@gemini-cli
Copy link
Copy Markdown
Contributor

gemini-cli Bot commented Jan 24, 2026

Hi there! Thank you for your contribution to Gemini CLI.

To improve our contribution process and better track changes, we now require all pull requests to be associated with an existing issue, as announced in our recent discussion and as detailed in our CONTRIBUTING.md.

This pull request is being closed because it is not currently linked to an issue. You can easily reopen this PR once you have linked it to an issue.

How to link an issue:
Add a keyword followed by the issue number (e.g., Fixes #123) in the description of your pull request. For more details, see the GitHub Documentation.

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

@ved015
Copy link
Copy Markdown
Contributor

ved015 commented Feb 1, 2026

hi @sujay-bhandari

I think there is a bug in the session initialization sequence within sessionUtils.ts when i am using /new command my previous session doesnt show in resume but the new one (ie which got created after new) does I think i have figured out why this happens i am sharing my findings here

  • geminiClient.resetChat() was being called before the new session ID was generated and set in the configuration.
  • resetChat() initializes a new ChatRecordingService, which reads the current sessionId from the Config at startup. Since the ID hadn't been updated yet, the new service inherited the previous session's ID.
  • The new chat session saved to the same history file as the previous one, leading to data overwrites and the appearance of "disappearing" sessions in the /resume list.

What is your take on this

@ved015
Copy link
Copy Markdown
Contributor

ved015 commented Feb 4, 2026

hi @sujay-bhandari i think when resolving conflicts you removed your changes in sessionUtils ie startNewSession please have a look at it otherwise all the tests will fail

@ved015
Copy link
Copy Markdown
Contributor

ved015 commented Feb 9, 2026

hi @sujay-bhandari

I think there is a bug in the session initialization sequence within sessionUtils.ts when i am using /new command my previous session doesnt show in resume but the new one (ie which got created after new) does I think i have figured out why this happens i am sharing my findings here

  • geminiClient.resetChat() was being called before the new session ID was generated and set in the configuration.
  • resetChat() initializes a new ChatRecordingService, which reads the current sessionId from the Config at startup. Since the ID hadn't been updated yet, the new service inherited the previous session's ID.
  • The new chat session saved to the same history file as the previous one, leading to data overwrites and the appearance of "disappearing" sessions in the /resume list.

What is your take on this

hi @sujay-bhandari awaiting your feedback on this 😁

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

@sujay-bhandari let me know if you want to take a look at @ved015 comments above

SessionStartSource,
flushTelemetry,
} from '@google/gemini-cli-core';
import { startNewSession } from '../../utils/sessionUtils.js';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This startNewSession function got deleted from
packages/cli/src/utils/sessionUtils.ts.

You will get that function on your previous commit. Here is the link

3fb37ba#diff-c86d2d5fda4df73694149d6625c00a6be42a13efafb38e474377d4a4d105fde4R539

@mrpmohiburrahman
Copy link
Copy Markdown
Contributor

Hi @jackwotherspoon! I noticed that @sujay-bhandari hasn't been active since January 20th, and a few other PRs trying to solve this issue have been closed recently to avoid duplication.

If you give the green light, I'd love to help get this over the finish line.

Let me know how you'd prefer to proceed

@jackwotherspoon
Copy link
Copy Markdown
Collaborator

Closing due to inactivity 👍

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.

Add /new command equivalent to starting gemini cli

5 participants