Boil the pasta: Bring a large pot of salted water to a rolling boil. Add the spaghetti and cook until al dente according to the package directions.
Reserve 1 cup of pasta water, then drain.
Sauté the tomatoes: While the pasta cooks, warm the olive oil in a large skillet over medium heat. Add the garlic and cook for 30 seconds, just until fragrant.
Blister and season: Add the cherry tomatoes and a pinch of salt. Cook, stirring occasionally, until the tomatoes soften and some begin to burst, 5–7 minutes.
Add red pepper flakes if using.
Build the sauce: Lower the heat. Stir in the pesto along with a splash of reserved pasta water to loosen it. You want a silky, glossy sauce that will coat the noodles.
Toss the pasta: Add the drained spaghetti to the skillet.
Toss well, adding more pasta water as needed until the sauce clings to the strands.
Finish with brightness: Grate in a little lemon zest and add a small squeeze of juice. Sprinkle in the Parmesan and toss again until melted and creamy. Taste and adjust salt and pepper.
Garnish and serve: Remove from heat.
Top with torn basil leaves, a drizzle of olive oil, and extra Parmesan. Serve hot.