cc-switch keeps saying there is an environment variable conflict and then deletes the variable Gemini CLI
Quick fix
Ignore the environment variable conflict prompt to keep your system variables, or upgrade cc-switch to v3.12.3 to fix saving in Official mode.
Symptom
Section titled “Symptom”写入环境变量后,cc-switch老是说环境变量冲突,然后就把这个环境变量删除了After writing the environment variable, cc-switch keeps saying there is an environment variable conflict and then deletes the variable
These two problems involve different mechanisms in how cc-switch handles Gemini CLI environment variables. First, cc-switch writes configuration entries into ~/.gemini/.env; if a variable of the same name already exists among the system environment variables (in ~/.zshrc, for instance), cc-switch reports a conflict and tries to delete it, because system environment variables take priority. Second, before v3.10.3, environment variables in Gemini Official mode could not be written into ~/.gemini/.env correctly; that was fixed in v3.10.3, but v3.13.0 introduced a new defect where clicking save empties the .env contents.
If cc-switch reports an environment variable conflict and you want to keep the system-level environment variable (the configuration in ~/.zshrc, for instance), ignore the prompt and do not let it delete anything.
For the UI settings not applying in Gemini Official mode, upgrade cc-switch to v3.12.3.
If you hit clicking save emptying the environment variables in v3.13.0, bypass the UI and edit the config file by hand to add the variables you need.
~/.gemini/.env GEMINI_API_KEY="你的API_KEY"GOOGLE_CLOUD_PROJECT="你的项目ID"
Affected Versions
Section titled “Affected Versions”Source Issues
Section titled “Source Issues”This page is distilled from 2 real issues
- Why does cc-switch delete the GEMINI_API_KEY in my ~/.zshrc?
- Because CC Switch writes configuration entries into a config file, which a higher-priority environment variable overrides. If you do not want the environment variable deleted, just ignore the prompt.
- Is .env configuration unusable in Gemini Official mode?
- It is not unusable. v3.10.3 fixed the environment variable write logic in Official mode, and it now writes ~/.gemini/.env correctly. If you hit a problem, make sure you are on v3.12.3 or edit the file by hand.
Related problems
Section titled “Related problems”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.