Bring a large pot of salted water to a boil. Add spaghetti and cook until al dente. Reserve 1/2 cup of pasta water before draining.
While the pasta cooks, heat olive oil in a large pan over medium heat. Add the garlic and red pepper flakes. Sauté until the garlic is fragrant but not brown.
Pour in the crushed tomatoes and stir in olives and capers. Simmer for 10 minutes, letting the flavors meld.
Toss the drained spaghetti into the sauce. If needed, add reserved pasta water to loosen it up. Stir in chopped basil.
Serve immediately with grated parmesan, if using.