Skip to content

Conversation

@korade-krushna
Copy link
Contributor

Summary

This PR fixes issue #17409 where directories added via /dir add did not persist across sessions when using the --resume flag. It ensures that any directories added to the workspace during a session are serialized to the session JSON file and automatically restored upon resumption.

Details

The fix involves the following changes:

  • State Persistence: Added a directories field to the ConversationRecord interface in packages/core/src/services/chatRecordingService.ts and a corresponding recordDirectories method to save the current workspace state.
  • Persistence Trigger: Updated the /dir add command in packages/cli/src/ui/commands/directoryCommand.tsx to persist the updated directory list to the session file immediately after a successful addition.
  • Restoration Logic: Modified the useSessionResume hook in packages/cli/src/ui/hooks/useSessionResume.ts to read the saved directories from the session data and re-add them to the WorkspaceContext whenever a session is resumed.

Related Issues

Closes #17409

How to Validate

  1. Start a new session: npm run start
  2. Add a directory to the workspace: /dir add ./some-local-folder
  3. Verify it's added: /dir show
  4. Exit the session: /exit or Ctrl+C
  5. Resume the session: npm run start -- --resume
  6. Verify the directory is automatically restored: /dir show
  7. Run unit tests to ensure no regressions:
    • npm test -w @google/gemini-cli-core -- src/services/chatRecordingService.test.ts
    • npm test -w @google/gemini-cli -- src/ui/hooks/useSessionResume.test.ts
    • npm test

Video

Screen.Recording.2026-01-25.at.12.31.51.AM.mov

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

@korade-krushna korade-krushna requested a review from a team as a code owner January 24, 2026 19:07
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @korade-krushna, 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 addresses a critical issue where workspace directories added during a session were not preserved when resuming that session. The changes ensure that any directories added by the user are now correctly saved and automatically restored, providing a more consistent and reliable user experience across sessions.

Highlights

  • State Persistence: Introduced a 'directories' field to the ConversationRecord interface and a 'recordDirectories' method in the chat recording service to save the current workspace state.
  • Persistence Trigger: Modified the '/dir add' command to immediately persist the updated directory list to the session file after a successful addition.
  • Restoration Logic: Updated the 'useSessionResume' hook to read saved directories from session data and re-add them to the WorkspaceContext upon session resumption.
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.

@korade-krushna korade-krushna changed the title fix: persist and restore workspace directories on session resume (#17409) fix: persist and restore workspace directories on session resume Jan 24, 2026
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 effectively addresses the issue of persisting and restoring workspace directories across sessions. The user experience during session restoration could be improved by notifying the user if any directories from the previous session could not be restored, preventing silent failures and confusion. The initial high-severity security concern was re-evaluated and deemed not applicable, as paths originating from a local user's session file are considered user-provided in a CLI context.

@gemini-cli gemini-cli bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Jan 24, 2026
@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 Jan 26, 2026
@jacob314 jacob314 self-requested a review January 26, 2026 17:48
@jacob314
Copy link
Contributor

I have reviewed PR 17454. The intent to persist and restore workspace directories added via /dir add across sessions is well-implemented and addresses the issue correctly. The implementation of recordDirectories in ChatRecordingService and its invocation in directoryCommand.tsx follows the project's service and command patterns.

Regarding the tests and React logic, I have one piece of feedback (manual review from /review-frontend by Jacob Richman):

  1. In packages/cli/src/ui/hooks/useSessionResume.test.ts, please replace vi.clearAllMocks() in beforeEach with vi.restoreAllMocks() in an afterEach block. This ensures better test isolation and adheres to our project's testing standards.

I have also flagged this change to anj-s as the automatic restoration of directory context impacts the initial prompt history, which may affect model response quality.

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

One tricky edge case we might want to handle in the future is when the only thing in the chat history is
/dir add
I would have expected resume to still work in that case but it doesn't work unless I also happened to have added a prompt to the chat history.

@korade-krushna
Copy link
Contributor Author

Sure @jacob314 created a issue for the same
#17677

@jacob314 jacob314 enabled auto-merge January 27, 2026 17:36
auto-merge was automatically disabled January 27, 2026 18:12

Head branch was pushed to by a user without write access

@korade-krushna
Copy link
Contributor Author

@jacob314 all the failed CI checks are addressed and fixed now

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! 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Directories added with /dir add do not persist across session when using --resume

2 participants