gemini-cli - 💡(How to fix) Fix agent search tools scan .gemini/tmp/ by default, causing recursive session log growth [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

When the agent uses grep_search or glob in the home/parent directory of the operating system without explicit exclusions, it scans .gemini/tmp/ which contains active session .jsonl files. This creates a recursive feedback loop — the agent finds its own past output, includes it in new responses, which get appended to the same session file, causing exponential log growth.

Error Message

filled, with no warning or error surfaced to the user. The CLI appears to be working mid-task with a quota or token limit error — again with no clear indication to the

Root Cause

Additionally, because the session content is fed back into the context window on each turn, the exponential growth directly inflates token consumption. This can rapidly exhaust API quota or hit context window limits, causing the session to fail mid-task with a quota or token limit error — again with no clear indication to the user that recursive self-scraping was the root cause.

Fix Action

Fixed

RAW_BUFFERClick to expand / collapse

Summary

When the agent uses grep_search or glob in the home/parent directory of the operating system without explicit exclusions, it scans .gemini/tmp/ which contains active session .jsonl files. This creates a recursive feedback loop — the agent finds its own past output, includes it in new responses, which get appended to the same session file, causing exponential log growth.

Impact

Session files can grow to hundreds of MB or more purely from this recursive scraping, degrading CLI performance and contributing to the load time issues described in #27027.

Over time, unchecked growth can push individual session files to several gigabytes. This not only degrades performance but can cause the CLI to crash or hang entirely on the next session load — as the UI attempts to parse or preview a file that has grown beyond reasonable bounds.

The situation escalates further if the agent performs a broad search from or near the home directory. In this case, it will recurse into ~/.gemini/tmp/, find its own session output, and include it in the current response — which is then appended back to the same session file. Each tool call compounds the previous one, creating an exponential feedback loop.

In the worst case, this loop runs unchecked until the system disk is completely filled, with no warning or error surfaced to the user. The CLI appears to be working normally while silently consuming all available disk space — a critical failure mode that is difficult to diagnose after the fact.

Additionally, because the session content is fed back into the context window on each turn, the exponential growth directly inflates token consumption. This can rapidly exhaust API quota or hit context window limits, causing the session to fail mid-task with a quota or token limit error — again with no clear indication to the user that recursive self-scraping was the root cause.

Potentially related issues

This recursive feedback loop may be a contributing root cause of several reported memory spike issues where users on long-running agent sessions hit 7-9GB memory usage:

  • #26836 — 9.71GB memory usage with gemini-3.1-flash-lite on Windows
  • #26751 — 7.46GB memory spike during long-running agent session on Windows
  • #26842 — 7.55GB memory spike, same session pattern on Windows

In all cases, if the agent used grep_search or glob during the session, it may have recursively included its own growing session .jsonl file into the context window. Each tool call compounds the previous one, causing exponential token consumption and memory growth — consistent with the symptoms reported.

The Windows-specific pattern is notable: Windows Defender actively scans files in AppData (where .gemini/tmp/ resides), meaning the agent is both reading and triggering AV scans on the same files it is recursively growing — further compounding memory and I/O pressure.

If any of these reporters can confirm whether their agent used file search tools during the affected session, it would help validate this hypothesis.

Current behavior

grep_search and glob have no default exclusion for .gemini/tmp/.

Expected behavior

.gemini/tmp/ should be excluded from agent search tools by default. Users who explicitly want to search internal state can opt in via a config setting (e.g. agent.searchInternalDirs = true in .gemini/config.toml) or by passing the path explicitly as a targeted search argument.

Proposed fix

Add ~/.gemini/tmp/ to the default exclude patterns in grep_search and glob. This preserves the ability to search project-level configs while isolating active session state from the agent's search context.

To allow users to opt out of this protection, a config flag such as agent.searchInternalDirs = true in .gemini/config.toml could disable the default exclusion for advanced use cases.

Client information

CLI Version: 0.42.0 Git Commit: 68e2196d5 OS: Linux Auth Method: Signed in with Google Tier: Gemini Code Assist in Google One AI Pro

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

.gemini/tmp/ should be excluded from agent search tools by default. Users who explicitly want to search internal state can opt in via a config setting (e.g. agent.searchInternalDirs = true in .gemini/config.toml) or by passing the path explicitly as a targeted search argument.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

gemini-cli - 💡(How to fix) Fix agent search tools scan .gemini/tmp/ by default, causing recursive session log growth [1 pull requests]