Bring a large pot of salted water to a rolling boil and cook the spaghetti according to package instructions until just shy of al dente, reserving about 1 cup (240 ml) of the pasta cooking water before draining.
While the pasta cooks, heat the olive oil in a non-stick frying pan over medium heat.
Add the crushed or finely chopped garlic and chopped anchovy fillets to the pan and cook briefly, stirring, until the garlic just begins to turn golden and the anchovies have mostly dissolved into the oil.
Stir in the tinned chopped tomatoes, capers, black olives, half the chopped parsley, the chopped basil or basil pesto, and the chili flakes or fresh chili.
Simmer the sauce for a few minutes to combine flavors; if it thickens too quickly, add about 1/4 cup of the reserved pasta water and stir.
Drain the pasta, reserving more cooking water if needed, and add the pasta directly to the sauce. Toss thoroughly, adding extra pasta water a little at a time to loosen the sauce until the pasta is cooked to your liking and evenly coated.
Scatter the remaining parsley over the pasta, transfer to bowls, and serve with freshly grated Parmesan and optional chopped fresh tomato.