Skip to content

Conversation

@y-okt
Copy link
Contributor

@y-okt y-okt commented Jul 30, 2025

TLDR

I implemented in #4605 the Multi-Directory Workspace Support by adding --include-directories option in command line. To follow up on that, this ticket is to add /directory command in CLI, so that even after starting up gemini-cli, we can add directories.
This feature is already discussed in #1118. Also, in the discussion with @jacob314 and @allenhutchison , we agreed to separate PRs for the sake of simplicity.
In another PR, I'm planning to work on configuration supports, suggested by this comment.

Dive Deeper

The same as TLDR.

Reviewer Test Plan

  1. pull this branch and build. Have ../test, ../test1 directories and have some random files for each.
  2. Run in gemini-cli npm run start -- --include-direcotires ../test
  3. In CLI, run /direcotry add ../test1
  4. Do the following.
スクリーンショット 2025-07-31 7 14 06 スクリーンショット 2025-07-31 7 14 17 スクリーンショット 2025-07-31 7 14 45

Testing Matrix

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

Linked issues / bugs

Partially Resolves #1118

@y-okt y-okt requested a review from a team as a code owner July 30, 2025 22:36
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 significantly enhances the multi-directory workspace support in the Gemini CLI by introducing an interactive in-session command. It allows users to dynamically manage their workspace directories, ensuring the AI model's context remains up-to-date with their project structure without needing to restart the application. This improves flexibility and user experience for multi-project workflows.

Highlights

  • New CLI Command: I've introduced a new /directory slash command (with /dir as an alias) to manage workspace directories directly within the Gemini CLI, building upon the existing --include-directories startup option.
  • Directory Management Subcommands: The /directory command includes two subcommands: add to dynamically add new directories to the workspace, and show to list all currently included directories.
  • Dynamic Environment Refresh: After successfully adding new directories via the /directory add command, the CLI now triggers an environment refresh. This ensures the Gemini model's context is immediately updated with the newly included paths, providing more relevant responses.
  • Sandbox Compatibility: The /directory add subcommand is explicitly disabled when the CLI is running in a restrictive sandbox profile. In such cases, users are guided to use the --include-directories option at startup instead, maintaining security while providing clear guidance.
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.

@y-okt
Copy link
Contributor Author

y-okt commented Jul 30, 2025

@jacob314 @allenhutchison Hi, could you please review this PR as well? This is a follow-up for #4605 , and I added "/directory" command to add context directories from the CLI as well. After this merge, I'll work on the settings.json configuration supports. Thanks!

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 valuable feature for multi-directory workspace support by adding the /directory command. The implementation is well-structured, including documentation, tests, and the core command logic. The addition of refreshEnvironment to update the chat context dynamically is a key part of this functionality.

My review identified one critical issue regarding an un-awaited asynchronous call, which could lead to race conditions. I've provided a detailed comment and a code suggestion to address this. The other changes appear to be correct and well-implemented.

@allenhutchison allenhutchison self-assigned this Jul 30, 2025
@y-okt y-okt force-pushed the feat/multi-dir-command branch 2 times, most recently from 83404e4 to ff9a49a Compare July 30, 2025 22:59
@allenhutchison
Copy link
Collaborator

allenhutchison commented Jul 30, 2025

Thank you for this contribution! The /directory command is a great feature that will significantly improve the user experience for multi-directory projects.

My review found one issue that need to be addressed before this can be merged:

  1. Missing Help Text: The subcommands for /directory (add and show) do not appear in the /help output. To fix this, you can add the subCommands property to the directoryCommand object in packages/cli/src/ui/commands/directoryCommand.tsx.

Suggested change for the help text in directoryCommand.tsx:

export const directoryCommand: SlashCommand = {
  name: 'directory',
  altNames: ['dir'],
  description: 'Manage workspace directories',
  kind: CommandKind.BUILT_IN,
  subCommands: [
    {
      name: 'add',
      description: 'Add a directory to the workspace',
    },
    {
      name: 'show',
      description: 'Show all directories in the workspace',
    },
  ],
  action: async (context: CommandContext, args: string) => {
    // ...
  },
};

Additionally, Memory Refresh Ignores New Directories: The performMemoryRefresh function is not aware of directories added via the /directory add command. When it calls loadHierarchicalGeminiMemory, it doesn't pass the updated list of workspace directories. As a result, the memory refresh only scans the original directory, and any context files in newly added directories are ignored. I think this is actually the right default behaviour, and we should think about a setting that controls it.

@y-okt y-okt force-pushed the feat/multi-dir-command branch from 6b01b43 to 3c34ba9 Compare July 31, 2025 14:03
@y-okt
Copy link
Contributor Author

y-okt commented Jul 31, 2025

Hi @allenhutchison , thank you for reviewing! I appreciate your reviews and suggestions! I added it to my PR. Could you please review again?
Also, about performMemoryRefresh, actually, I noticed that in this PR I don't need to add that. addDirectoryContext is enough to reflect the directory structures to the model. However, I agree that performMemoryRefresh is not able to reflect the directories added. In the next PR, I'm planning to work on having a configuration option in settings.json. Probably we can add the customization logic there!

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 PR. This will be a valuable addition.

@allenhutchison allenhutchison added this pull request to the merge queue Jul 31, 2025
Merged via the queue into google-gemini:main with commit f9a0540 Jul 31, 2025
14 checks passed
acoliver referenced this pull request in vybestack/llxprt-code Jul 31, 2025
thacio added a commit to thacio/auditaria that referenced this pull request Aug 1, 2025
MarkAngler pushed a commit to MarkAngler/dbx-cli that referenced this pull request Aug 4, 2025
JunYang-tes pushed a commit to JunYang-tes/gemini-cli.nvim that referenced this pull request Aug 9, 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

2 participants