Skip to content

fix(core): respect .gitignore and .geminiignore in session_context directory tree#27886

Open
KirtiRamchandani wants to merge 1 commit into
google-gemini:mainfrom
KirtiRamchandani:fix/session-context-respect-ignore-files
Open

fix(core): respect .gitignore and .geminiignore in session_context directory tree#27886
KirtiRamchandani wants to merge 1 commit into
google-gemini:mainfrom
KirtiRamchandani:fix/session-context-respect-ignore-files

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

Summary

Ensures the <session_context> directory tree honors the same ignore rules as the rest of the CLI.

Fixes #27787

Problem

getDirectoryContextString() builds the folder tree shown inside <session_context>. It calls getFolderStructure() with only fileService, but does not pass fileFilteringOptions from config.

getFolderStructure() only applies .gitignore / .geminiignore filtering when both are available:

  1. fileService.shouldIgnoreFile() / shouldIgnoreDirectory()
  2. Matching fileFilteringOptions.respectGitIgnore / respectGeminiIgnore flags

Without (2), ignored paths can still appear in the session bootstrap context — wasting tokens and potentially leaking files the user intentionally excluded.

Root cause

// Before
getFolderStructure(dir, {
  fileService: config.getFileService(),
});

Other tools (ls, glob, read-many-files, etc.) already pass config.getFileFilteringOptions(). Session context generation was the missing call site.

Fix

Pass the configured filtering options alongside the file service:

getFolderStructure(dir, {
  fileService: config.getFileService(),
  fileFilteringOptions: config.getFileFilteringOptions(),
});

This aligns session context generation with the ignore behavior used elsewhere in core.

Testing

Updated environmentContext.test.ts expectations and mocked getFileFilteringOptions().

cd packages/core && npx vitest run src/utils/environmentContext.test.ts
# 8 passed

@KirtiRamchandani KirtiRamchandani requested a review from a team as a code owner June 13, 2026 16:57
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 an issue where the session context directory tree was failing to respect user-defined ignore rules. By passing the configured file filtering options to the folder structure generation logic, the system now consistently applies .gitignore and .geminiignore settings, preventing unnecessary token usage and potential file exposure.

Highlights

  • Session Context Filtering: Updated the session context generation to correctly pass file filtering options, ensuring that .gitignore and .geminiignore rules are respected.
  • Test Coverage: Updated environment context tests to mock filtering options and verify that the folder structure generation correctly applies ignore rules.
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 the 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 counterproductive. 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.

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.

@github-actions github-actions Bot added the size/s A small PR label Jun 13, 2026
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

📊 PR Size: size/S

  • Lines changed: 16
  • Additions: +16
  • Deletions: -0
  • Files changed: 2

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

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 updates getDirectoryContextString in environmentContext.ts to pass fileFilteringOptions from the configuration to getFolderStructure. The corresponding unit tests in environmentContext.test.ts have been updated to mock getFileFilteringOptions and verify that the options are correctly passed. There are no review comments, so I have no feedback to provide.

@KirtiRamchandani

Copy link
Copy Markdown
Author

Thanks for reviewing.

This wires config.getFileFilteringOptions() into getFolderStructure() for session directory trees, matching how ls, glob, and read-many-files already honor .gitignore / .geminiignore.

Unit tests assert the options object is forwarded. Happy to add an integration test if you'd like.

Wire config.getFileFilteringOptions() into getFolderStructure() so
session_context directory listings honor .gitignore and .geminiignore.
@KirtiRamchandani KirtiRamchandani force-pushed the fix/session-context-respect-ignore-files branch from 9cd5c2f to 6b40527 Compare June 13, 2026 17:25
@gemini-cli gemini-cli Bot added priority/p2 Important but can be addressed in a future release. area/agent Issues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Quality labels Jun 13, 2026
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 priority/p2 Important but can be addressed in a future release. size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): session_context should respect .gitignore and .geminiignore

1 participant