Preheat the oven to 400°F (200°C).
In a large skillet, melt the butter over medium heat. Add the onion and garlic, and sauté until translucent and fragrant, about 3–4 minutes.
Toss in the mushrooms and cook until they release their moisture and start to brown, about 5–7 minutes.
Sprinkle the flour over the vegetables and stir to coat. Cook for about 1 minute to remove the raw flour taste.
Pour in the chicken broth and milk (or cream), stirring constantly as the sauce thickens. Add the thyme, salt, and pepper to taste.
Fold in the cooked chicken and peas (if using). Allow the mixture to simmer gently for 3–5 minutes, until everything is heated through and the sauce is creamy.
Transfer the filling to a suitable baking dish. Cover with puff pastry or pie crust, trimming any excess. Make a few small slits in the top to vent steam.
Bake for 20–25 minutes, or until the pastry is golden brown and crisp. If the edges brown too quickly, cover with a foil shield and continue baking.
Let the pot pie rest for about 10 minutes before serving. This helps the sauce set a bit and makes it easier to slice.