gemini-cli - 💡(How to fix) Fix Environment Leakage: .env variables from project root poison shell environment and override subprocess configurations [1 participants]

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…
GitHub stats
google-gemini/gemini-cli#25798Fetched 2026-04-23 07:45:08
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
labeled ×1

Error Message

A temporary workaround is to manually prefix every test command with environment variables (e.g., $env:DB_DATABASE="testing"; php artisan test), but this is error-prone and defeats the purpose of automatic configuration via phpunit.xml.

Fix Action

Fix / Workaround

A temporary workaround is to manually prefix every test command with environment variables (e.g., $env:DB_DATABASE="testing"; php artisan test), but this is error-prone and defeats the purpose of automatic configuration via phpunit.xml.

Code Example

> /about
 CLI Version                              0.38.2Git Commit                               b0ed611a0                                                                   │
Model                                    Auto (Gemini 3)Sandbox                                  no sandbox                                                                  │
OS                                       win32 (Windows 11)Auth Method                              Signed in with GoogleTier                                     Gemini Code Assist in Google One AI Pro
RAW_BUFFERClick to expand / collapse

What happened?

When running Gemini CLI in a Laravel project, the CLI automatically loads variables from the project's .env file into its own process environment. These variables are then exported to the shell environment.

When executing child processes like php artisan test (which uses PHPUnit/Pest), these child processes inherit the OS-level environment variables. In PHP, getenv() prioritizes these OS-level variables over variables defined in phpunit.xml. As a result, tests run against the production/local database defined in .env instead of the testing database defined in phpunit.xml. This is extremely dangerous when using traits like RefreshDatabase, as it can lead toaccidental data loss in the main database.

What did you expect to happen?

The Gemini CLI should not automatically export .env variables to the shell environment in a way that poisons child processes. Subprocesses like php artisan test should be able to use their own environment configurations (from phpunit.xml or .env.testing) without being overridden by leaked variables from the CLI's parent process.

Client information

<details> <summary>Client Information</summary>

Run gemini to enter the interactive CLI, then run the /about command.

> /about
 CLI Version                              0.38.2                                                                      │
│ Git Commit                               b0ed611a0                                                                   │
│ Model                                    Auto (Gemini 3)                                                             │
│ Sandbox                                  no sandbox                                                                  │
│ OS                                       win32 (Windows 11)                                                                       │
│ Auth Method                              Signed in with Google                               │
│ Tier                                     Gemini Code Assist in Google One AI Pro
</details>

Login information

Signed in with Google Account (Google One AI Pro tier).

Anything else we need to know?

This issue was identified while trying to run Pest tests in a Laravel 13 project on Windows. The environment leakage was confirmed by running Get-ChildItem Env: inside the Gemini CLI shell, which showed all variables from the .env file (like DB_DATABASE=stockease) already set at the OS level.

A temporary workaround is to manually prefix every test command with environment variables (e.g., $env:DB_DATABASE="testing"; php artisan test), but this is error-prone and defeats the purpose of automatic configuration via phpunit.xml.

extent analysis

TL;DR

The Gemini CLI's automatic loading of .env variables into its process environment is causing child processes like php artisan test to inherit these variables, overriding their own environment configurations.

Guidance

  • Verify that the issue is specific to the Gemini CLI by checking if the problem persists when running tests outside of the CLI.
  • Investigate the Gemini CLI's documentation or configuration options to see if there's a way to disable or customize the automatic loading of .env variables.
  • Consider using a separate .env file for testing purposes, such as .env.testing, and configure your test commands to use this file instead of the default .env file.
  • Look into modifying the phpunit.xml file to use a different environment variable prefix or to override the inherited variables.

Example

No code snippet is provided as the issue is more related to configuration and environment variable management.

Notes

The issue seems to be specific to the Gemini CLI and its interaction with child processes. The provided workaround of prefixing test commands with environment variables is error-prone and not a long-term solution.

Recommendation

Apply a workaround, such as using a separate .env file for testing purposes or modifying the phpunit.xml file, as the root cause of the issue is related to the Gemini CLI's behavior and not a straightforward code fix.

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…

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 Environment Leakage: .env variables from project root poison shell environment and override subprocess configurations [1 participants]