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.
- 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
Let me start by exploring the repository structure to understand how it's organized and find relevant files related to authentication and OAuth.
Assistant
Let me explore the repository structure more to understand how it's organized.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor </tool_call>
Assistant
Let me explore the repository structure first.
Assistant
This appears to be a Harbor repository. Let me look for files related to gemini-cli and codex auth to understand the pattern being followed.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/adapters </tool_call>
Assistant
Let me use the bash terminal tool to list the adapters directory.
Assistant
Let me search for gemini-cli related files and also look for codex auth patterns.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -type d -name "gemini" 2>/dev/null </tool_call>
Assistant
Let me search for gemini-cli related directories and files.
Assistant
The gemini-cli isn't in a subdirectory. Let me search for files related to "gemini" and "codex" in the repository.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "gemini-cli" /harbor --include=".py" --include=".md" --include="*.json" 2>/dev/null | head -50 </tool_call>
Assistant
Let me search for gemini-cli references in the repository.
Assistant
Now let me look for codex auth patterns and the implementation mentioned in the issue.
<tool_call> <function=bash_terminal> <parameter=command> grep -r "codex" /harbor/src --include="*.py" 2>/dev/null | head -50 </tool_call>
Assistant
Let me search for codex-related files in the src directory to understand the codex auth pattern.
Assistant
The issue description mentions that the user already has a working implementation. Let me first understand the existing codex.py implementation and then look at the gemini_cli.py implementation.
Assistant
Now let me look at the gemini_cli.py file to understand its current implementation:
Assistant
Now I understand the issue. The issue is about adding OAuth credential injection support to the
gemini-cliagent, similar to what was done in thecodexagent. Thecodexagent has the_resolve_auth_json_path()method that allows:CODEX_AUTH_JSON_PATH- use a specific auth.json fileCODEX_FORCE_AUTH_JSON- use~/.codex/auth.json
For
gemini-cli, the equivalent would be:GEMINI_OAUTH_CREDS_PATH- use a specific OAuth credentials fileGEMINI_FORCE_OAUTH- use~/.gemini/oauth_creds.json
Let me search for any tests related to this functionality to understand the expected implementation better.
<tool_call> <function=bash_terminal> <parameter=command> find /harbor -name "codexauth*" -type f 2>/dev/null </tool_call>
Assistant
Let me search for any test files related to codex auth or OAuth credentials.
Assistant
Let me look at the test_codex_auth.py file to understand how the codex auth functionality is tested.
Assistant
Now I understand the pattern. Let me also look at the
harbor.utils.envmodule to see theparse_bool_env_valuefunction used by codex.<tool_call> <function=bash_terminal> <parameter=command> grep -r "parse_bool_env_value" /harbor/src --include="*.py" 2>/dev/null </tool_call>
Assistant
Let me search for the parse_bool_env_value function to understand how it works.
Assistant
Let me look at the parse_bool_env_value function.
Assistant
Let me look at the base.py file to understand the base class structure for installed agents.
Assistant
Now I have a good understanding of the structure. Let me look at the rest of the codex.py file to see how auth.json is handled during the run.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "_resolve_auth_json_path|upload_file|chown|setup_command|auth_json" /harbor/src/harbor/agents/installed/codex.py </tool_call>
Assistant
Let me search for these methods in the codex.py file.
Assistant
Let me see the full
_resolve_auth_json_pathmethod and therunmethod's auth handling section:<tool_call> <function=bash_terminal> <parameter=command> sed -n '674,720p' /harbor/src/harbor/agents/installed/codex.py </tool_call>
Assistant
Let me get the specific lines of the _resolve_auth_json_path method and the run method's auth handling section.
Assistant
Now I have a clear understanding of the pattern. Let me look for the
_get_envmethod in the base class to understand how environment variables are accessed.<tool_call> <function=bash_terminal> <parameter=command> grep -n "_get_env" /harbor/src/harbor/agents/installed/base.py </tool_call>
Assistant
Let me search for the
_get_envmethod in the agents base module.Assistant
Let me look at the
_get_envmethod in the base.py file.<tool_call> <function=bash_terminal> <parameter=command> sed -n '230,260p' /harbor/src/harbor/agents/installed/base.py </tool_call>
Assistant
Let me use the bash terminal to look at the
_get_envmethod.Assistant
Now I have a clear understanding of the pattern. Let me now understand what files are in the /harbor/src/harbor/agents/installed/ directory.
<tool_call> <function=bash_terminal> <parameter=command> ls -la /harbor/src/harbor/agents/installed/ </tool_call>
Assistant
Let me use the bash terminal to list the installed agents.
Assistant
Now I understand the codebase. Based on my research:
-
The
codex.pyagent has an_resolve_auth_json_path()method that allows:CODEX_AUTH_JSON_PATH- explicit path to an auth.json fileCODEX_FORCE_AUTH_JSON- use~/.codex/auth.jsonby default
-
The
gemini_cli.pyagent needs the same functionality with:GEMINI_OAUTH_CREDS_PATH- explicit path to an oauth credentials fileGEMINI_FORCE_OAUTH- use~/.gemini/oauth_creds.jsonby default
-
The issue mentions that users with "Login with Google" session have
~/.gemini/oauth_creds.json.
Now I need to implement the same pattern for
gemini_cli.py. Let me also check if there's any existing test file for gemini_cli:<tool_call> <function=bash_terminal> <parameter=command> find /harbor/tests -name "gemini" 2>/dev/null </tool_call>
-
Assistant
Let me find any test files related to gemini-cli.
Assistant
Let me look at the test_gemini_cli.py file to understand the testing patterns:
<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/tests/unit/agents/installed/test_gemini_cli.py </tool_call>
Assistant
Let me use the bash terminal tool to look at the test file.
Assistant
Now I have a clear understanding of the codebase. Let me implement the OAuth credential injection functionality for gemini-cli.
Here's my plan:
- Add a
_resolve_oauth_creds_path()method toGeminiClithat mirrors theCodex._resolve_auth_json_path()method - Modify the
run()method to handle OAuth credentials similar to howcodexhandles auth.json - Add tests for the new functionality
Let me first check the exact format of the
~/.gemini/oauth_creds.jsonfile. Let me search for any references to this file format.<tool_call> <function=bash_terminal> <parameter=command> grep -r "oauth_creds" /harbor --include=".py" --include=".md" --include="*.json" 2>/dev/null </tool_call>
- Add a
Assistant
Let me search for any references to OAuth credentials in the repository.
Assistant
These references are in the litellm package, not in the harbor codebase. The issue description mentions that users with "Login with Google" session have
~/.gemini/oauth_creds.json, which is a Google OAuth credentials file used by the gemini CLI.Based on the codex pattern and the issue description, I need to implement:
-
_resolve_oauth_creds_path()method that:- Returns the file from
GEMINI_OAUTH_CREDS_PATHenv var if set - Returns
~/.gemini/oauth_creds.jsonifGEMINI_FORCE_OAUTHis truthy - Returns
Noneotherwise (falling back to API key)
- Returns the file from
-
Modify the
run()method to:- Upload the OAuth credentials file if resolved
- Set up the gemini CLI to use OAuth instead of API key
- Fix file ownership with chown
Let me now implement the changes. First, let me see the full structure of the gemini_cli.py file to understand where to add the new method.
<tool_call> <function=bash_terminal> <parameter=command> wc -l /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
-
Assistant
Let me get the line count and structure of the gemini_cli.py file.
Assistant
Let me see the structure of the file to understand where to place the new method and where to modify the run() method.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "def " /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me get the method list from the gemini_cli.py file.
Assistant
Now let me see the run() method to understand its structure and where to add the OAuth credential handling.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '649,715p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me get the content of the run() method from line 649 to 715.
Assistant
Now I have a complete understanding of the file structure. Let me also look at the codex's
_REMOTE_CODEX_SECRETS_DIRto understand the secrets directory pattern. I'll now implement the changes togemini_cli.py:- Add a
_REMOTE_GEMINI_OAUTH_DIRconstant (similar to codex's_REMOTE_CODEX_SECRETS_DIR) - Add a
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
Let me create the modified version of the gemini_cli.py file. I'll use the edit command to make the changes.
First, let me check the existing constants and class structure to understand how to add the new constant.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '20,60p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
- Add a
Assistant
Let me see the class definition and constants for the gemini_cli.py file.
Assistant
Now I understand the structure. Let me implement the changes. I'll:
- Add a
_REMOTE_GEMINI_OAUTH_DIRconstant - Add
_resolve_oauth_creds_path()method after the_build_settings_commandmethod - Modify the
run()method to handle OAuth credentials
Let me make the changes step by step. First, I'll add the constant and the
_resolve_oauth_creds_pathmethod.<tool_call> <function=bash_terminal> <parameter=command> cat /harbor/src/harbor/agents/installed/gemini_cli.py | head -100 </tool_call>
- Add a
Assistant
Let me view the first 100 lines of the gemini_cli.py file to understand the structure better before making edits.
Assistant
Now I'll implement the changes. First, let me add the constant and the
_resolve_oauth_creds_path()method. I'll edit the file to add these changes.Assistant
Now I understand the structure. Let me implement the changes to add OAuth credential support to
gemini_cli.py. I'll:- Add the import for
parse_bool_env_value - Add a
_REMOTE_GEMINI_OAUTH_DIRconstant - Add a
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
- Add the import for
Assistant
Let me check the file to see what happened and make sure the import was added correctly.
Assistant
Let me fix the import section and add all the required changes in a cleaner way:
Assistant
Let me rewrite the gemini_cli.py file with the correct structure and changes:
Assistant
Now let me verify the file was written correctly:
<tool_call> <function=bash_terminal> <parameter=command> head -50 /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me verify the file was written correctly by checking the first 50 lines.
Assistant
Good, the file looks correct. Now let me check that the _resolve_oauth_creds_path method was added correctly:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "_resolve_oauth_creds_path|GEMINI_OAUTH|GEMINI_FORCE_OAUTH" /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me use the bash terminal tool to check the method was added.
Assistant
The method was added. Let me also check the line count to make sure the file is complete:
<tool_call> <function=bash_terminal> <parameter=command> wc -l /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
The bash terminal command was not invoked. Let me try again.
Assistant
The file has 792 lines (was 715 lines before, so we added 77 lines). Now let me verify the syntax of the file by running Python to import it:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && python -c "from harbor.agents.installed.gemini_cli import GeminiCli; print('Import successful')" </tool_call>
Assistant
Let me run the import test using the bash terminal tool.
Assistant
The module is not installed. Let me try running it with the proper Python path or using the virtual environment.
Assistant
The import works. Now let me run the existing tests to make sure I haven't broken anything:
Assistant
I see there are some bugs in my implementation. The
_convert_gemini_to_atifmethod has issues. Let me check the original file and fix the bugs.Assistant
I accidentally overwrote the
_convert_gemini_to_atifmethod which introduced bugs. Let me restore the original file and make only the minimal changes needed for OAuth support.Assistant
Now let me view the original file and make the minimal changes needed:
- Add
PurePosixPathto the imports - Add
parse_bool_env_valueimport - Add
_REMOTE_GEMINI_OAUTH_DIRconstant - Add
_resolve_oauth_creds_path()method - Modify the
run()method to handle OAuth credentials
Let me look at the original run() method to understand how to modify it:
- Add
Assistant
Let me look at the original run() method in detail:
Assistant
Now let me make the changes step by step. First, I'll add the imports:
Assistant
Now I need to add the import for
parse_bool_env_valueafter the other harbor imports. Let me do this with a proper edit.Assistant
Now let me add the import for
parse_bool_env_valueafter the Trajectory import:Assistant
Let me check if the import was added correctly:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '25,35p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check if the import was added correctly using the bash terminal tool.
Assistant
The sed command corrupted the file. Let me restore it and use a cleaner approach:
Assistant
Let me take a different approach - I'll use Python to make the file modifications properly:
Assistant
Now let me add the constant and the method. Let me first find the right location in the file:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '30,50p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me use the bash terminal tool to check the file contents.
Assistant
Good, the imports are correct. Now I need to add the constant after the docstring and add the method. Let me use Python to add these:
Assistant
Now let me add the
_resolve_oauth_creds_path()method before the_build_register_skills_command()method. Let me first find where that method is:Assistant
Now let me add the
_resolve_oauth_creds_path()method before line 585:Assistant
Now let me verify the constant and method were added correctly:
Assistant
Now let me modify the
run()method to handle OAuth credentials. First, let me look at the current implementation:Assistant
Let me see more of the run() method to understand its full structure:
Assistant
Now let me modify the
run()method to add OAuth credential handling. I'll read the current file, make the necessary changes, and write it back:Assistant
Now let me verify the changes by checking the run() method:
Assistant
Let me also check the finally block:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '760,810p' /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me use the bash terminal tool to check the finally block.
Assistant
The cleanup block wasn't added properly. Let me check if the finally block replacement worked correctly:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "cleanup|rm -rf.*remote_oauth_dir" /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me check if the cleanup block was added by looking for the specific text.
Assistant
The grep command failed with exit code 1, meaning the text wasn't found. This means the replacement didn't work. Let me check the exact text of the finally block and add the cleanup properly:
<tool_call> <function=bash_terminal> <parameter=command> tail -20 /harbor/src/harbor/agents/installed/gemini_cli.py </tool_call>
Assistant
Let me use the bash terminal tool to see the end of the file.
Assistant
The cleanup block wasn't added. Let me add it manually:
<tool_call> <function=bash_terminal> <parameter=command> python3 << 'PYEOF'
Read the file
with open('/harbor/src/harbor/agents/installed/gemini_cli.py', 'r') as f: content = f.read()
The old finally block that wasn't replaced properly
old_text = ''' ) except Exception: pass'''
Add cleanup after the exception block
new_text = ''' ) except Exception: pass # cleanup - best effort try: await self.exec_as_agent( environment, command=f'rm -rf {shlex.quote(remote_oauth_dir)}', ) except Exception: pass'''
content = content.replace(old_text, new_text, 1)
Write back
with open('/harbor/src/harbor/agents/installed/gemini_cli.py', 'w') as f: f.write(content)
print("Cleanup block added") PYEOF </tool_call>
Assistant
The bash terminal command wasn't invoked. Let me use the correct tool format.
Assistant
Now let me verify that the cleanup block was added:
Assistant
Now let me verify the file can be imported and run the tests:
Assistant
Now let me run the existing tests to make sure everything works:
Assistant
All the existing tests pass. Now let me run the codex auth tests to make sure my implementation follows the same pattern correctly:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && .venv/bin/python -m pytest tests/unit/agents/installed/test_codex_auth.py -v </tool_call>
Assistant
Let me run the codex auth tests to see what they're testing and ensure my implementation follows the same pattern.
Assistant
The codex auth tests all pass. Now let me create test files for the gemini_cli OAuth functionality. First, let me check if there's already a test file for gemini_cli auth:
Assistant
There's no test file for gemini_cli auth yet. Let me create one based on the codex auth test file. Let me first check the structure of the codex test file:
Assistant
Now I'll create the test file for gemini_cli OAuth based on the codex auth tests:
Assistant
Now let me run the new test file to make sure my implementation works correctly:
Assistant
All 18 tests pass. Now let me run all the tests together to make sure everything works together:
Assistant
All 40 tests pass. Now let me also run some broader tests to make sure the changes don't break anything else:
Assistant
The tests are passing. Let me run the full test suite for the installed agents to make sure everything is working:
Assistant
All 600 tests pass. Let me also verify the changes I made by checking the git diff:
Assistant
Now let me also check the new test file:
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && git status </tool_call>
Assistant
Let me use the bash terminal tool to check the git status.
Assistant
Let me now summarize the changes and the checklist:
Summary of Changes
-
Modified
/harbor/src/harbor/agents/installed/gemini_cli.py:- Added
PurePosixPathimport from pathlib - Added
parse_bool_env_valueimport fromharbor.utils.env - Added
_REMOTE_GEMINI_OAUTH_DIRconstant (/tmp/gemini-secrets) - Added
_resolve_oauth_creds_path()method that:- Returns file from
GEMINI_OAUTH_CREDS_PATHenv var if set - Returns
~/.gemini/oauth_creds.jsonifGEMINI_FORCE_OAUTHis truthy - Returns
Noneotherwise (falling back to API key auth)
- Returns file from
- Modified the
run()method to:- Resolve OAuth credentials using
_resolve_oauth_creds_path() - Upload OAuth credentials file to the container when present
- Set up proper file ownership with chown
- Fall back to API key env vars when no OAuth credentials are present
- Clean up the OAuth secrets directory after the run
- Resolve OAuth credentials using
- Added
-
Created
/harbor/tests/unit/agents/installed/test_gemini_cli_auth.py:- Comprehensive unit tests mirroring the codex auth tests
- 18 tests covering:
- Default behavior (returns None when no env vars set)
- Explicit path via env var
- Explicit path via extra_env (--ae flag)
- Missing explicit path raises error
- Truthy FORCE_OAUTH values (1, true, TRUE, yes)
- Falsy FORCE_OAUTH values (0, false, FALSE, no)
- Missing default OAuth file raises error
- Invalid FORCE_OAUTH values raise error
- Uploads OAuth credentials when present
- Skips chown when default_user is None
- Uses API key when no OAuth credentials
- Uploads via GEMINI_FORCE_OAUTH when set
Checklist
-
If an error was reported in the issue description, I have successfully reproduced it.
- The issue was a feature request to add OAuth credential injection to gemini-cli, similar to codex. I've implemented this feature.
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I've verified the fix works by running all existing tests (600 tests pass) and my new tests (18 tests pass).
-
I have thought about edge cases and made sure my fix handles them as well.
- The implementation handles:
- No env vars set (returns None, uses API key)
- Explicit path via env var
- Explicit path via extra_env (--ae)
- Invalid/missing explicit path (raises ValueError)
- Truthy/falsy FORCE_OAUTH values
- Missing default OAuth file (raises ValueError)
- Invalid FORCE_OAUTH values (raises ValueError)
- default_user is None (skips chown)
- Cleanup of secrets directory in finally block
- The implementation handles:
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
- All 600 tests in tests/unit/agents/installed/ pass
- All 9 tests in tests/unit/agents/installed/test_gemini_cli.py pass
- All 18 tests in tests/unit/agents/installed/test_gemini_cli_auth.py pass
The implementation is complete and follows the same pattern as the codex agent for auth.json handling.
<tool_call> <function=bash_terminal> <parameter=command> cd /harbor && .venv/bin/python -m pytest tests/unit/agents/installed/test_gemini_cli_auth.py tests/unit/agents/installed/test_codex_auth.py -v </tool_call>
-
Assistant
Let me verify the tests pass again for both the new gemini_cli auth tests and the original codex auth tests.
Assistant
All 36 tests pass (18 for gemini_cli auth and 18 for codex auth). The implementation is complete.
Let me submit the changes:
Assistant
The implementation is complete. Let me submit the changes.
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
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →