Skip to content

Gemini CLI ignores .env with custom oauth_creds.json path #2076

Description

@piknockyou

Description

🐛 Problem

When running Gemini CLI, some users encounter the following error on login:

Failed to login. Message: This account requires setting the GOOGLE_CLOUD_PROJECT env var.
See https://goo.gle/gemini-cli-auth-docs#workspace-gca
Image

According to the Gemini CLI Authentication Docs, this error should only occur in specific cases, but I am seeing this even though none of those cases apply. I only have personal accounts.


✅ Workaround

The issue can be resolved by explicitly setting GOOGLE_CLOUD_PROJECT in a .env file located at:

  • Windows: %USERPROFILE%\.gemini\
  • Linux/macOS: ~/.gemini/

Example:

GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID_HERE

After doing so, Gemini CLI starts and works fine. ✅

The same fix also applies for Kilo Code > Settings > Providers > API Provider > Gemini CLI. ✅


🚨 Issue with Kilo Code

However, when Kilo Code > Settings > Providers > OAuth Credentials Path (optional) > "YOUR_CUSTOM_PATH_HERE\oauth_creds.json" is configured for API Provider Gemini CLI, Kilo Code disregards the .env file located next to the oauth_creds.json file. In chat, this leads to a Gemini CLI API error ❌:

{
  "error": {
    "code": 403,
    "message": "Permission denied on resource project default.",
    "errors": [
      {
        "message": "Permission denied on resource project default.",
        "domain": "global",
        "reason": "forbidden"
      }
    ],
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "CONSUMER_INVALID",
        "domain": "googleapis.com",
        "metadata": {
          "containerInfo": "default",
          "service": "cloudaicompanion.googleapis.com",
          "consumer": "projects/default"
        }
      },
      {
        "@type": "type.googleapis.com/google.rpc.LocalizedMessage",
        "locale": "en-US",
        "message": "Permission denied on resource project default."
      },
      {
        "@type": "type.googleapis.com/google.rpc.Help",
        "links": [
          {
            "description": "Google developers console",
            "url": "https://console.developers.google.com/"
          }
        ]
      }
    ]
  }
}

🎯 Expected Behavior

  • Each profile change (chat mode) or path change (settings) for Gemini CLI should trigger a reload of the .env file that resides alongside the selected oauth_creds.json.

🔄 Suggested Fix / Feature Request

  • Update the integration of Gemini CLI so that the .env file is dynamically read/reloaded whenever a different Gemini CLI profile is selected.
  • Ensure that GOOGLE_CLOUD_PROJECT is consistently applied from the .env file next to the active oauth_creds.json, not just from the one originally loaded at launch.

🪜 Reproduce

To reproduce cleanly, you must ensure there’s no “cross-contamination” from the default .gemini folder loading an existing .env file during Kilo Code setup.

  1. Close VS Code.
  2. Rename existing ~/.gemini folder.
  3. Create a .env file inside it; it contains GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID_HERE.
  4. Start VS Code and set up the Kilo Code provider Gemini CLI with the OAuth Credentials Path pointing to your oauth_creds.json.

Of course, for these steps to be relevant, your account must also be one of those flagged as requiring the GOOGLE_CLOUD_PROJECT setting, as detailed in the Gemini CLI authentication docs.


📌 Summary

  • Problem: Gemini CLI (vanilla & Kilo Code) requires GOOGLE_CLOUD_PROJECT env var, even for personal accounts where it shouldn't be needed.
  • Workaround: Manually creating a .env file with GOOGLE_CLOUD_PROJECT in ~/.gemini/ fixes the issue for the standard CLI and for Kilo Code's default setup.
  • Kilo Code Issue: Kilo Code ignores the .env file when a custom path for oauth_creds.json is used, causing API errors.
  • Expected Fix: Kilo Code should dynamically load the .env file that is located next to the currently active oauth_creds.json upon profile or path changes.

💻 Environment

  • OS: Windows 11

Related to

#947
#1153
#1199
#1454

cline/cline#4526
google-gemini/gemini-cli#1432
google-gemini/gemini-cli#3001

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions