
Cook the pasta according to package instructions in salted water until al dente. Drain and set aside, reserving a bit of the pasta water.
In a large pan, heat the olive oil over medium. Add the chopped onion and sauté. Add the minced garlic and saute for 3-5 minutes until the onion is translucent. Add pepper flakes (if using) and sauté for another minute until fragrant.
Reduce the heat to low and add the pesto to the pan, stirring well to combine.
Add the cooked pasta to the pan, tossing to coat with the pesto mixture. If the pasta seems dry, add a bit of reserved pasta water for the desired consistency.
Season with salt and pepper to taste. Serve hot and top with freshly grated Parmesan cheese.