Answer: The CLI automatically loads environment variables from an `.env` file, checking the `.env` file in the current working directory first, then searching upwards in parent directories, and finally looking for `~/.env` in the user's home directory. Some variables like `DEBUG` and `DEBUG_MODE` are excluded from project `.env` files, but variables from `.gemini/.env` files are never excluded. Status: Confirmed Entry: tool/gemini-cli/settings/environment-variables-dotenv Revision: 1 Digest: sha256:80e664276a8db85e (changes whenever the content changes) Timeline: Created: 2026-11-13T03:18:46Z Last changed: 2026-11-13T03:18:46Z Last verified: 2026-11-20T12:53:27Z Next check: 2026-11-21T12:53:27Z Check interval: Daily Expected change: No fixed schedule Data: Field | Value | Source | As of loading order first location | .env | [1] | 2026-11-20 loading order second step | searches upwards in parent directories until it finds an `.env` file or reaches the project root (identified by a `.git` folder) or the home directory | [1] | 2026-11-20 loading order third location | ~/.env | [1] | 2026-11-20 excluded variables | DEBUG | [1] | 2026-11-20 never excluded file | .gemini/.env | [1] | 2026-11-20 customization setting | advanced.excludedEnvVars | [1] | 2026-11-20 Sources: [1] Google. "Gemini CLI configuration". https://geminicli.com/docs/reference/configuration.md Role: primary. Accessed: 2026-11-20T12:53:27Z Quote: "`.env` file in the current working directory." (Supports: loading order first location) Quote: "If not found, it searches upwards in parent directories until it finds an `.env` file or reaches the project root (identified by a `.git` folder) or the home directory." (Supports: loading order second step) Quote: "If still not found, it looks for `~/.env` (in the user's home directory)." (Supports: loading order third location) Quote: "Some environment variables (like `DEBUG` and `DEBUG_MODE`) are automatically excluded from being loaded from project `.env` files" (Supports: excluded variables) Quote: "Variables from `.gemini/.env` files are never excluded." (Supports: never excluded file) Quote: "You can customize this behavior using the `advanced.excludedEnvVars` setting in your `settings.json` file." (Supports: customization setting) Published: 2026-10-16T02:36:07Z Snapshot SHA-256: 4fb90004ef3e4aeb3705ceeea4ab8a0d8e0e3aa4553293a1df035990740cc9ca (captured 2026-11-13T03:18:45Z) Verification: Method: Automated extraction from [1] with deepseek-flash (JSON output, thinking disabled). Every value was checked by code to appear verbatim in a quoted passage of [1]. On this check the text of [1] was unchanged since 2026-11-13T03:18:46Z, so the values verified then were kept. Cross-check: not-available at 2026-11-20T12:53:27Z. No independent second source is configured for this entry Last successful check: 2026-11-20T12:53:27Z Last attempt: 2026-11-20T12:53:27Z Notes and limitations: Extracted automatically from a single official source (section "Environment variables and `.env` files"). Related: https://latestn.com/tool/gemini-cli/settings/export-default-system-prompt How do I export the default system prompt in Gemini CLI? https://latestn.com/tool/gemini-cli/settings/hook-environment-variables What environment variables are available to Gemini CLI hooks? https://latestn.com/tool/gemini-cli/settings/load-theme-file How do I load a custom theme from a file in Gemini CLI? https://latestn.com/tool/gemini-cli/settings/enable-notifications How do I enable notifications in Gemini CLI? https://latestn.com/tool/gemini-cli/settings/enable-plan-mode-model-steering How do I enable Plan Mode and model steering in Gemini CLI? https://latestn.com/tool/gemini-cli/settings/enable-system-prompt-override How do I enable a custom system prompt override in Gemini CLI using GEMINI_SYSTEM_MD? https://latestn.com/tool/ All entries in AI tools Change log: Time | Event | Change | Source 2026-11-13T03:18:46Z | added | Entry created | — Changes for this entry as a feed: https://latestn.com/tool/gemini-cli/settings/environment-variables-dotenv/latest Challenge this entry: Open challenges: None How: If a value here is wrong or out of date, send what is wrong and a link to evidence. Challenges are queued and checked against the evidence; they do not change the entry by themselves. If the entry changes as a result, the change log says so. Form: https://latestn.com/dispute/tool/gemini-cli/settings/environment-variables-dotenv POST: https://latestn.com/dispute/tool/gemini-cli/settings/environment-variables-dotenv with claim, evidence_url, and optionally field and contact (form-encoded or JSON) GET: https://latestn.com/dispute/tool/gemini-cli/settings/environment-variables-dotenv?claim={what is wrong}&evidence_url={link} How to cite: LatestN. (2026). How do I set environment variables for Gemini CLI using .env files? Revision 1, last verified 2026-11-20T12:53:27Z. https://latestn.com/tool/gemini-cli/settings/environment-variables-dotenv (accessed 2026-11-21T09:53:41Z). @misc{LatestN_tool_gemini_cli_settings_environment_variables_dotenv_r1, title = {How do I set environment variables for Gemini CLI using .env files?}, author = {{LatestN}}, year = {2026}, howpublished = {\url{https://latestn.com/tool/gemini-cli/settings/environment-variables-dotenv}}, note = {Revision 1; digest sha256:80e664276a8db85e; last verified 2026-11-20T12:53:27Z; accessed 2026-11-21T09:53:41Z} } Reuse: License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) Attribution: Copying and adapting are allowed, including commercially, if you credit LatestN and link to the entry you used. Each entry ends with a ready-made citation. URL: https://latestn.com/tool/gemini-cli/settings/environment-variables-dotenv