Preheat the oven to 375°F (190°C) and bring a large pot of salted water to a boil for the pasta.
In a large skillet, heat the olive oil over medium heat. Add the onion and garlic; sauté until translucent and fragrant, about 3–4 minutes.
Add the sliced mushrooms to the skillet and cook until they release their moisture and begin to brown, 5–7 minutes. Season lightly with salt and pepper.
In a separate saucepan, melt the butter over medium heat. Whisk in the flour to form a light roux and cook for 1–2 minutes, stirring constantly.
Gradually whisk in the chicken broth and heavy cream, creating a smooth sauce. Bring to a gentle simmer and cook until it thickens, about 3–5 minutes. Stir in half of the Parmesan and the mozzarella until melted and glossy. Season with salt and pepper to taste.
Add the shredded chicken, peas (if using), and the mushroom mixture to the sauce. Stir to combine and warm through.
Cook the spaghetti in the boiling water until just shy of al dente. Drain and reserve a splash of the pasta water in case you need to loosen the sauce.
Toss the hot pasta with the chicken and mushroom sauce until evenly coated. If the mixture seems too thick, add a tablespoon or two of the reserved pasta water to loosen.
Transfer the mixture to a greased baking dish. Sprinkle with the remaining Parmesan and the shredded mozzarella.
Bake in the preheated oven for 15–20 minutes, until the top is bubbly and golden. If you like a darker crust, broil for an additional 1–2 minutes, keeping a close eye on it.
Garnish with chopped fresh parsley and serve hot, with a simple green salad or steamed broccoli on the side if you like.