Bring a large pot of salted water to a boil. Add the spaghetti and cook according to the package instructions until al dente. Reserve about ½ cup of the pasta water, then drain the spaghetti in a colander.
In a large skillet, pour in the olive oil and heat it over medium-low heat. You want it warm enough to infuse the garlic without burning it.
Add the sliced garlic to the skillet. Cook gently, stirring frequently, until the garlic is golden and fragrant, about 2-3 minutes. Be careful not to let it brown too much, as burnt garlic can taste bitter.
Once the garlic is ready, add the red pepper flakes to the skillet. Stir to combine, allowing them to sauté for about 30 seconds.
Add the drained spaghetti to the skillet along with the reserved pasta water. Toss everything together until the spaghetti is well coated in the garlic oil.
Remove the skillet from the heat and add in the chopped parsley and basil (if using). Toss again to incorporate. Finally, sprinkle the grated Parmesan cheese over the pasta and give it one last toss to combine.