Repository navigation
fix(gemini): read export KEY=value lines in ~/.gemini/.env - #8862
Merged
Merged
Conversation
parse_env_file skipped `export GEMINI_API_KEY=...` because its key check saw "export GEMINI_API_KEY". Importing the live config then stored the default provider without the key, and switching back to that provider from another one removed the key that the .env writer had kept in place. Gemini CLI reads .env with dotenv, which accepts the export prefix, and CC Switch's own .env writer (live/patch/dotenv.rs) does too.
2 tasks done
farion1231
reviewed
Oct 25, 2026
farion1231
left a comment
Owner
There was a problem hiding this comment.
LGTM, thanks for your contribution!
Owner
|
Merged, thanks! Nice catch on the read/write asymmetry: the writer already kept |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 概述
parse_env_file(src-tauri/src/gemini_config.rs) skippedexport KEY=valuelines, because its key check sawexport GEMINI_API_KEY. Importing the live config then stored thedefaultGemini provider without its key, and switching back to it from another provider removed the key from~/.gemini/.env. Gemini CLI reads the file with dotenv, which accepts theexportprefix, and CC Switch's own.envwriter (live/patch/dotenv.rs) handles it too.parse_env_filestrips anexportprefix before the key check, like the writer'sparse_key.Related Issue / 关联 Issue
Fixes #8861
Testing
~/.gemini/.env=export GEMINI_API_KEY=AIza-user-key, then import, switch to a second provider and back:defaultprovider after importenv: {}env: {"GEMINI_API_KEY": "AIza-user-key"}~/.gemini/.envafter switching backexport GEMINI_API_KEY=AIza-user-keytest_parse_env_file_reads_export_lines(unit) andswitching_back_to_imported_gemini_default_keeps_an_export_line_key(integration, intests/provider_service.rs). On main the integration test fails with an empty.env.cargo test: 4248 passed.cargo fmt --checkpasses.cargo clippy --all-targetsreports nothing in the changed files (Rust 1.99.1).Checklist / 检查清单
cargo clippypasses (if Rust code changed) / 通过 Clippy 检查(如修改了 Rust 代码)pnpm typecheck,pnpm format:checkand the i18n files are not affected.