From c63092f00c22ef2521a88a8419af8c33b03f4a6f Mon Sep 17 00:00:00 2001 From: kevin-ramdass Date: Fri, 13 Feb 2026 16:30:38 -0800 Subject: [PATCH 1/3] feat: introduce `includeDirectoryTree` setting to conditionally include the directory structure in the environment context. --- docs/get-started/configuration.md | 5 +++++ packages/cli/src/config/config.ts | 2 ++ packages/cli/src/config/settingsSchema.ts | 10 ++++++++++ packages/core/src/config/config.ts | 7 +++++++ .../core/src/utils/environmentContext.test.ts | 19 +++++++++++++++++++ packages/core/src/utils/environmentContext.ts | 6 ++++-- schemas/settings.schema.json | 7 +++++++ 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/docs/get-started/configuration.md b/docs/get-started/configuration.md index 5f6b89b9a2d..ba938cbed48 100644 --- a/docs/get-started/configuration.md +++ b/docs/get-started/configuration.md @@ -633,6 +633,11 @@ their corresponding top-level category object in your `settings.json` file. - **Description:** The format to use when importing memory. - **Default:** `undefined` +- **`context.includeDirectoryTree`** (boolean): + - **Description:** Whether to include the directory tree of the current + working directory in the initial request to the model. + - **Default:** `true` + - **`context.discoveryMaxDirs`** (number): - **Description:** Maximum number of directories to search for memory. - **Default:** `200` diff --git a/packages/cli/src/config/config.ts b/packages/cli/src/config/config.ts index b7b5dfc7d92..871f6ca695d 100755 --- a/packages/cli/src/config/config.ts +++ b/packages/cli/src/config/config.ts @@ -454,6 +454,7 @@ export async function loadCliConfig( } const memoryImportFormat = settings.context?.importFormat || 'tree'; + const includeDirectoryTree = settings.context?.includeDirectoryTree ?? true; const ideMode = settings.ide?.enabled ?? false; @@ -745,6 +746,7 @@ export async function loadCliConfig( embeddingModel: DEFAULT_GEMINI_EMBEDDING_MODEL, sandbox: sandboxConfig, targetDir: cwd, + includeDirectoryTree, includeDirectories, loadMemoryFromIncludeDirectories: settings.context?.loadMemoryFromIncludeDirectories || false, diff --git a/packages/cli/src/config/settingsSchema.ts b/packages/cli/src/config/settingsSchema.ts index b6b764808f9..c6fa4c80ca7 100644 --- a/packages/cli/src/config/settingsSchema.ts +++ b/packages/cli/src/config/settingsSchema.ts @@ -949,6 +949,16 @@ const SETTINGS_SCHEMA = { description: 'The format to use when importing memory.', showInDialog: false, }, + includeDirectoryTree: { + type: 'boolean', + label: 'Include Directory Tree', + category: 'Context', + requiresRestart: false, + default: true, + description: + 'Whether to include the directory tree of the current working directory in the initial request to the model.', + showInDialog: false, + }, discoveryMaxDirs: { type: 'number', label: 'Memory Discovery Max Dirs', diff --git a/packages/core/src/config/config.ts b/packages/core/src/config/config.ts index 6dfc62f3221..06b941b047b 100644 --- a/packages/core/src/config/config.ts +++ b/packages/core/src/config/config.ts @@ -436,6 +436,7 @@ export interface ConfigParameters { folderTrust?: boolean; ideMode?: boolean; loadMemoryFromIncludeDirectories?: boolean; + includeDirectoryTree?: boolean; importFormat?: 'tree' | 'flat'; discoveryMaxDirs?: number; compressionThreshold?: number; @@ -603,6 +604,7 @@ export class Config { | undefined; private readonly experimentalZedIntegration: boolean = false; private readonly loadMemoryFromIncludeDirectories: boolean = false; + private readonly includeDirectoryTree: boolean = true; private readonly importFormat: 'tree' | 'flat'; private readonly discoveryMaxDirs: number; private readonly compressionThreshold: number | undefined; @@ -786,6 +788,7 @@ export class Config { this.summarizeToolOutput = params.summarizeToolOutput; this.folderTrust = params.folderTrust ?? false; this.ideMode = params.ideMode ?? false; + this.includeDirectoryTree = params.includeDirectoryTree ?? true; this.loadMemoryFromIncludeDirectories = params.loadMemoryFromIncludeDirectories ?? false; this.importFormat = params.importFormat ?? 'tree'; @@ -1161,6 +1164,10 @@ export class Config { return this.loadMemoryFromIncludeDirectories; } + getIncludeDirectoryTree(): boolean { + return this.includeDirectoryTree; + } + getImportFormat(): 'tree' | 'flat' { return this.importFormat; } diff --git a/packages/core/src/utils/environmentContext.test.ts b/packages/core/src/utils/environmentContext.test.ts index 9872a07efb2..a43bb5fd560 100644 --- a/packages/core/src/utils/environmentContext.test.ts +++ b/packages/core/src/utils/environmentContext.test.ts @@ -88,6 +88,7 @@ describe('getEnvironmentContext', () => { getDirectories: vi.fn().mockReturnValue(['/test/dir']), }), getFileService: vi.fn(), + getIncludeDirectoryTree: vi.fn().mockReturnValue(true), getEnvironmentMemory: vi.fn().mockReturnValue('Mock Environment Memory'), getToolRegistry: vi.fn().mockReturnValue(mockToolRegistry), @@ -146,6 +147,24 @@ describe('getEnvironmentContext', () => { expect(getFolderStructure).toHaveBeenCalledTimes(2); }); + it('should omit directory structure when getIncludeDirectoryTree is false', async () => { + (vi.mocked(mockConfig.getIncludeDirectoryTree!) as Mock).mockReturnValue( + false, + ); + + const parts = await getEnvironmentContext(mockConfig as Config); + + expect(parts.length).toBe(1); + const context = parts[0].text; + + expect(context).toContain(''); + expect(context).not.toContain('Directory Structure:'); + expect(context).not.toContain('Mock Folder Structure'); + expect(context).toContain('Mock Environment Memory'); + expect(context).toContain(''); + expect(getFolderStructure).not.toHaveBeenCalled(); + }); + it('should handle read_many_files returning no content', async () => { const mockReadManyFilesTool = { build: vi.fn().mockReturnValue({ diff --git a/packages/core/src/utils/environmentContext.ts b/packages/core/src/utils/environmentContext.ts index 32ce9f09e0c..474961e9594 100644 --- a/packages/core/src/utils/environmentContext.ts +++ b/packages/core/src/utils/environmentContext.ts @@ -53,7 +53,9 @@ export async function getEnvironmentContext(config: Config): Promise { day: 'numeric', }); const platform = process.platform; - const directoryContext = await getDirectoryContextString(config); + const directoryContext = config.getIncludeDirectoryTree() + ? await getDirectoryContextString(config) + : ''; const tempDir = config.storage.getProjectTempDir(); const environmentMemory = config.getEnvironmentMemory(); @@ -63,7 +65,7 @@ This is the Gemini CLI. We are setting up the context for our chat. Today's date is ${today} (formatted according to the user's locale). My operating system is: ${platform} The project's temporary directory is: ${tempDir} -${directoryContext} +${directoryContext ? directoryContext + '\n' : ''} ${environmentMemory} `.trim(); diff --git a/schemas/settings.schema.json b/schemas/settings.schema.json index 12aec589735..ad1b4b31d03 100644 --- a/schemas/settings.schema.json +++ b/schemas/settings.schema.json @@ -1052,6 +1052,13 @@ "markdownDescription": "The format to use when importing memory.\n\n- Category: `Context`\n- Requires restart: `no`", "type": "string" }, + "includeDirectoryTree": { + "title": "Include Directory Tree", + "description": "Whether to include the directory tree of the current working directory in the initial request to the model.", + "markdownDescription": "Whether to include the directory tree of the current working directory in the initial request to the model.\n\n- Category: `Context`\n- Requires restart: `no`\n- Default: `true`", + "default": true, + "type": "boolean" + }, "discoveryMaxDirs": { "title": "Memory Discovery Max Dirs", "description": "Maximum number of directories to search for memory.", From b4be337b60562360fd7276c934ae147a67e09212 Mon Sep 17 00:00:00 2001 From: kevin-ramdass Date: Fri, 13 Feb 2026 16:30:38 -0800 Subject: [PATCH 2/3] feat: introduce `includeDirectoryTree` setting to conditionally include the directory structure in the environment context. --- packages/core/src/core/client.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/core/src/core/client.test.ts b/packages/core/src/core/client.test.ts index 185019434be..4698f2c4093 100644 --- a/packages/core/src/core/client.test.ts +++ b/packages/core/src/core/client.test.ts @@ -243,6 +243,7 @@ describe('Gemini Client (client.ts)', () => { getShowModelInfoInChat: vi.fn().mockReturnValue(false), getContinueOnFailedApiCall: vi.fn(), getProjectRoot: vi.fn().mockReturnValue('/test/project/root'), + getIncludeDirectoryTree: vi.fn().mockReturnValue(true), storage: { getProjectTempDir: vi.fn().mockReturnValue('/test/temp'), }, From f391b3b4fbd1cc29ce9dacabddb89160d2d15e23 Mon Sep 17 00:00:00 2001 From: kevin-ramdass Date: Fri, 13 Feb 2026 16:30:38 -0800 Subject: [PATCH 3/3] feat: introduce `includeDirectoryTree` setting to conditionally include the directory structure in the environment context. --- packages/core/src/utils/environmentContext.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/utils/environmentContext.ts b/packages/core/src/utils/environmentContext.ts index 474961e9594..88dd1aab68c 100644 --- a/packages/core/src/utils/environmentContext.ts +++ b/packages/core/src/utils/environmentContext.ts @@ -65,7 +65,7 @@ This is the Gemini CLI. We are setting up the context for our chat. Today's date is ${today} (formatted according to the user's locale). My operating system is: ${platform} The project's temporary directory is: ${tempDir} -${directoryContext ? directoryContext + '\n' : ''} +${directoryContext} ${environmentMemory} `.trim();