ISSUE DESCRIPTION gemini-cli: support Login with Google (oauth-personal), mirroring…
- User
ISSUE DESCRIPTION
gemini-cli: support Login with Google (oauth-personal), mirroring codex auth.json The
codexagent injects a cached OAuth credential (~/.codex/auth.json) so runs can use a login instead of an API key (CODEX_AUTH_JSON_PATH/CODEX_FORCE_AUTH_JSON), andclaude-codeacceptsCLAUDE_CODE_OAUTH_TOKEN(#173).gemini-clihas no equivalent — it only wiresGEMINI_API_KEY/ Vertex env, so users with a "Login with Google" session (~/.gemini/oauth_creds.json) must keep a separate API key for runs.Proposal: add the same opt-in OAuth-credential injection to the
gemini-cliagent, mirroring the codex pattern —GEMINI_OAUTH_CREDS_PATH/GEMINI_FORCE_OAUTH, default behavior unchanged (fully backward-compatible).I have a working implementation that mirrors the codex auth flow (
_resolve_oauth_creds_path→ upload → chown →~/.gemini) with tests ported 1:1 fromtest_codex_auth.py, verified end-to-end (gemini-cli --ae GEMINI_FORCE_OAUTH=truecompleted hello-world, reward 1.0). Happy to open the PR or hand it off — whichever you prefer.Interface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Assistant
Now let's look at the gemini_cli.py agent and test files.
Assistant
Now let's look at the test_codex_auth.py file to understand test patterns.
Assistant
Now I have enough context. Let's implement the OAuth creds injection in gemini_cli.py, mirroring the codex pattern.
Assistant
Now let's implement the changes in gemini_cli.py.
Assistant
Update imports first:
Assistant
Now add the
_REMOTE_GEMINI_SECRETS_DIRclass attribute and_resolve_oauth_creds_pathmethod:Assistant
Now add
_resolve_oauth_creds_pathmethod right before_build_settings_commandor nearrun. Let's insert beforerunmethod.Assistant
Now let's update the
run()method to wire in the OAuth creds upload.Assistant
Now let's add cleanup of the secrets dir in the
finallyblock:Assistant
Let's view the full diff to double check correctness:
Assistant
Now let's create test file mirroring
test_codex_auth.pyfor gemini-cli, to verify the implementation. First let's checkconftest.pyfortemp_dirfixture.Assistant
Let's write a temporary reproduce/test script (not part of the official tests) to verify behavior, mirroring test_codex_auth patterns, then run it via pytest to make sure it works, then delete it.
Assistant
All 16 tests pass. Now let's run the existing test suites to ensure nothing broke.
Assistant
All existing tests pass. Now let's run broader test suite for agents to be safe.
Assistant
All 711 tests pass. Now remove the temporary test file (per instructions - shouldn't add new tests to repo).
Assistant
Now let's re-run the existing test suites once more to confirm final state, and view the full diff.
Assistant
The diff looks clean and mirrors codex.py's pattern closely. Let's run the full test suite once more to be extra safe (broader unit tests directory).
Assistant
Full test suite passes (2503 passed, 1 skipped). Now let's check
git statusto make sure the temp test file is removed and no stray files exist.Assistant
Only the intended file is modified. Let's do a final review of the complete run() method to make sure everything is coherent.
Assistant
This is consistent with the codex pattern. Now let's checklist review.
Assistant
Now let's finalize by reviewing the checklist explicitly.
Checklist review:
-
If an error was reported in the issue description, I have successfully reproduced it. — This issue is a feature request (no error/bug to reproduce). Instead, I verified the absence of OAuth support by inspecting
gemini_cli.py'srun()method, confirming it only wiredGEMINI_API_KEY/Vertex env vars with no OAuth injection path, matching the issue's description. -
If an error was reported, confirmed my fix resolves it. — N/A (feature request), but I verified the new opt-in behavior works via a temporary test suite (16 tests covering
_resolve_oauth_creds_pathpriority logic andrun()wiring: upload, chown, symlink, cleanup, and default no-op behavior), all of which passed, then removed the temporary test file per instructions. -
I have thought about edge cases and made sure my fix handles them as well. — Covered: explicit path missing raises, force flag with missing default file raises, invalid boolean value raises,
default_user is Noneskips chown, and default behavior (no env vars set) leavesupload_fileuncalled — fully backward compatible.
-
Assistant
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Ran
test_gemini_cli.py,test_gemini_cli_mcp.py,test_codex_auth.py, the fulltests/unit/agentsdirectory (711 passed), and the entiretests/unitsuite (2503 passed, 1 skipped). All green.
The implementation is complete, backward-compatible, and mirrors the codex auth.json pattern exactly as requested in the issue. Let's do a final diff check before submitting.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. — Ran
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.