Heat the olive oil in a large skillet over medium heat.
Add the minced garlic and diced onion and sauté for 3–5 minutes until softened and fragrant.
Add the whole peeled tomatoes with their juice, breaking the tomatoes up slightly with a spoon; season with salt, freshly ground black pepper, and crushed red pepper flakes if using.
Bring the sauce to a gentle simmer and cook for about 20 minutes to concentrate the flavors, stirring occasionally.
Meanwhile, bring a large pot of salted water to a boil and cook the spaghetti until al dente, about 8–10 minutes; reserve 1/2 cup of the pasta cooking water, then drain the pasta.
Stir the chopped basil into the sauce, then add the drained spaghetti to the skillet and toss to combine, adding reserved pasta water a little at a time to loosen the sauce if needed.
Divide the spaghetti among plates, garnish with extra basil, and serve with grated Parmesan if desired.