Preheat the oven to 375 F. Cook the pasta in salted water until al dente, then drain and set aside. If you plan to bake the dish, reserving a cup of pasta water helps loosen the sauce later.
In a large skillet, heat olive oil over medium heat. Add the onions and mushrooms, cooking until they release their moisture and start to brown, about 5 to 7 minutes. Stir in the garlic and cook for another 30 seconds until fragrant.
Push vegetables to the side and melt butter in the skillet. Sprinkle in the flour, whisking constantly to make a light roux for about 1 minute.
Slowly whisk in milk and cream, then stir in white wine if using. Cook until the sauce thickens and coats the back of a spoon, about 3 to 5 minutes.
Stir in the parmesan cheese, thyme, salt, and pepper. Fold in the shredded chicken and half of the torn mozzarella, letting the cheese melt into the sauce.
Add the cooked pasta to the sauce and toss to combine. If the mixture seems thick, add a splash of pasta water or more milk to reach a creamy consistency.
Transfer the mixture to a baking dish. Top with the remaining mozzarella and a light dusting of extra parmesan if you like a crisp, bubbly top.
Bake for 15 to 20 minutes until the cheese is melted and golden in spots. For a more golden top, broil for an additional 1 to 2 minutes watching carefully to prevent burning.
Let the dish rest for 5 minutes before serving. This helps the sauce set slightly and makes serving easier.