Preheat your oven to 375°F (190°C). Bring a pot of water to a boil, then add the green beans and cook for 4–5 minutes until they’re just tender but still bright green. Drain and rinse under cold water to stop the cooking process.
In a large skillet, heat olive oil and butter over medium heat. Add the chopped onions and cook until soft and translucent, about 4 minutes. Stir in the garlic and mushrooms, and cook until the mushrooms release their juices and begin to brown, around 6–8 minutes.
Sprinkle the flour over the mushroom mixture and stir well, cooking for 1–2 minutes. Slowly pour in the chicken broth while whisking to prevent lumps. Then add the cream, salt, pepper, and nutmeg. Simmer until the sauce thickens, about 3–4 minutes. Stir in the shredded cheese, if using, and let it melt into the sauce.
Add the blanched green beans into the skillet with the sauce and stir to combine. Pour the whole mixture into your baking dish and smooth it out with a spoon or spatula.
Sprinkle 1 cup of the crispy fried onions evenly over the top. Reserve the rest for later. This layer adds that irresistible crunch and golden finish.
Bake the casserole for 20–25 minutes, or until it’s bubbling and golden on top. Remove from the oven, sprinkle the remaining ½ cup of crispy onions on top, and return to the oven for another 5 minutes to crisp them up.