Skip to content

feat(cli): add /restart slash command#25657

Open
martin-hsu-test wants to merge 1 commit intogoogle-gemini:mainfrom
martin-hsu-test:feat/restart-command-v2
Open

feat(cli): add /restart slash command#25657
martin-hsu-test wants to merge 1 commit intogoogle-gemini:mainfrom
martin-hsu-test:feat/restart-command-v2

Conversation

@martin-hsu-test
Copy link
Copy Markdown

@martin-hsu-test martin-hsu-test commented Apr 19, 2026

Summary

Adds a new /restart slash command that gracefully restarts the gemini CLI process and automatically resumes the current chat session in the new process.

Closes #16124.

Motivation

Today, when the CLI auto-updates itself in-place, users see:

ℹ Update successful! The new version will be used on your next run.
> /restart
✕ Unknown command: /restart

…and have to manually:

  1. /quit (or Ctrl+C)
  2. Re-launch gemini
  3. Run /chat resume or gemini --resume <id>

/restart collapses all three into one command.

How it works

┌──────────┐ /restart  ┌─────────────────┐ IPC      ┌──────────────┐
│ User     ├──────────▶│ AppContainer    ├─────────▶│ Parent       │
│ in chat  │           │ .restart()      │ {type:   │ watchdog     │
└──────────┘           └────────┬────────┘  restart-│ (index.ts)   │
                                │           with-   └──────┬───────┘
                            relaunchApp()    resume,       │ on next
                                │            sessionId}    │ spawn:
                                ▼                          ▼
                         exit code 199              spawn(node, [...args,
                                                          '--resume', sid])
  1. New restartCommand reads the current session ID via context.services.agentContext.config.getSessionId() and returns {type: 'restart', resumeSessionId, messages}.
  2. slashCommandProcessor dispatches the new return type to actions.restart().
  3. AppContainer.restart() sends an IPC message {type: 'restart-with-resume', sessionId} to the parent watchdog, then calls the existing relaunchApp() helper (which exits with RELAUNCH_EXIT_CODE = 199).
  4. The parent watchdog records the sessionId in pendingExtraScriptArgs and prepends ['--resume', sessionId] to the next spawn's argv. The buffer is cleared after one use.

Design rationale

IPC over env vars / marker files — Env vars only flow parent→child, and a disk marker file would add a race condition + cleanup burden. The parent watchdog already has an IPC channel for admin-settings-update, so we extend it with one more message type.

Explicit sessionId over --resume (latest) — The semantic intent of /restart is "continue this session", not "continue the most recent session". With multiple gemini instances running concurrently, "latest" could resolve to a different instance's session — that would feel like data loss. Passing the explicit ID makes the behavior deterministic.

Graceful degradation on IPC failure — If process.send is unavailable (e.g. when launched with GEMINI_CLI_NO_RELAUNCH=true for development), the restart still happens; only the resume is skipped. Users get a working restart over a stuck process.

Tests

  • restartCommand.test.ts: 2 new unit tests covering presence/absence of agentContext.config.
  • slashCommandProcessor.test.tsx: 35/35 existing tests still pass after adding restart to the actions mock.
  • BuiltinCommandLoader.test.ts: 17/17 existing tests still pass after registering restartCommand.
  • IPC contract end-to-end verified out-of-band by spawning a child that sends restart-with-resume + exits 199, and asserting the next spawn's argv contains ['--resume', sessionId].
  • Manually verified in a real TTY: previous chat history is visible after /restart and AI retains session-specific context.

Files changed (8)

File Change
packages/cli/src/ui/commands/restartCommand.ts new — command definition
packages/cli/src/ui/commands/restartCommand.test.ts new — unit tests
packages/cli/src/ui/commands/types.ts adds RestartActionReturn to the union
packages/cli/src/ui/hooks/slashCommandProcessor.ts dispatches 'restart' action
packages/cli/src/ui/hooks/slashCommandProcessor.test.tsx mock update
packages/cli/src/ui/AppContainer.tsx restart action handler
packages/cli/src/services/BuiltinCommandLoader.ts registers restartCommand
packages/cli/index.ts parent watchdog IPC handler + spawn arg injection

Net: +194 / −6 lines.

Adds a new /restart slash command that gracefully restarts the gemini
CLI process and resumes the current chat session in the new process.

Motivation: when the CLI auto-updates itself in-place, users currently
have to manually quit, re-launch, and run /chat resume to continue
their conversation. /restart performs all three steps automatically.

Implementation
--------------
1. New restartCommand returns {type: 'restart', resumeSessionId, ...}
   from its action, capturing the current session ID via
   context.services.agentContext.config.getSessionId().

2. slashCommandProcessor dispatches the new return type to a new
   actions.restart() handler.

3. AppContainer.restart() sends an IPC message to the parent watchdog
   ({type: 'restart-with-resume', sessionId}), then calls the existing
   relaunchApp() helper which exits with RELAUNCH_EXIT_CODE (199).

4. The parent watchdog in packages/cli/index.ts records the sessionId
   in pendingExtraScriptArgs and injects ['--resume', sessionId] into
   the next spawn's argv, then clears the buffer.

Design rationale
----------------
* IPC over env vars / marker files: env vars only flow parent->child,
  and marker files add a disk race + cleanup burden. The parent
  watchdog already has an IPC channel for admin-settings-update, so we
  extend it.

* Explicit sessionId vs --resume (latest): the user intent of
  /restart is 'continue THIS session', not 'continue the most recent
  session'. With multiple gemini instances running concurrently,
  'latest' could resolve to a different instance's session, which
  would feel like data loss.

* IPC failure is non-fatal: if process.send is unavailable (e.g.
  GEMINI_CLI_NO_RELAUNCH=true) the restart still happens, just without
  resume. Users get a working restart over a stuck process.

Tests
-----
* New restartCommand.test.ts: 2 unit tests covering presence and
  absence of agentContext.config.
* slashCommandProcessor.test.tsx: existing 35 tests still pass after
  adding restart to the actions mock.
* BuiltinCommandLoader.test.ts: existing 17 tests still pass after
  registering restartCommand.
* End-to-end IPC contract verified out-of-band by spawning a child
  that sends restart-with-resume + exits 199, and asserting the next
  spawn's argv contains ['--resume', sessionId].

Closes google-gemini#16124
@martin-hsu-test martin-hsu-test requested a review from a team as a code owner April 19, 2026 14:02
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the developer experience by adding a /restart command to the Gemini CLI. This feature streamlines the process of restarting the application after updates or configuration changes by automating the session resumption, effectively replacing a multi-step manual workflow with a single command.

Highlights

  • New /restart command: Introduced a new slash command that allows users to gracefully restart the CLI process while maintaining their current chat session.
  • IPC-based session resumption: Implemented an IPC mechanism between the parent watchdog and the child process to pass the current session ID, ensuring the new process automatically resumes the correct chat.
  • Deterministic session handling: The implementation uses an explicit session ID rather than a 'latest' heuristic to prevent data loss when multiple CLI instances are running.
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.

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.

@gemini-cli gemini-cli bot added priority/p2 Important but can be addressed in a future release. area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 19, 2026
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 new /restart slash command that allows users to relaunch the CLI process while automatically resuming the current session. The implementation involves adding IPC message handling in the main entry point to capture session IDs and inject them as --resume arguments into the next process spawn. The review feedback correctly identifies a property access error in the restartCommand implementation and its associated tests, where agentContext was being treated as a wrapper rather than the configuration object itself.

Comment thread packages/cli/src/ui/commands/restartCommand.ts
Comment thread packages/cli/src/ui/commands/restartCommand.test.ts
@Abdul-nazeer
Copy link
Copy Markdown

Hi, I’d like to work on the /restart slash command feature.

Proposed approach:

  • Identify current slash command handling logic in the CLI
  • Implement /restart to reset session state and context
  • Ensure proper user feedback after restart

Please let me know if this aligns or if there are any specific guidelines I should follow.

@Abdul-nazeer
Copy link
Copy Markdown

/assign

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 help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p2 Important but can be addressed in a future release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

/restart command

2 participants