diff --git a/src/ucode/cli.py b/src/ucode/cli.py index 5b92495b..287181a9 100644 --- a/src/ucode/cli.py +++ b/src/ucode/cli.py @@ -2877,7 +2877,7 @@ def claude_cmd( claude_agent.disable_smart_routing(load_state()) print_success("Claude Code smart routing disabled; ug routing hooks removed") return - if enable_model_discovery or (model_location is not None and provider is None): + if enable_model_discovery or model_location is not None or provider is not None: os.environ[claude_agent.GATEWAY_MODEL_DISCOVERY_ENV_VAR] = "1" with _smart_routing_v2_flag(enable_smart_routing_flag): with _disable_smart_routing_for_subcommand("claude", ctx): diff --git a/tests/test_cli.py b/tests/test_cli.py index 1002d936..c138a160 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -692,6 +692,15 @@ def test_claude_model_location_is_forwarded(self): assert mock_launch.call_args.args[1].args == [] assert os.environ["ENABLE_CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY"] == "1" + def test_claude_provider_enables_model_discovery(self): + with patch("ucode.cli._launch_tool") as mock_launch: + result = runner.invoke(app, ["claude", "--provider", "main.default.anthropic"]) + + assert result.exit_code == 0, result.output + assert mock_launch.call_args.kwargs["provider"] == "main.default.anthropic" + assert mock_launch.call_args.args[1].args == [] + assert os.environ["ENABLE_CLAUDE_CODE_GATEWAY_MODEL_DISCOVERY"] == "1" + def test_codex_model_location_is_forwarded(self): with patch("ucode.cli._launch_tool") as mock_launch: result = runner.invoke(app, ["codex", "--model-location", "main.default"])