Auto-update runs npm install -g when a Gemini CLI source checkout is run from outside the clone

Aperta Adatta ai principianti
#30,209 6 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@tanveerhkit ci sta già lavorando.

Dal 13/11/2026.

  • #30267 di @tanveerhkit — aperta
  • #30272 di @bitwizard25 — aperta
  • #30315 di @tadipavan — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
node.js, typescript
Ambito
cli, devtools

Direzione di ricerca

Inizia da packages/cli/src/utils/installationInfo.ts e dai test unitari di getInstallationInfo(); attualmente simulano la directory di lavoro come radice del progetto. Segui come il percorso di ingresso della CLI e la directory corrente determinano il tipo di installazione, poi aggiungi test per l’esecuzione di un checkout del codice sorgente da un’altra directory. Il lavoro è completato quando questo caso viene identificato come clone locale e non può attivare un aggiornamento globale di npm.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/core effort/small status/bot-triaged
What happened?

When Gemini CLI is run from a source checkout (for example node ~/gemini-cli/bundle/gemini.js, or the alias / npm link setups suggested in CONTRIBUTING.md) from any directory other than the clone itself, the CLI classifies itself as a global npm installation. With auto-update enabled (the default), it then spawns npm install -g @google/gemini-cli@<channel> in the background.

I hit this while testing. Running the source bundle from a plain folder showed Installed with npm. Attempting to automatically update now..., and the npm debug log shows it ran npm install --global @google/gemini-cli@nightly, which installed a global copy of the published nightly next to my source checkout. The checkout is detected as Running from a local git clone. Please update with "git pull". only when run from inside the clone itself.

Root cause

getInstallationInfo() in packages/cli/src/utils/installationInfo.ts treats the CLI as a local git clone only if:

isGitRepository(process.cwd()) &&
realPath.startsWith(normalizedProjectRoot) &&
!realPath.includes('/node_modules/')

projectRoot comes from config.getProjectRoot(), which returns targetDir, i.e. the directory the user runs the CLI in. So both checks depend on the current directory, not on where the CLI itself lives. When they fail, detection falls through to the default branch ("Assume global npm"), which returns npm install -g @google/gemini-cli@latest as the update command.

Minimal check: getInstallationInfo(process.cwd(), true), as the real caller passes it, with process.argv[1] set to <clone>/bundle/gemini.js:

Current directory Result
Inside the gemini-cli clone Running from a local git clone. Please update with "git pull".
A folder that is not a git repository auto-update: npm install -g @google/gemini-cli@latest
Another git repository auto-update: npm install -g @google/gemini-cli@latest

The current-directory check dates back to when auto-update was added (#4686). It likely explains #5853, which was closed after the behavior seemed to go away: whether it happens depends only on the current directory. The unit tests mock process.cwd() to return projectRoot, so they never cover running from a different directory.

What did you expect to happen?

A source checkout should always be detected as "Running from a local git clone", whatever the current directory is, and auto-update should never run npm install -g for it.

Suggested fix

Detect the clone from the CLI's own location instead of the current directory, for example !realPath.includes('/node_modules/') && isGitRepository(path.dirname(realPath)). Keeping the node_modules exclusion leaves global, local and package-manager installs unaffected. A test should cover running a checkout from another directory. With npm link, the linked checkout is currently classified the same way, so an auto-update would likely replace the link with the published package. Workaround: set "general": { "enableAutoUpdate": false }.

Client information
  • Gemini CLI built from source on current main (62bab5b23); installationInfo.ts is unchanged there
  • Node.js 20.19.6, macOS 27.2
Anything else we need to know?

I have this fix ready locally with regression tests: the new test fails on main and passes with the fix. Happy to open a PR if this is open for a community contribution.

Edited shortly after posting to correct the root cause and suggested fix: projectRoot is also the current directory, so the original suggestion (isGitRepository(projectRoot)) would not have helped.

Lingua principale
TypeScript
Stelle
109k
Fork
14.9k
Merge medio
1g 2h
PR unite (30g)
111

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google-gemini/gemini-cli

Tutte le issue di google-gemini/gemini-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.