Bring a large pot of salted water to a boil and cook the spaghetti according to package instructions until al dente; reserve about 1/4 cup of the cooking water before draining.
Heat the olive oil in a non-stick frying pan over medium heat, then add the crushed garlic and chopped anchovy fillets and cook briefly until the garlic just begins to turn golden and the anchovies break down.
Add the canned peeled chopped tomatoes, capers, black olives, half the chopped parsley, and the chopped basil or basil pesto; stir in the chili flakes (or chopped fresh chilli) and simmer for a few minutes.
If the sauce thickens too quickly, add about 1/4 cup of the reserved pasta cooking water to loosen it.
Drain the pasta and add it to the pan with the sauce; toss well over medium heat, adding more pasta water if needed, and cook for a few minutes until the pasta is done to your liking and fully coated in sauce.
Scatter the remaining chopped parsley over the pasta, divide among bowls, and serve with freshly grated Parmesan and optional chopped fresh tomato.