Skip to content

fix(cli): use os.homedir() for home directory warning check#26410

Draft
HaleTom wants to merge 1 commit intogoogle-gemini:mainfrom
HaleTom:homedir
Draft

fix(cli): use os.homedir() for home directory warning check#26410
HaleTom wants to merge 1 commit intogoogle-gemini:mainfrom
HaleTom:homedir

Conversation

@HaleTom
Copy link
Copy Markdown

@HaleTom HaleTom commented May 3, 2026

Summary

The "running in home directory" warning was triggering incorrectly in subdirectories of home. The root cause: the warning check used the core homedir() helper, which respects the GEMINI_CLI_HOME environment variable. This is wrong because GEMINI_CLI_HOME is for configuring the config directory — it should not affect whether the user is literally in their OS home directory.

Changes

packages/cli/src/utils/userStartupWarnings.ts

  • Replace homedir() (from @google/gemini-cli-core) with os.homedir() (from node:os)
  • The warning now always compares against the real OS home directory, regardless of GEMINI_CLI_HOME

packages/cli/src/utils/userStartupWarnings.test.ts

  • Remove the homedir: () => os.homedir() mock passthrough (no longer needed)
  • Add 4 new test cases:
    • Subdirectory of home — no warning
    • Symlinked home + subdirectory — no warning
    • Symlinked home (exact match) — warning shown
    • GEMINI_CLI_HOME differs from os.homedir() — no warning

Fixes #22309

How to Validate

  1. npx vitest run packages/cli/src/utils/userStartupWarnings.test.ts — all tests pass
  2. Manual: run gemini from ~ — warning appears; from ~/some-project — no warning

Related

The home directory warning incorrectly used the core homedir() helper
which respects the GEMINI_CLI_HOME environment variable. When
GEMINI_CLI_HOME is set to a non-home directory, the warning could fire
in subdirectories or miss the actual home directory entirely.

Switch to Node's native os.homedir() so the check always compares
against the real OS home directory.

Add test coverage for subdirectories, symlinked home directories, and
GEMINI_CLI_HOME override scenarios.

Fixes google-gemini#22309
@HaleTom HaleTom requested a review from a team as a code owner May 3, 2026 16:16
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Note

Gemini is unable to generate a summary for this pull request due to the file types involved not being currently supported.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/security Issues related to security help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels May 3, 2026
@HaleTom HaleTom marked this pull request as draft May 3, 2026 16:36
@HaleTom HaleTom force-pushed the homedir branch 2 times, most recently from 46db34e to 28580cf Compare May 3, 2026 19:31
@HaleTom HaleTom changed the title Production readiness review: fix unused imports and security test coverage fix(cli): use os.homedir() for home directory warning check May 3, 2026
@gemini-cli gemini-cli Bot added the area/core Issues related to User Interface, OS Support, Core Functionality label May 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality area/security Issues related to security help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! priority/p1 Important and should be addressed in the near term.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Home Dir Warning - Even when in subfolder of home dir?

1 participant