The rule for bivalves has two parts. Before cooking, discard any mussel or oyster that is open and does not close when tapped; it is dead. After cooking, discard any that remain closed; they did not open. Do not pry them open with a knife. The same reasoning applies in both cases: the shell’s behavior is the only direct indication available of the condition of the animal inside.
A live mussel keeps its shell closed; that shows its muscle is working. If you tap a slightly open mussel gently or slide its two shells against each other, it will close within a few seconds if it is alive. If it does not close, it is dead and should be discarded because there is no way to know when it died. Also discard mussels with cracked or broken shells, or ones that feel noticeably too light or too heavy; being too light may indicate that the inside has dried out, while excessive weight may mean the shell is full of sand. The same check applies to oysters, scallops, and all other bivalves, and should never be skipped.
During cooking, heat relaxes the muscle that holds the shells together, and the shells open on their own. This is also a sign that the mussel has been exposed to enough heat. But opening by itself is not a measure of doneness; remove mussels that open early from the pot and cook the remaining ones a little longer, or the first ones to open will become rubbery. Shake the pot a few times during cooking so the mussels at the bottom and top switch places and the heat is distributed evenly. Mussels whose shells have opened by only a few millimeters count as open; waiting for them to open fully will overcook the rest.
Do not force open any mussel that is still closed when cooking is finished. There are two possible reasons: it may already have been dead before cooking, or its muscle may be abnormally strong and it may not have opened. It is impossible to tell the two cases apart from the outside, and this uncertainty itself is the source of the risk. So the rule is simple and nonnegotiable: discard any that do not open. Do not eat a mussel that has been pried open with a knife, because there is no way to know how long it has been dead.
This strict rule comes from how bivalves feed. They filter water and accumulate whatever is in it; as a result, they spoil very quickly, and spoilage does not always show through smell or appearance. For the same reason, with these products, discarding them when in doubt is the only right course. You do not need to discard sound mussels cooked in the same pot; remove only the ones that did not open and eat the rest.
The step that minimizes risk happens when you shop. Buy mussels and oysters alive, from sources you know, and transport them home cold. At home, store them in a ventilated container in the refrigerator, covered with a damp cloth; do not submerge them in water, because they will suffocate in fresh water. Do not seal the bag tightly. It is best to cook them on the day you buy them. Cooked bivalves keep for only a short time in the refrigerator and should not be left at room temperature for more than two hours, or more than one hour above 32°C / 90°F.