Preheat your oven to 350°F (175°C).
Cook the spaghetti according to the package instructions until al dente. Drain and set aside.
In a large skillet, heat the olive oil over medium heat. Add the chopped onion and minced garlic, sautéing until they are soft and fragrant, about 3-4 minutes.
Add the sliced mushrooms and cook for an additional 4-5 minutes until they're tender.
Stir in the cooked chicken, frozen peas, chicken broth, heavy cream, dried thyme, salt, and pepper. Bring to a simmer and let it cook for about 5 minutes.
In a large mixing bowl, combine the cooked spaghetti with the chicken and mushroom mixture. Mix well to combine.
Pour the mixture into a greased baking dish. Top with shredded cheddar cheese, grated Parmesan cheese, and breadcrumbs if using.
Bake in the preheated oven for 25-30 minutes, or until the top is golden and bubbly.
Remove from the oven and let it cool for a few minutes before serving.