Skip to content

Restarting the terminal and running gemini asks for an api-key - Gemini CLI

Quick fix

Update cc-switch for the save-clears-config bug. If it still fails, that is a Gemini CLI read bug — put the environment variables in bash_profile.

Error output
重启终端,执行gemini,提示需要输入api-key。
English translation

Restarting the terminal and running gemini asks for an api-key.

Two causes. First, early cc-switch versions (3.13.0, for example) have a bug where saving config in Google Official mode unexpectedly clears the `.gemini/.env` file, or leaves preset template config such as usage queries unwritten. Second, the Gemini CLI itself has a bug reading `.env` files: even when cc-switch writes the config file correctly, the Gemini CLI cannot read it and asks for an api-key.

  1. Update cc-switch to the latest version, fixing both saving in Google Official mode clearing `.env` and config not being written.

  2. If it still asks for an api-key after updating, you have hit the Gemini CLI `.env` reading bug. Put the url, key, and model straight into your system `bash_profile` and restart the terminal.

    ~/.bash_profile 或 ~/.zshrc
    # 在此处直接配置 Gemini 的 url、key、model 环境变量
ToolGemini CLI
VersionUnknown
PlatformsWindowsmacOS
I checked and the config file under `.gemini` is written correctly — why does it still not apply?
A Gemini CLI bug reading `.env` files. Give up on writing through cc-switch for now and configure the environment variables in your system `bash_profile` instead.
Why do the environment variables disappear when I reopen the editor after saving in Google Official mode?
A bug in early cc-switch versions where saving unexpectedly clears the variables you set. Updating to the latest version fixes it.

This is an unofficial community wiki with no affiliation to the cc-switch authors or the project itself. Its content is compiled from the project's public GitHub issues. This site distributes no software.