You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
read-many-files decides whether a matched binary asset was "explicitly requested" using substring containment between the glob pattern string and the file's stem/extension — not actual pattern matching. Any overlap between a directory-name fragment in the pattern and a binary file's stem marks the asset as requested, so it gets embedded as a base64 inlineData part even though the user never asked for binaries. The two checks are also inconsistently cased (extension compare is case-insensitive, stem compare case-sensitive).
With a matched file quarterlyreport.png: stem quarterlyreport is a substring of the pattern → requestedExplicitly === true → the PNG is inlined as an image part, consuming large context and surprising the user.
Conversely, a genuine request like "assets/logo.png" fails the intent for logo.PNG on case-sensitive filesystems due to the asymmetric casing.
What did you expect to happen?
"Explicitly requested" should mean the include pattern actually matches this specific binary file (e.g., run the pattern through the same matcher used for discovery), not fuzzy string overlap.
Impact
Unexpected large binary payloads injected into model context; token bloat; potential policy surprises for users who believed they only requested text.
Suggested direction
Match the file's path against each include pattern with the project's glob engine (minimatch/glob) instead of includes(), normalizing case consistently.
Found by source audit on current main (commit 5411f113c); platform-independent. No open issue/PR covering this was found (searched: read-many-files binary explicitly requested).
I reviewed the requestedExplicitly branch in packages/core/src/tools/read-many-files.ts. At the moment it compares the raw include-pattern string with the file’s stem and extension, which explains why incidental text overlap can opt a binary file into inline content. I’d keep discovery, exclusions, and binary rendering unchanged, and replace only this intent check with an actual match of the normalized relative file path using the repository’s existing glob semantics.
In packages/core/src/tools/read-many-files.test.ts, I’d add the reported false-positive shape (**/*report*/** alongside quarterlyreport.png) and verify that the image is not treated as explicitly requested. A second case would use an actual path such as assets/logo.png and verify that explicit binary inclusion still works; I’d also follow the project’s existing expectations for path separators and case handling.
There is one semantic choice worth confirming before implementation: should “explicitly requested” mean a real glob match against the file path, or only a literal file-path include? If maintainers prefer the former, I’m happy to send the focused fix and regression tests after approval, with the targeted suite and npm run preflight completed first.
Effort Analysis:
The ReadManyFilesToolInvocation.execute method in packages/core/src/tools/read-many-files.ts incorrectly determines if a binary asset was 'explicitly requested' by using String.prototype.includes() on the glob pattern string (lines 306-310). This results in incorrect behavior where any substring overlap between the pattern and the file's stem or extension triggers a match. The fix involves replacing this includes() logic with proper glob matching against the actual file path using the project's established matching libraries (glob or picomatch, both already available in packages/core). This is a highly localized, single-file logic error with no platform dependencies or complex state management, mapping directly to the 'effort/small' guideline.
The read_file and read_many_files tools are failing to correctly handle subdirectory paths on Windows. Additionally, the CLI version (0.1.7) is significantly outdated; please verify if this issue persists in the latest version (0.59.0).
I've opened #29783 for this. It replaces the substring check with real glob matching (picomatch, already a core dependency): an asset counts as requested only when an include pattern actually matches it and the pattern's last segment names its extension or name. Note the repro in the description doesn't trigger the bug (the old check tests stem-in-pattern), so the PR uses cases that do, e.g. '/report/' inlining reports/report.png. Regression tests included; CLA is signed. Could a maintainer add help wanted?
Activity
Jokasa7 commentedon Aug 29, 2026
I reviewed the
requestedExplicitlybranch inpackages/core/src/tools/read-many-files.ts. At the moment it compares the raw include-pattern string with the file’s stem and extension, which explains why incidental text overlap can opt a binary file into inline content. I’d keep discovery, exclusions, and binary rendering unchanged, and replace only this intent check with an actual match of the normalized relative file path using the repository’s existing glob semantics.In
packages/core/src/tools/read-many-files.test.ts, I’d add the reported false-positive shape (**/*report*/**alongsidequarterlyreport.png) and verify that the image is not treated as explicitly requested. A second case would use an actual path such asassets/logo.pngand verify that explicit binary inclusion still works; I’d also follow the project’s existing expectations for path separators and case handling.There is one semantic choice worth confirming before implementation: should “explicitly requested” mean a real glob match against the file path, or only a literal file-path include? If maintainers prefer the former, I’m happy to send the focused fix and regression tests after approval, with the targeted suite and
npm run preflightcompleted first.gemini-cli commentedon Aug 29, 2026
This is a bug in the file reading tool where it incorrectly inlines binary assets. Please provide your CLI version.
gemini-cli commentedon Aug 29, 2026
Effort Analysis:
The
ReadManyFilesToolInvocation.executemethod inpackages/core/src/tools/read-many-files.tsincorrectly determines if a binary asset was 'explicitly requested' by usingString.prototype.includes()on the glob pattern string (lines 306-310). This results in incorrect behavior where any substring overlap between the pattern and the file's stem or extension triggers a match. The fix involves replacing thisincludes()logic with proper glob matching against the actual file path using the project's established matching libraries (globorpicomatch, both already available inpackages/core). This is a highly localized, single-file logic error with no platform dependencies or complex state management, mapping directly to the 'effort/small' guideline.2 remaining items
gemini-cli commentedon Sep 2, 2026
The read_file and read_many_files tools are failing to correctly handle subdirectory paths on Windows. Additionally, the CLI version (0.1.7) is significantly outdated; please verify if this issue persists in the latest version (0.59.0).
fix(core): replace fuzzy requestedExplicitly logic with glob matching…
priyanshu1976 commentedon Oct 16, 2026
I've opened #29783 for this. It replaces the substring check with real glob matching (picomatch, already a core dependency): an asset counts as requested only when an include pattern actually matches it and the pattern's last segment names its extension or name. Note the repro in the description doesn't trigger the bug (the old check tests stem-in-pattern), so the PR uses cases that do, e.g. '/report/' inlining reports/report.png. Regression tests included; CLA is signed. Could a maintainer add help wanted?
fix(core): ensure read-many-files only inlines explicitly requested b…