Cook the spaghetti in salted water according to package instructions. Reserve 1/2 cup of pasta water, then drain the pasta.
In a large skillet, heat olive oil over medium heat. Add minced garlic and red pepper flakes, cooking until fragrant.
Stir in capers, anchovies (if using), and olives. Cook for 2 minutes to blend flavors.
Pour in the crushed tomatoes and bring to a simmer. Cook for 10 minutes, stirring occasionally.
Season the sauce with salt and pepper, then toss the cooked spaghetti in the skillet with the sauce.
If needed, add reserved pasta water to achieve the desired consistency.
Serve warm, garnished with fresh parsley.