Cook the spaghetti according to package instructions in a large pot of salted boiling water until al dente. Reserve 1/2 cup of pasta water, then drain the spaghetti.
In a large skillet, heat the olive oil over medium heat. Add the minced garlic and sauté for about 1 minute until fragrant, being careful not to burn it.
Add the cooked spaghetti to the skillet along with the chopped basil, lemon zest, and lemon juice. Toss to combine, adding reserved pasta water a little at a time until the desired consistency is reached.
Season with red pepper flakes (if using), salt, and pepper to taste. Toss again to mix well.
Serve immediately, topped with grated Parmesan cheese if desired.