Summary
The Gemini plugin fails to refresh expired OAuth tokens when gemini-cli is installed via Homebrew, causing repeated "Gemini session expired" errors roughly every hour.
Root Cause
The plugin's loadOauthClientCreds() function searches for OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET in a file at a path like:
@google/gemini-cli-core/dist/src/code_assist/oauth2.js
However, Homebrew-installed gemini-cli (tested on v0.37.1) bundles all source into chunk files:
@google/gemini-cli/bundle/chunk-DZQZKSDY.js
@google/gemini-cli/bundle/chunk-7D745VGL.js
...
The individual oauth2.js file no longer exists. As a result, loadOauthClientCreds() returns null, refreshToken() bails out, and the plugin throws an error with an invalid command (gemini auth login doesn't exist either).
Reproduction
- Install gemini-cli via Homebrew:
brew install gemini-cli
- Authenticate: run
gemini and complete OAuth flow
- Wait ~1 hour for the access token to expire
- OpenUsage shows:
Gemini session expired. Run gemini auth login to authenticate.
Suggested Fix
In loadOauthClientCreds(), add the Homebrew bundle directory as a candidate and search bundle/chunk-*.js files for the OAUTH_CLIENT_ID / OAUTH_CLIENT_SECRET patterns. For example:
/opt/homebrew/opt/gemini-cli/libexec/lib/node_modules/@google/gemini-cli/bundle/
Also, the error message references gemini auth login which is not a valid command — the Gemini CLI has no auth subcommand. The correct instruction is to just run gemini to re-trigger the OAuth flow.
Workaround
Create a shim file at the expected path with the client credentials extracted from the bundle:
mkdir -p /opt/homebrew/opt/gemini-cli/libexec/lib/node_modules/@google/gemini-cli/node_modules/@google/gemini-cli-core/dist/src/code_assist/
Then write oauth2.js there with the OAUTH_CLIENT_ID and OAUTH_CLIENT_SECRET values from the bundle chunks. This breaks on brew upgrade.
Environment
- macOS (Apple Silicon)
- gemini-cli v0.37.1 (Homebrew)
- OpenUsage latest
Summary
The Gemini plugin fails to refresh expired OAuth tokens when
gemini-cliis installed via Homebrew, causing repeated "Gemini session expired" errors roughly every hour.Root Cause
The plugin's
loadOauthClientCreds()function searches forOAUTH_CLIENT_IDandOAUTH_CLIENT_SECRETin a file at a path like:However, Homebrew-installed
gemini-cli(tested on v0.37.1) bundles all source into chunk files:The individual
oauth2.jsfile no longer exists. As a result,loadOauthClientCreds()returnsnull,refreshToken()bails out, and the plugin throws an error with an invalid command (gemini auth logindoesn't exist either).Reproduction
brew install gemini-cligeminiand complete OAuth flowGemini session expired. Run gemini auth login to authenticate.Suggested Fix
In
loadOauthClientCreds(), add the Homebrew bundle directory as a candidate and searchbundle/chunk-*.jsfiles for theOAUTH_CLIENT_ID/OAUTH_CLIENT_SECRETpatterns. For example:Also, the error message references
gemini auth loginwhich is not a valid command — the Gemini CLI has noauthsubcommand. The correct instruction is to just rungeminito re-trigger the OAuth flow.Workaround
Create a shim file at the expected path with the client credentials extracted from the bundle:
Then write
oauth2.jsthere with theOAUTH_CLIENT_IDandOAUTH_CLIENT_SECRETvalues from the bundle chunks. This breaks onbrew upgrade.Environment