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
Let me start by exploring the repository structure to understand the codebase and then look at the codex agent's auth implementation to mirror it for gemini-cli.
Assistant
Now let me look at the gemini_cli.py file:
Assistant
Now let me look at the existing gemini test file and the conftest for
temp_dir:Assistant
Let me look at the base class and helpers to understand
_get_envandparse_bool_env_value:Assistant
Assistant
Now let me check how the gemini run command constructs the env. The current code uses
os.environdirectly. For the oauth flow, I should useself._get_envso extra_env works.Let me look at the current
run()method's auth section and design the new one.Now let me also check the test file for gemini_cli to understand the run test patterns (the test_gemini_cli.py - does it test run?).
Assistant
There are no run() tests in test_gemini_cli.py. Now let me implement the changes.
Let me design the implementation mirroring codex:
-
Add imports:
PurePosixPath,parse_bool_env_value, .
-
Assistant
Now let me run the existing tests to confirm baseline:
Assistant
Now I'll implement the changes. First, let me update the imports and add the class constant and the
_resolve_oauth_creds_pathmethod:Assistant
Now let me make the edits. First, update imports:
Assistant
Let me clean up the import ordering:
Assistant
I lost the
parse_bool_env_valueimport. Let me re-add it:Assistant
Now add the class constant for the remote secrets dir:
Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. Let me find a good place — right beforerun():Assistant
Now let me insert the
_resolve_oauth_creds_pathmethod before the@with_prompt_templatedecorator:Assistant
Now let me rewrite the
run()method's auth section to handle the OAuth creds injection:Assistant
Now let me add cleanup of the secrets dir in the finally block:
Assistant
Now let me verify the full run method and check for syntax issues:
Assistant
Let me check if
osis still used elsewhere in the file:Assistant
osis no longer used. Let me remove the unused import:Assistant
Now let me create a test file mirroring
test_codex_auth.pyto validate my implementation. But the instructions say not to add new tests to the repository. I'll create a temporary test script instead. Let me first write a temporary reproduction/test script:Assistant
All 18 temporary tests pass. Now let me run the existing tests to ensure I didn't break anything:
Assistant
All existing tests pass. Let me run a broader test sweep to ensure nothing broke:
Assistant
All 695 tests pass. Let me check the linter config and run it on the modified file:
Assistant
Ruff passes. Let me check formatting too:
Assistant
Let me check if there's documentation about env vars / auth that I should update, mirroring codex docs:
Assistant
Let me re-run the tests after the
osimport removal to confirm everything still passes:Assistant
Let me review the final diff to make sure everything is clean:
Assistant
The diff looks clean. Let me do a final sanity check — confirm no temp files remain and the module imports cleanly:
Assistant
Only
gemini_cli.pyis modified, no temp files remain, and the import works. Let me do a final broad test run to be fully confident:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.