Skip to content

fix: block insert env param to gemini(eg: gemini_api_key form json co…#283

Open
Next2012 wants to merge 1 commit intotiann:mainfrom
Next2012:fix_block_gemini_env
Open

fix: block insert env param to gemini(eg: gemini_api_key form json co…#283
Next2012 wants to merge 1 commit intotiann:mainfrom
Next2012:fix_block_gemini_env

Conversation

@Next2012
Copy link
Copy Markdown
Contributor

GeminiCLI can automatically obtain authorization, whether by retrieving the API_KEY from environment variables or by logging in with a Google account. This statement indicates that the extracted GEMINI_API_KEY will override the normal account login, thereby significantly reducing the quota of paid versions (such as Google AI Pro).

…nfig), which will cause google auth account tigger using limit
Copy link
Copy Markdown

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review mode: initial
Major: ACP Gemini env no longer passes hook settings or project dir to Gemini CLI; remote sessions can lose hooks and project context (see inline).
Testing: Not run (automation)

cwd?: string;
}): NodeJS.ProcessEnv {
const env: NodeJS.ProcessEnv = {
return {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[MAJOR] buildGeminiEnv now ignores hookSettingsPath and cwd, so the ACP Gemini process no longer receives GEMINI_CLI_SYSTEM_SETTINGS_PATH or GEMINI_PROJECT_DIR. That disables hook server config and can put remote sessions in the wrong project context (ACP spawn has no cwd). Evidence: cli/src/gemini/utils/config.ts:104-112.

Suggested fix:

export function buildGeminiEnv(opts: {
    model?: string;
    token?: string;
    hookSettingsPath?: string;
    cwd?: string;
}): NodeJS.ProcessEnv {
    const env: NodeJS.ProcessEnv = { ...process.env };

    if (opts.hookSettingsPath) {
        env.GEMINI_CLI_SYSTEM_SETTINGS_PATH = opts.hookSettingsPath;
    }
    if (opts.cwd) {
        env.GEMINI_PROJECT_DIR = opts.cwd;
    }

    return env;
}

Copy link
Copy Markdown
Collaborator

@hqhq1025 hqhq1025 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for identifying the issue — you're right that injecting GEMINI_API_KEY can override Google account login and downgrade quota for paid users (Google AI Pro).

However, the current fix removes all environment variable injection, not just the API key. This breaks two critical features:

1. GEMINI_CLI_SYSTEM_SETTINGS_PATH — hook settings lost

if (opts.hookSettingsPath) {
    env.GEMINI_CLI_SYSTEM_SETTINGS_PATH = opts.hookSettingsPath;
}

Without this, HAPI's hook settings (custom behaviors, permission rules) won't be passed to Gemini CLI. Remote sessions will lose all hook-based customization.

2. GEMINI_PROJECT_DIR — project directory lost

if (opts.cwd) {
    env.GEMINI_PROJECT_DIR = opts.cwd;
}

Without this, Gemini won't know the correct working directory for the session.

3. GEMINI_MODEL — minor, already redundant

The model env var removal is fine because it's already passed via --model CLI arg (line 32 of geminiBackend.ts).

Suggested fix

Only remove the API key injection while keeping the other env vars:

export function buildGeminiEnv(opts: {
    model?: string;
    token?: string;
    hookSettingsPath?: string;
    cwd?: string;
}): NodeJS.ProcessEnv {
    const env: NodeJS.ProcessEnv = {
        ...process.env
    };

    // NOTE: intentionally NOT injecting opts.token into GEMINI_API_KEY.
    // Gemini CLI handles auth on its own (env var or Google account login).
    // Injecting the token would override Google account auth and downgrade
    // quota for paid plans like Google AI Pro.

    if (opts.hookSettingsPath) {
        env.GEMINI_CLI_SYSTEM_SETTINGS_PATH = opts.hookSettingsPath;
    }

    if (opts.cwd) {
        env.GEMINI_PROJECT_DIR = opts.cwd;
    }

    return env;
}

This addresses your concern (no API key override) while preserving hook settings and project directory injection.

The bot review also flagged this:

Major: ACP Gemini env no longer passes hook settings or project dir to Gemini CLI; remote sessions can lose hooks and project context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants