Skip to content

docs(auth): clarify env-file discovery & recommend#2402

Merged
allenhutchison merged 2 commits into
google-gemini:mainfrom
jarvisphere:issue-2262
Jul 1, 2025
Merged

docs(auth): clarify env-file discovery & recommend#2402
allenhutchison merged 2 commits into
google-gemini:mainfrom
jarvisphere:issue-2262

Conversation

@jarvisphere

Copy link
Copy Markdown
Contributor

TLDR

  • Add introductory sentence explaining preferred .gemini/.env location (project or home dir) and note that plain .env also works
  • Streamline search-order explanation, keeping “first file wins” warning

Dive Deeper

Reviewer Test Plan

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes: #2262

@umairidris

Copy link
Copy Markdown
Contributor

/gemini summary

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request significantly improves the documentation for the Gemini CLI's authentication process by clarifying how environment variables are discovered and loaded from .env files. The changes aim to provide users with a clearer understanding of configuration management and recommend best practices for organizing their environment settings.

Highlights

  • Documentation Clarity: Added a new, dedicated section to the authentication.md document that thoroughly explains the .env file discovery mechanism, including the search order and precedence rules for environment variables.
  • Recommended Practice: Introduced a recommendation for using .gemini/.env files to better isolate Gemini-specific environment variables, while also clarifying that plain .env files are still supported.
  • Improved Navigation: Updated existing mentions of .env files throughout the authentication guide to link directly to the new, comprehensive section for easier reference and a streamlined user experience.
Changelog
  • docs/cli/authentication.md
    • Added a new section titled 'Persisting Environment Variables with .env Files' that details the search order (current directory upwards, then home directory) and precedence rules for .env files.
    • Introduced a recommendation to use .gemini/.env for better isolation of Gemini-specific variables.
    • Updated existing references to .env files (lines 22, 36, 57, 71) to be internal links to the newly added section for improved navigation.
    • Included practical examples for setting up both project-specific and user-wide .env configurations.
Activity
  • No human activity to report yet.

@umairidris

Copy link
Copy Markdown
Contributor

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request clarifies the environment variable discovery process. However, the documentation should explicitly state the precedence between .gemini/.env and .env when both exist in the same directory, and clarify whether the search for .env files stops at the project root or continues to the system root.


### Persisting Environment Variables with `.env` Files

You can create a **`.gemini/.env`** file in your project directory or in your home directory. Creating a plain **`.env`** file also works, but `.gemini/.env` is recommended to keep Gemini variables isolated from other tools.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

It's recommended to use .gemini/.env to avoid conflicts with other tools. However, the documentation doesn't explicitly state what happens if both .gemini/.env and .env exist in the same directory. Clarify the precedence in this scenario to prevent confusion. This is especially important since the warning states that variables are not merged across multiple files.

Comment thread docs/cli/authentication.md Outdated
Comment on lines +84 to +89
1. Starting in the **current directory** and moving upward toward `/`, for each directory it checks:
1. `.gemini/.env`
2. `.env`
2. If no file is found, it falls back to your **home directory**:
* `~/.gemini/.env`
* `~/.env`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The documentation states that the CLI searches upwards towards /. It should be clarified whether this search stops at the project root (e.g., identified by a .git directory) or continues all the way to the system root. This behavior should be explicitly documented to avoid unexpected behavior.

@allenhutchison allenhutchison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution. This looks like a valuable addition to our docs. Can you please run npm run preflight to fix the lint issues and then ping me to review again?

@allenhutchison allenhutchison self-assigned this Jun 29, 2025
@jarvisphere

Copy link
Copy Markdown
Contributor Author

@allenhutchison fixed the lint issues, please take a look again.

@allenhutchison allenhutchison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great thank you for your contribution.

@allenhutchison
allenhutchison added this pull request to the merge queue Jul 1, 2025
Merged via the queue into google-gemini:main with commit 1a30b96 Jul 1, 2025
4 checks passed
involvex pushed a commit to involvex/gemini-cli that referenced this pull request Sep 11, 2025
@sripasg sripasg added the size/s A small PR label Jun 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s A small PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GOOGLE_CLOUD_PROJECT env var

4 participants