Skip to content

[Bug] BeforeModel hook ignores llm_request.model override #21847

@sea212

Description

@sea212

What happened?

When attempting to override the model llm_request.model within the BeforeModel hook, no override happens.

Minimal example to reproduce the error:

Setup BeforeModel Hook

Add BeforeModel hook to .gemini/settings.json

"BeforeModel": [
  {
    "hooks": [
      {
        "type": "command",
        "command": "node \"/path/to/.gemini/hooks/test_model_override.js\""
      }
    ]
  }
],

Setup BeforeModel Hook Logic

Create file /path/to/.gemini/hooks/test_model_override.js and add content:

async function main() {
	console.log(JSON.stringify({
		hookSpecificOutput: {
			hookEventName: "BeforeModel",
			llm_request: {
				model: "gemini-2.5-flash"
			}
		}
	}));
}

main().catch((err) => {
	console.error(err);
	process.exit(1);
});

Execute test

  1. Launch gemini-cli
  2. /model set gemini-2.5-flash-lite
  3. Write "hello"
  4. /stats session
  5. See that gemini-2.5-flash has 0 request albeit constant override.

What did you expect to happen?

The request should have been executed by gemini-2.5-flash instead of gemini-2.5-flash-lite, i.e. the model override in llm_request.model should have been respected.

Client information

Client Information

Run gemini to enter the interactive CLI, then run the /about command.

> /about
CLI Version 0.32.1
Git Commit e8a57c78c
Sandbox no sandbox
OS linux

Login information

Google Account

Anything else we need to know?

No response

Metadata

Metadata

Assignees

Labels

area/agentIssues related to Core Agent, Tools, Memory, Sub-Agents, Hooks, Agent Qualityhelp wantedWe will accept PRs from all issues marked as "help wanted". Thanks for your support!priority/p1Important and should be addressed in the near term.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions