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.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.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /harbor, current file: none) bash-$
- Assistant
I'll start by exploring the repository structure to understand the codebase and locate the relevant files. Let's first check the current directory.
- Assistant
Let me explore the repository structure to understand the codebase better. I need to find:
- The gemini-cli agent implementation
- The codex auth implementation to mirror3. Existing tests
- Assistant
Let me look at the src directory structure to find the gemini-cli agent implementation.
- Assistant
Let me explore the structure more.
- Assistant
Let me examine both the codex and gemini-cli agent implementations to understand the pattern.
- Assistant
Let me search for the auth-related functions in codex.py.
- Assistant
Let me see the _resolve_auth_json_path function in detail:
- Assistant
I need to use the goto command or just use sed/cat to view specific lines.
- Assistant
Now let me look at the gemini_cli.py file to understand its structure:
- Assistant
Let me read the gemini_cli.py file to understand its current structure.
- Assistant
Let me continue reading the gemini_cli.py file to see the rest of the implementation.
- Assistant
Let me continue reading to find the run method.
- Assistant
Let me continue reading to find the run method:
- Assistant
Now let me look at the test files to understand the existing test structure and see if there are tests for the codex auth feature:
- Assistant
Let me examine the codex auth test file to understand the testing pattern:
- Assistant
Let me continue reading the test file to see all the tests.
- Assistant
Now let me look at the existing gemini_cli test files:
- Assistant
Let me check the base agent class to understand the
_get_envmethod and other utilities: - Assistant
Let me check the
parse_bool_env_valueutility: - Assistant
Let me look at the
parse_bool_env_valuefunction to understand how it works: - Assistant
Now let me check how the
_get_envmethod works in the base class to understand how extra_env is handled: - Assistant
Now let me also check the conftest.py for test fixtures:
- Assistant
Let me check the conftest to understand the temp_dir fixture.
- Assistant
Let me look at the full conftest.py to understand the fixtures: up to 60 lines.
- Assistant
Let me look at the conftest.py to understand the temp_dir fixture.
- Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
-
In
gemini_cli.py, I need to:- Add
_resolve_oauth_creds_pathmethod mirroring codex's_resolve_auth_json_path - Add
_REMOTE_GEMINI_HOMEand_REMOTE_GEMINI_SECRETS_DIRclass constants - Modify the
runmethod to handle OAuth credentials injection - Import
parse_bool_env_valueandPurePosixPathandEnvironmentPaths
- Add
-
Create tests in a new file
test_gemini_cli_oauth.pymirroringtest_codex_auth.py
Let me first check existing imports in gemini_cli.py more carefully, and also look at how codex handles the _REMOTE paths and session management:
-
- Assistant
Let me look at the imports section and the existing
runmethod more carefully: - Assistant
Now let me look at the EnvironmentPaths to understand the path constants:
- Assistant
Let me look at the EnvironmentPaths class to understand the paths:
- Assistant
Let me look at the EnvironmentPaths class:
- Assistant
Now let me look at the full gemini_cli
runmethod carefully: - Assistant
Now I have a clear understanding of the codebase. Let me implement the OAuth credential injection for gemini-cli, mirroring the codex pattern. First, let me add the imports needed:
- Assistant
Now I need to add the import for
parse_bool_env_value: - Assistant
I see the edit duplicated the imports. Let me fix this by removing the duplicate lines:
- Assistant
Let me fix the duplicated imports by removing lines 29-54:
- Assistant
Good, the imports are clean now. Now I need to add the class constants and the
_resolve_oauth_creds_path()method. Let me first add the class constants: - Assistant
I see there's a duplicate
name()method and I also need to addPurePosixPathimport. Let me fix both issues: - Assistant
Now let me remove the duplicate
name()method: - Assistant
Good. Now I need to add the
_resolve_oauth_creds_path()method. Let me add it after thename()method: - Assistant
Good. Now I need to modify the
run()method to inject the OAuth credentials. Let me find and view the run method: - Assistant
Let me view the run method now:
- Assistant
Now I need to modify the
run()method to add OAuth credential injection. Let me replace the entire run method: - Assistant
Let me verify the rest of the file looks good:
- Assistant
Good. Now let me verify the full file is syntactically correct by running a quick syntax check:
- Assistant
Now let me create the test file for the OAuth creds functionality. I'll mirror the codex auth tests:
- Assistant
Now let me write the test file:
- Assistant
Good. Now let me run the tests to make sure they pass:
- Assistant
Let me check how tests are run in this project:
- Assistant
I see - we need
asyncio_mode = "auto"but it's complaining about unknown config option. Let me check if there's a pytest-asyncio installed and try with the venv Python: - Assistant
All 18 tests pass. Now let me also run the existing gemini_cli tests to make sure I haven't broken anything:
- Assistant
All tests pass. Let me also run the existing codex auth tests to make sure those still pass too:
- Assistant
All tests pass. Let me verify the final state of my changes by looking at the diff:
- Assistant
Let me check the git status to see all changes:
- Assistant
Let me view the full diff:
- Assistant
Let me also run the existing MCP test to make sure it still passes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
Qwen/Qwen3.6-27BCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →