Preheat oven to 375°F (190°C) and lightly grease a baking dish.
Heat butter or oil in a large skillet over medium heat. Add mushrooms and cook until they release moisture and begin to brown.
Add onion and cook until softened, then stir in garlic and cook for 30 seconds.
Pour in cream and simmer gently for 2–3 minutes.
Stir in cheese until melted and smooth. Season with salt, pepper, and herbs if using.
Transfer mixture to the prepared baking dish and spread evenly.
Bake uncovered for 25–30 minutes, until bubbly and lightly golden on top.
Let rest for 5 minutes before serving.