Preheat your oven to 350°F (175°C).
Cook the spaghetti according to the package instructions. Drain and set aside.
In a large skillet, melt the butter over medium heat. Add the onions and garlic, and cook until softened.
Add the mushrooms and cook until they release their moisture and start to brown.
Sprinkle the flour over the vegetables and stir to combine. Cook for 1-2 minutes.
Gradually whisk in the chicken broth and heavy cream. Cook, stirring constantly, until the sauce thickens.
Stir in the Parmesan cheese, chicken, peas, salt, and pepper. Cook until heated through.
Combine the sauce with the cooked spaghetti and transfer to a baking dish.
Bake in the preheated oven for 25-30 minutes, until bubbly and golden on top.
Let it cool slightly before serving. Enjoy!