Rinse the cockles or clams thoroughly, making sure no sand remains. Set aside.
Bring a large pot of water to a boil. Add the spaghetti and salt and cook according to the package instructions until al dente. Drain and set aside in a large serving bowl or pasta pot.
Meanwhile, coat the bottom of a large, heavy saucepan or Dutch oven with the olive oil. Add the garlic and heat the pan over low, stirring frequently, until the garlic just starts to turn golden, about 3 minutes.
Add the cockles and wine and cover the pan. Steam until the shells open, about 8 minutes, discarding any that do not open. (You can continue to cook the unopened ones for a few more minutes because some may take a little longer.)
Gently spoon the open cockles in their shells and the cooking liquid over the pasta in the reserved bowl or pot.
Add the parsley and gently toss until the pasta is thoroughly coated with the broth. Sprinkle with pepper flakes if desired.
Divide the pasta between 4 shallow bowls and top with the cockles in their shells and a few spoonfuls of broth. Serve immediately.