Skip to content

feat(config): add setting to make directory tree context configurable#19053

Open
kevin-ramdass wants to merge 3 commits intomainfrom
kevin-ramdass/dir
Open

feat(config): add setting to make directory tree context configurable#19053
kevin-ramdass wants to merge 3 commits intomainfrom
kevin-ramdass/dir

Conversation

@kevin-ramdass
Copy link
Contributor

Summary

Adds a new advanced setting context.includeDirectoryTree to control whether the workspace directory tree is included in the initial session context sent to the model. This allows users with very large workspaces or specific context window concerns to opt out of sending the full directory structure by default.

Details

  • Added the includeDirectoryTree boolean setting (default: true) to settingsSchema.ts under the context category.
  • Set showInDialog: false so it acts as an advanced configuration and does not clutter the settings UI.
  • Plumbed the setting through loadCliConfig in the cli package down to the Config class in the core package.
  • Updated the getEnvironmentContext utility to conditionally omit the directory structure and workspace list when the flag is set to false.
  • Added unit test coverage in environmentContext.test.ts to verify the exclusion logic.
  • Generated the updated settings.md documentation.

Related Issues

Related to #15328

How to Validate

  1. Run the test suite: npm run test
  2. Add the following to your ~/.gemini/settings.json:
    "context": {
      "includeDirectoryTree": false
    }
  3. Run npm run start in the workspace.
  4. Run /chat debug to dump the current session's initial context request.
  5. Inspect the generated gcli-request-*.json file.
  6. Verify that the <session_context> block no longer contains the - Workspace Directories: and - Directory Structure: sections.

…de the directory structure in the environment context.
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @kevin-ramdass, 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 introduces a new configuration option that allows users to control the inclusion of the workspace directory tree in the initial context provided to the model. This enhancement addresses concerns related to context window limitations for large workspaces by providing an opt-out mechanism for sending the full directory structure, thereby improving flexibility and resource management for users.

Highlights

  • New Configuration Setting: Introduced a new advanced setting, context.includeDirectoryTree, which is a boolean that defaults to true. This setting controls whether the workspace directory tree is included in the initial session context sent to the model.
  • Conditional Directory Tree Inclusion: The getEnvironmentContext utility was updated to conditionally omit the directory structure and workspace list from the session context when context.includeDirectoryTree is set to false.
  • Configuration Plumbing: The new setting has been plumbed through the CLI's configuration loading (loadCliConfig) down to the core Config class, ensuring it is accessible and respected throughout the application.
  • Test Coverage and Documentation: Unit tests were added in environmentContext.test.ts to verify the exclusion logic, and the settings.md documentation was updated to reflect the new setting.
Changelog
  • docs/get-started/configuration.md
    • Added documentation for the new context.includeDirectoryTree setting.
  • packages/cli/src/config/config.ts
    • Extracted the includeDirectoryTree setting from the loaded configuration.
    • Passed the includeDirectoryTree value to the core Config class during initialization.
  • packages/cli/src/config/settingsSchema.ts
    • Defined the includeDirectoryTree property within the context category of the settings schema, setting its type to boolean and default to true, and marking it as an advanced setting (showInDialog: false).
  • packages/core/src/config/config.ts
    • Added includeDirectoryTree as an optional boolean property to the ConfigParameters interface.
    • Declared a private includeDirectoryTree property in the Config class, defaulting to true.
    • Initialized the includeDirectoryTree property in the Config constructor using the provided parameter or its default.
    • Implemented a getIncludeDirectoryTree() getter method to access the setting's value.
  • packages/core/src/utils/environmentContext.test.ts
    • Updated the mock configuration to include a mock for getIncludeDirectoryTree.
    • Added a new test case to verify that the directory structure is correctly omitted from the environment context when getIncludeDirectoryTree returns false.
  • packages/core/src/utils/environmentContext.ts
    • Modified the getEnvironmentContext function to conditionally retrieve the directory context string based on the config.getIncludeDirectoryTree() setting.
    • Adjusted the session context template to include the directory context only if it's present, ensuring proper formatting with a newline.
  • schemas/settings.schema.json
    • Added the includeDirectoryTree property to the JSON schema for settings, including its title, description, markdown description, default value, and type.
Activity
  • No human activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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.

@gemini-cli
Copy link
Contributor

gemini-cli bot commented Feb 14, 2026

Hi @kevin-ramdass, thank you so much for your contribution to Gemini CLI! We really appreciate the time and effort you've put into this.

We're making some updates to our contribution process to improve how we track and review changes. Please take a moment to review our recent discussion post: Improving Our Contribution Process & Introducing New Guidelines.

Key Update: Starting January 26, 2026, the Gemini CLI project will require all pull requests to be associated with an existing issue. Any pull requests not linked to an issue by that date will be automatically closed.

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

@github-actions
Copy link

github-actions bot commented Feb 14, 2026

Size Change: +685 B (0%)

Total Size: 24.4 MB

ℹ️ View Unchanged
Filename Size Change
./bundle/gemini.js 24.4 MB +685 B (0%)
./bundle/sandbox-macos-permissive-open.sb 890 B 0 B
./bundle/sandbox-macos-permissive-proxied.sb 1.31 kB 0 B
./bundle/sandbox-macos-restrictive-open.sb 3.36 kB 0 B
./bundle/sandbox-macos-restrictive-proxied.sb 3.56 kB 0 B
./bundle/sandbox-macos-strict-open.sb 4.82 kB 0 B
./bundle/sandbox-macos-strict-proxied.sb 5.02 kB 0 B

compressed-size-action

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 new setting, context.includeDirectoryTree, allowing users to exclude the directory tree from the initial context. While the implementation is solid, a critical prompt injection vulnerability was identified: workspace information (file and directory names) is embedded into the LLM prompt without sanitization, which could be exploited by a malicious workspace to manipulate the model's behavior. Additionally, a minor formatting issue in the prompt construction adds an extra newline.

My operating system is: ${platform}
The project's temporary directory is: ${tempDir}
${directoryContext}
${directoryContext ? directoryContext + '\n' : ''}
Copy link
Contributor

Choose a reason for hiding this comment

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

security-high high

The directoryContext variable is directly embedded into the LLM prompt within a <session_context> block without sanitization, making it vulnerable to prompt injection. An attacker could create a file or directory with a name containing the </session_context> closing tag followed by malicious instructions, potentially leading to unauthorized tool execution. Remediation: Sanitize directoryContext by escaping or removing any occurrences of the </session_context> tag before embedding it. Additionally, this line introduces an extra newline in the session context, which could subtly affect model behavior.

Suggested change
${directoryContext ? directoryContext + '\n' : ''}
${directoryContext ? directoryContext.replace(/<\/session_context>/g, '') + '\n' : ''}

@gemini-cli gemini-cli bot added area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item. labels Feb 14, 2026
…de the directory structure in the environment context.
…de the directory structure in the environment context.
@kevin-ramdass kevin-ramdass marked this pull request as ready for review February 14, 2026 01:23
@kevin-ramdass kevin-ramdass requested review from a team as code owners February 14, 2026 01:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality 🔒 maintainer only ⛔ Do not contribute. Internal roadmap item.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant