Shipping an AI app or agent? Security review in 1 working day: $149 / ₹13,900. Request a review →
AI Review Ready
Home / Error fixes / Not opening the browser
Fix · Gemini CLI · sign-in

Gemini CLI not opening the browser to sign in

Fix: start it with NO_BROWSER=true gemini (PowerShell: $env:NO_BROWSER="true"; gemini). Gemini CLI then prints a sign-in URL instead. Open it in any browser, on any device, sign in, and paste the authorization code you get back into the terminal.

What you see

The normal flow prints this and waits for the browser to report back:

Attempting to open authentication page in your browser.
Otherwise navigate to:

https://accounts.google.com/...

Waiting for authentication...

When it goes wrong, the source code has three messages that all end in the same advice:

Failed to open browser with error: ...
Please try running again with NO_BROWSER=true set.

Authentication timed out after 5 minutes. The browser tab may have gotten stuck in a loading state. Please try again or use NO_BROWSER=true for manual authentication.

Authentication consent could not be obtained.
Please run Gemini CLI in an interactive terminal to authenticate, or use NO_BROWSER=true for manual authentication.

How the NO_BROWSER login works

  1. Set the variable for that run: NO_BROWSER=true gemini (bash, zsh), or $env:NO_BROWSER="true" then gemini (PowerShell).
  2. Choose Sign in with Google. It prints Please visit the following URL to authorize the application: and a link.
  3. Open the link anywhere, even on your phone, and sign in. Google sends you to codeassist.google.com/authcode with the code.
  4. Paste it at Enter the authorization code:. You have 5 minutes, and it allows two attempts.

Your login is then cached, by default in ~/.gemini/oauth_creds.json, so later sessions start without signing in.

When Gemini CLI skips the browser on purpose

It goes straight to the URL-and-code flow, as if NO_BROWSER were set, when:

  • BROWSER is set to www-browser;
  • CI is set, or DEBIAN_FRONTEND=noninteractive;
  • on Linux, none of DISPLAY, WAYLAND_DISPLAY or MIR_SOCKET is set (servers, most containers);
  • on macOS or Windows, you are in an SSH session (SSH_CONNECTION is set).

Causes and fixes

SymptomCauseFix
Failed to open browser with errorNo program could open the URL, for example xdg-open missing in a minimal containerNO_BROWSER=true
Browser opens, you sign in, the terminal still waits, then times outThe sign-in redirect goes to http://127.0.0.1:<port>/oauth2callback on the machine running Gemini CLI, and never got thereRetry once; otherwise NO_BROWSER=true
Running in Docker and you want the browser flowThe callback listener binds to 127.0.0.1 inside the container on a random portThe source reads OAUTH_CALLBACK_HOST (its comment gives 0.0.0.0 for Docker) and OAUTH_CALLBACK_PORT for a fixed port you can publish. NO_BROWSER=true is simpler
Manual authorization is required but the current session is non-interactiveA script or pipe can't paste a codeSign in once interactively, or use an API key (below)
Authentication consent could not be obtainedGemini CLI couldn't ask "Do you want to continue?" in this terminalRun it in an interactive terminal, or NO_BROWSER=true

Skip the Google login: use an API key

Scripts, CI and headless mode can't do an interactive Google login, and Gemini CLI's docs point them to environment-variable auth: a GEMINI_API_KEY from Google AI Studio, or Vertex AI. Set the key, start gemini and choose Use Gemini API key. Inside a session, /auth opens the dialog to change sign-in method. API-key quotas differ from Google-login quotas; see Gemini CLI 429.

Still failing?

  • unable to get local issuer certificate during sign-in means a corporate proxy is inspecting TLS. Try NODE_USE_SYSTEM_CA=1 first, then NODE_EXTRA_CA_CERTS pointing at your company's root certificate.
  • Company, school or Workspace accounts need GOOGLE_CLOUD_PROJECT set to a project ID before signing in.
  • Exit code 41 is Gemini CLI's FatalAuthenticationError: sign-in failed, so read the message printed above it.

Running Claude Code, Codex or Cursor on real repos, or shipping an AI agent? A Quick Review ($149 / ₹13,900, 1 working day) checks one repo, config or setup for leaked keys, risky agent permissions and MCP servers. Request a Quick Review

FAQ

How do I log in to Gemini CLI over SSH?

Run NO_BROWSER=true gemini, choose Sign in with Google, open the printed URL in a browser on your own machine, and paste the authorization code back into the SSH session.

What does NO_BROWSER=true do in Gemini CLI?

It stops Gemini CLI from trying to open a browser. It prints a sign-in URL and asks you to paste the authorization code shown after you sign in.

Can I use Gemini CLI in CI without a browser?

Not with Google login, which needs an interactive terminal. Gemini CLI's docs say to use a GEMINI_API_KEY or Vertex AI credentials from environment variables.

Where does Gemini CLI store my Google login?

In ~/.gemini/oauth_creds.json by default, unless encrypted credential storage is turned on.

Related errors

Sources

Read 30 Nov 2026. These tools change often: if a step no longer matches, the linked page wins.

Related free tools