Skip to content

Conversation

@y-okt
Copy link
Contributor

@y-okt y-okt commented Aug 1, 2025

TLDR

In #4605 and #5241, I implemented the Multi-Directory Workspace support. These can:

  • allow --include-directories option, which can include directories when starting up the gemini-cli
  • allow /directory command, which can add/show the directory from CLI

In this PR, inspired by comments from @allenhutchison, implemented includeDirectories and clearWorkspaceDirsOnRefresh fields in settings.json.

  • includeDirectories (default: null) can add directories from the very beginning of gemini-cli launching.
  • loadMemoryFromIncludeDirectories (default: false) can load the GEMINI.md file when "/dir add" or the memory is refreshed.

This is the final PR for the multi-directory support.

Dive Deeper

The same as TLDR.

Reviewer Test Plan

  • create ../test, ../test1, ../test2, ../test3
  • pull this branch, build
  • in ~/.gemini/settings.json, add "<path_to_test1>/test1" in "includeDirectories" field
  • in /.gemini/settings.json, add "<path_to_test2>/test2" in "includeDirectories" field
  • npm run start -- --include-directories ../test
  • run /dir show
  • input "remember very clearly that his name is John"
  • see /dir (you need to see this with/without loadMemoryFromIncludeDirectories field enabled in settings.json)
project dir's settings.json

スクリーンショット 2025-08-01 22 56 23

home dir's settings.json

スクリーンショット 2025-08-01 22 56 28

Verifying that directories are successfully added from settings.json

スクリーンショット 2025-08-01 22 56 39

Without loadMemoryFromIncludeDirectories

スクリーンショット 2025-08-02 13 06 30 スクリーンショット 2025-08-02 13 06 43

With loadMemoryFromIncludeDirectories

スクリーンショット 2025-08-02 13 01 43 スクリーンショット 2025-08-02 13 02 00

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Resolves #1118

@y-okt y-okt requested a review from a team as a code owner August 1, 2025 14:32
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.

Summary of Changes

Hello @y-okt, 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 completes the multi-directory workspace support by introducing persistent configuration options via settings.json. It allows users to define includeDirectories that are loaded automatically on startup and provides a clearWorkspaceDirsOnRefresh setting to control how workspace directories behave during memory refreshes.

Highlights

  • Persistent Directory Inclusion: Introduced includeDirectories in settings.json to allow users to specify directories that should always be included in the workspace context upon gemini-cli startup.
  • Workspace Directory Refresh Control: Added clearWorkspaceDirsOnRefresh to settings.json, which, when set to true, will clear any dynamically added workspace directories (those not specified in settings.json) during a memory refresh operation.
  • Robust Path Resolution: Implemented a new resolvePath utility to correctly handle and expand common path notations like ~ (home directory) and %userprofile% within includeDirectories specified in settings.json.
  • CLI Argument Integration: Ensured that includeDirectories specified in settings.json are properly combined with those provided via the --include-directories command-line argument, providing a unified set of initial workspace directories.
  • Enhanced Test Coverage: Added comprehensive unit tests to validate the correct merging and resolution of includeDirectories from various configuration scopes (system, user, workspace) and command-line arguments.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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 or fill out our survey to provide feedback.

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 completes the multi-directory workspace support by adding configuration options in settings.json for includeDirectories and clearWorkspaceDirsOnRefresh. The changes are well-structured, introducing a new resolvePath utility and updating configuration loading across the CLI and core packages.

My review has identified a critical issue where directories provided via CLI arguments are lost during a memory refresh, as well as a bug in path resolution for tilde (~) prefixed paths. I've also included a minor suggestion to improve type safety in the new setDirectories method. Addressing these points will ensure the new features are robust and behave as expected.

@y-okt
Copy link
Contributor Author

y-okt commented Aug 1, 2025

@allenhutchison @jacob314 Hi, could you please reivew this PR to add configurations for multi-directory workspace support? This is the final PR for this multi-directory workspace feature, described in #1118. Thanks!

@allenhutchison allenhutchison self-assigned this Aug 1, 2025
@y-okt y-okt force-pushed the feat/multi-dir-config branch from 75ec800 to ed9bd21 Compare August 1, 2025 16:26
@allenhutchison
Copy link
Collaborator

Thank you for this excellent contribution! The multi-directory support is a powerful feature, and the implementation is very clean.

I have one suggestion for improvement regarding the new settings.

While the clearWorkspaceDirsOnRefresh setting makes sense, I believe a more useful feature for users would be to control whether GEMINI.md memory files are loaded from these additional directories. This would give users more fine-grained control over the context that gets loaded, especially when including shared libraries or other projects that might have their own GEMINI.md files.

Could we replace clearWorkspaceDirsOnRefresh with a new boolean setting called loadMemoryFromIncludeDirectories?

Suggested Change:

  1. Remove the clearWorkspaceDirsOnRefresh setting and its related logic from config.ts, settings.ts, and App.tsx.
  2. Add a new loadMemoryFromIncludeDirectories boolean setting to settings.ts and config.ts, with a default value of false.
  3. Update the memory discovery logic (likely in packages/core/src/utils/memoryDiscovery.ts) to check for this new flag.
    • If false, GEMINI.md files should only be loaded from the primary working directory.
    • If true, GEMINI.md files should be loaded from all directories in the WorkspaceContext.

This change would make the multi-directory feature even more flexible and prevent unexpected context from being loaded.

What are your thoughts on this suggestion? I'm happy to discuss it further.

@allenhutchison allenhutchison self-requested a review August 1, 2025 21:46
@y-okt y-okt force-pushed the feat/multi-dir-config branch 2 times, most recently from f453bd9 to f73ba69 Compare August 2, 2025 04:02
@y-okt
Copy link
Contributor Author

y-okt commented Aug 2, 2025

@allenhutchison Hi, thank you very much for reviewing!
I agree with you, thank you for your suggestion. Controlling the behavior of GEMINI.md should be a great feature.
Based on your feedback, I changed some code. Could you please review again? I updated the PR description as well. Thanks!

Copy link
Collaborator

@allenhutchison allenhutchison left a comment

Choose a reason for hiding this comment

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

Great work on this, @y-okt! The implementation for multi-directory support is very clean and a fantastic addition to the CLI. Thank you for being so receptive to the feedback.

We're almost ready to approve the pull request. It looks like there might be a few merge conflicts to resolve with the main branch, but once that's sorted, this will be ready to go. This is an excellent contribution

@y-okt y-okt force-pushed the feat/multi-dir-config branch from 80a4ffa to f6a322f Compare August 4, 2025 23:12
@y-okt
Copy link
Contributor Author

y-okt commented Aug 4, 2025

@allenhutchison Thank you for reviewing! I've just resolved merge conflicts. Could you please check?

@y-okt y-okt requested a review from allenhutchison August 4, 2025 23:16
Copy link
Collaborator

@allenhutchison allenhutchison left a comment

Choose a reason for hiding this comment

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

This is great. Thank you for all of your hard work.

@allenhutchison allenhutchison added this pull request to the merge queue Aug 5, 2025
Merged via the queue into google-gemini:main with commit 5c8268b Aug 5, 2025
14 checks passed
acoliver referenced this pull request in vybestack/llxprt-code Aug 5, 2025
@y-okt
Copy link
Contributor Author

y-okt commented Aug 5, 2025

@allenhutchison Thank you very much for your reviews and approvals! I really enjoyed contributing to this issue!

thacio added a commit to thacio/auditaria that referenced this pull request Aug 5, 2025
agmsb pushed a commit to agmsb/gemini-cli that referenced this pull request Aug 6, 2025
// Handle comma-separated values
dirs.flatMap((dir) => dir.split(',').map((d) => d.trim())),
})
.option('load-memory-from-include-directories', {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@y-okt would you mind doing a follow up to drop this from command line args (only rely on settings)? We've been trying to reduce the number of command line surface area we have

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NTaylorMullen Hi, understood, let me work on this!

JunYang-tes pushed a commit to JunYang-tes/gemini-cli.nvim that referenced this pull request Aug 9, 2025
JeongJaeSoon pushed a commit to JeongJaeSoon/gemini-cli that referenced this pull request Aug 21, 2025
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 2025
reconsumeralization pushed a commit to reconsumeralization/gemini-cli that referenced this pull request Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhancement: Multi-Directory Workspace Support

3 participants