gemini-cli - 💡(How to fix) Fix [BUG]: Environment Leakage: .env variables from project root poison shell environment and override subprocess configurations [1 comments, 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#26098Fetched 2026-04-29 06:36:06
View on GitHub
Comments
1
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
commented ×1labeled ×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.39.1Git Commit                                 4d73f3413                                                                         │
Model                                      Auto (Gemini 3)Sandbox                                    no sandbox                                                                        │
OS                                         win32                                                                             │
Auth Method                                Signed in with GoogleTier                                       Gemini Code Assist in Google One AI ProIDE Client                                 IDE
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.39.1                                                                            │
│ Git Commit                                 4d73f3413                                                                         │
│ Model                                      Auto (Gemini 3)                                                                   │
│ Sandbox                                    no sandbox                                                                        │
│ OS                                         win32                                                                             │
│ Auth Method                                Signed in with Google                                      │
│ Tier                                       Gemini Code Assist in Google One AI Pro                                           │
│ IDE Client                                 IDE
</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 indeed caused by the Gemini CLI's environment variable export by checking the output of Get-ChildItem Env: inside the Gemini CLI shell.
  • Consider using a temporary workaround by prefixing test commands with environment variables, such as $env:DB_DATABASE="testing"; php artisan test, although this is error-prone.
  • Investigate the Gemini CLI's configuration options to see if there's a way to disable or customize the automatic loading of .env variables.
  • Review the phpunit.xml configuration to ensure that it's correctly set up to use the testing database.

Example

No code snippet is provided as it's not clearly supported by the issue, but an example of the temporary workaround is given in the issue: $env:DB_DATABASE="testing"; php artisan test.

Notes

The issue seems to be specific to the Gemini CLI's behavior on Windows, and the provided workaround may not be suitable for all use cases. Further investigation into the Gemini CLI's configuration and the phpunit.xml setup is necessary to find a more permanent solution.

Recommendation

Apply workaround: Use the temporary workaround of prefixing test commands with environment variables, such as $env:DB_DATABASE="testing"; php artisan test, until a more permanent solution is found. This is because the root cause of the issue is the Gemini CLI's automatic loading of .env variables, and disabling or customizing this behavior may require changes to the CLI's configuration or code.

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