Preheat the oven to 375°F and grease a 9×13 baking dish.
Bring a large pot of salted water to a boil. Add the green beans and cook for 4 to 5 minutes, just until bright green and slightly tender. Drain and set aside.
In a large skillet, melt the butter over medium heat. Add the sliced onions and cook, stirring often, until softened and golden, about 20 to 25 minutes.
Add the garlic and cook for about 30 seconds, just until fragrant.
Sprinkle in the flour, salt, and pepper, then stir well to coat the onions.
Slowly pour in the chicken broth and heavy cream, stirring until smooth. Simmer for 2 to 3 minutes, until slightly thickened.
Add the green beans and half of the Gruyère, then stir until combined.
Transfer the mixture to the prepared baking dish and top with the remaining Gruyère and the croutons.
Bake for 20 to 25 minutes, until hot and bubbly and the topping is lightly golden.