Preheat the oven to 375°F (190°C). Lightly grease a 9 × 13-inch baking dish with butter or cooking spray. Bring a large pot of salted water to a boil. Add the trimmed green beans and cook for 4–5 minutes, until they become bright green and slightly tender but still have a little crunch.
Drain the green beans and immediately rinse them under cold water to stop the cooking process. Set aside.
Melt the butter in a large skillet over medium heat. Add the sliced mushrooms and cook for 5–7 minutes, stirring occasionally, until they release their moisture and develop lightly golden edges.
Add the minced garlic and cook for another 30 seconds, just until fragrant.
Sprinkle the flour over the mushrooms and stir well to coat everything evenly. Cook for about 1 minute to remove the raw flour taste.
Gradually pour in the milk, heavy cream, and broth while whisking continuously to prevent lumps. Add the Worcestershire sauce, salt, black pepper, onion powder, and dried thyme.
Simmer for 3–5 minutes, stirring frequently, until the sauce becomes smooth and thick enough to coat the back of a spoon.
Add the blanched green beans to the creamy mushroom sauce. Stir gently until all the beans are evenly coated.
Fold in ½ cup of crispy fried onions and the Parmesan cheese, if using. Transfer the mixture to the prepared baking dish and spread it into an even layer.
Place the baking dish in the preheated oven and bake uncovered for 15 minutes, allowing the sauce to bubble and the flavors to come together.
Remove the casserole from the oven and sprinkle the remaining 1 cup of crispy fried onions evenly over the top.
Return it to the oven and bake for another 8–10 minutes, until the topping is golden brown and crispy and the casserole is bubbling around the edges.
Remove the homemade green bean casserole from the oven and let it rest for 5 minutes before serving. This gives the creamy sauce a little time to settle.
Serve warm with your favorite holiday dishes or a comforting weeknight dinner.