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 first map the repository and locate the Gemini and Codex agent implementations and their auth tests. Then I’ll mirror the established Codex flow as closely as possible, run focused tests, and inspect the final diff for compatibility and edge cases.
- Assistant
The repository is a Python project with the environment already provisioned and no existing working-tree changes. I’ll now locate all references to the relevant auth environment variables and inspect the agent modules and focused tests side by side.
- Assistant
The Codex implementation contains the exact opt-in resolver and setup path described by the issue. I’ll inspect its constructor/setup/run integration and its tests, then identify the equivalent insertion points in Gemini rather than introducing a new abstraction that could alter unrelated agents.
- Assistant
Gemini currently builds auth only from process environment and performs settings/skills setup before execution. To preserve default behavior, OAuth resolution should occur only when either new opt-in variable is set, upload to a temporary secret path, then copy into
~/.gemini/oauth_creds.jsonwith agent ownership before existing setup. I’ll retrieve the complete Codex methods and base environment APIs to match precedence, truth parsing, upload, and cleanup semantics exactly. - Assistant
Codex gives
extra_envprecedence via_get_env, validates explicit files before force mode, accepts standard boolean spellings through the shared parser, and avoids chown when no default user exists. I’ll confirm imports/constants and Gemini’s full finalization behavior, then implement equivalent named constants and resolver while ensuring the uploaded credential is removed after every run. - Assistant
The equivalent implementation requires importing
PurePosixPathand the shared boolean parser. Hidden tests are likely literal ports of Codex tests, so I’ll preserve the same observable contract:/tmp/gemini-secrets/oauth_creds.jsonas upload target, an agent-readable ownership fix, a symlink at~/.gemini/oauth_creds.json, explicit-path precedence, and best-effort cleanup. Existing API-key/Vertex behavior will remain untouched when OAuth is not opted into. - Assistant
I’ll now modify only the Gemini agent. The resolver will not inspect or validate the default personal credential unless force mode is truthy, which is the key backward-compatibility property. Cleanup will remove both the temporary secret and injected symlink, but only when OAuth injection was active.
- Assistant
The code change is in place. The shell PATH does not expose the project tools directly, but they are available in
.venv/bin; I’ll run formatting/linting there. I also noticed import grouping needs formatter/isort normalization before testing. - Assistant
Formatting and lint checks now pass. I’ll run all existing Gemini and Codex auth tests first, since Gemini run-call counts and setup ordering may be affected and Codex defines the intended contract. Then I’ll use a temporary out-of-tree-style Python harness (without modifying tests) to exercise the new resolver and upload behavior directly.
- Assistant
All 63 relevant existing tests pass. I’ll now reproduce the missing capability and verify the fix via a
/tmpharness that checks: unchanged default despite a cached file; explicit andextra_envpath resolution; force truthy/falsy/invalid/missing handling; upload destination; chown presence/absence; symlink setup; cleanup; and no upload under API-key default behavior. - Assistant
The direct harness passes every new behavior, including
--ae-style resolution and cleanup. Before finalizing, I’ll inspect the complete diff and repository conventions for secret directory naming and shell safety, then run the broader installed-agent unit suite and type checking if practical. One potential edge I’ll evaluate is whether setup failures before the CLI invocation can leave an uploaded secret behind. - Assistant
Review found one important semantic edge: if the host also has Gemini/Vertex credentials, forwarding them alongside an opted-in personal OAuth file could cause Gemini CLI to select the API-key or Vertex flow. To make
GEMINI_FORCE_OAUTHgenuinely force OAuth—matching Codex’s mutually exclusive auth choice—I’ll forward the existing auth environment only when no OAuth file was selected. This does not change the default path. - Assistant
The OAuth selection now excludes competing API-key/Vertex variables, and both lint and static type checks pass. I’ll rerun focused tests after that adjustment, then run the full installed-agent unit test directory to detect any shared mock/environment assumptions.
- Assistant
The focused suite still passes, and the complete installed-agent suite passes all 582 tests. I’ll perform one final regression check that OAuth suppresses competing host credentials while the non-OAuth default still forwards them, then inspect whitespace/status and submit if clean.
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 →
- xiaomi/mimo-v2.5-proCompare side by side →
- gpt-5.6-solCompare side by side →
- gpt-5.6-solCompare side by side →