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.
Assistant
Now let me look at the existing tests for codex auth and the agent name module:
Assistant
Now let me look at the Claude code agent to see how CLAUDE_CODE_OAUTH_TOKEN works, since it's also mentioned in the issue.
Assistant
Now let me look at the agent name module and understand the EnvironmentPaths:
Assistant
Now let me check the test conftest:
Assistant
Now I have a good understanding. Let me check the existing environment tests to understand
default_user:Assistant
Now let me look at how the codex agent's
_resolve_auth_json_pathis implemented to see exact patterns. Let me also look at what~/.geminipaths are needed:Assistant
Now let me look at the issue:
~/.gemini/oauth_creds.jsonis the file that should be injected. Let me also check what the typical Gem CLI uses. Let me look at if there's a CHANGELOG to understand:Assistant
Now let me check how gemini-cli's
~/.geminiis structured. Let me search for any docs about gemini oauth:Assistant
Let me look at the
runmethod of gemini-cli more carefully:Assistant
Let me first run the existing tests for both codex and gemini to confirm the test environment works:
Assistant
Now I have a clear understanding of the codebase. Let me plan the implementation:
Plan:
- Add
_resolve_oauth_creds_path()method toGeminiCliclass, mirroring codex's_resolve_auth_json_path():- Check
GEMINI_OAUTH_CREDS_PATHfor explicit path - Check
GEMINI_FORCE_OAUTHfor~/.gemini/oauth_creds.json - Default: None (use
GEMINI_API_KEY)
- Check
- Modify
run()to:- When OAuth creds are configured, upload the file to
/tmp/gemini-secrets/oauth_creds.json, chown it, and symlink to~/.gemini/oauth_creds.json - When OAuth creds are configured, skip the API key env vars (since user opts out)
- Clean up the secrets dir at the end
- When OAuth creds are configured, upload the file to
- Add tests in
tests/unit/agents/installed/test_gemini_cli_auth.pymirroringtest_codex_auth.py
Let me first verify the codex test patterns more carefully:
- Add
Assistant
Now let me look at the full test pattern for
test_uses_tmp_codex_home_and_syncs_sessions_to_agent_logsto understand what to mirror:Assistant
Now I have everything I need. Let me implement the changes. First, let me modify the
gemini_cli.py:Assistant
Need to add the imports first.
Let me first check what imports are already in
gemini_cli.py:Let me first check what imports are already ingemini_cli.py:Assistant
Now let me look at the install method in
gemini_cli.pyto ensure I understand the structure:Assistant
Now let me make the changes to
gemini_cli.py. First, update the imports:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod. First, I need to find a good location to add it - right before therunmethod:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod and a secrets dir constant right before therunmethod:Assistant
Now let me add the
_resolve_oauth_creds_pathmethod right before therunmethod:Assistant
Let me verify the changes look correct:
Assistant
Let me see the full updated
runmethod:Assistant
Now let me run the existing tests to confirm I haven't broken anything:
Assistant
All existing tests pass. Now let me create the tests for the new OAuth feature. I'll port the codex auth tests 1:1:
Assistant
Now let me run the new tests:
Assistant
All 19 new tests pass. Let me also verify the complete test suite for installed agents still passes:
Assistant
All 601 tests pass! Let me also run the broader test suite to make sure nothing else is affected:
Assistant
All 2522 unit tests pass! Now let me think about edge cases. Let me write a quick test to verify the end-to-end behavior to make sure the codex-like flow works:
Assistant
Let me check the actual command format:
Assistant
The flow works correctly. Let me also verify the default behavior (no OAuth) still works:
Assistant
Let me also do a sanity check that I didn't break anything else by running a broader test:
Assistant
Let me check if there's an integration test:
Assistant
Let me also run the tests for the codex auth to verify the parallel codex auth tests are still working (they should be unchanged):
Assistant
All 59 tests pass (including 19 new ones). Now let me clean up the temporary verification scripts:
Assistant
Now let me verify the final state of the changes:
Assistant
Let me look at the new test file to confirm it's well-structured:
Assistant
Now let me also check that the unused
EnvironmentPathsimport isn't actually needed. Let me check the import:Assistant
I notice
EnvironmentPathsis imported but not actually used in my changes. Let me remove the unused import:Assistant
Now let me run the tests one more time to confirm everything still works:
Assistant
All 601 tests pass. Let me also run a syntax check on the modified file:
Assistant
Let me also check that the test file has the right number of tests to match the codex auth tests:
Assistant
Let me also add a test for the edge case where both
GEMINI_OAUTH_CREDS_PATHandGEMINI_FORCE_OAUTHare set (explicit should win):Assistant
All 20 tests pass. Let me also run the full test suite to make sure nothing else is affected:
Assistant
All 2523 tests pass (1 more than before since I added a new test). Let me also check the final state of the changes:
Assistant
The diff is clean. Let me look at the final test file:
Assistant
The test file is well-structured and follows the codex test pattern closely. Let me also do a final review by checking the final state of the gemini_cli.py file:
Assistant
Now let me check that my implementation properly handles the
Pathimport. Let me also think about one more thing — thePathimport is needed for the_resolve_oauth_creds_pathmethod:Assistant
Good. Let me also check if there's a
GeminiCliimport path issue:Assistant
Everything is in order. Let me check the final test results one more time:
Assistant
All 20 tests pass. Let me run the full test suite one more time to confirm everything is good:
Assistant
All 2523 unit tests pass. Let me verify the final diff:
Assistant
Checklist Review
Let me go through the issue's checklist:
-
✅ If an error was reported in the issue description, I have successfully reproduced it. - The issue is a feature request, not an error report. The codex auth flow that we're mirroring is already known to work. I tested my implementation end-to-end with a mock environment and confirmed the new OAuth credentials injection works correctly.
-
✅ If an error was reported in the issue description, I have confirmed that my fix resolves the error. - Same as above (feature request, not a bug fix). I confirmed via comprehensive unit tests (20 new tests, all passing) that:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.