Finely chop onion and scrub clams In a 5- to 6-quart heavy kettle heat oil over moderate heat until hot but not smoking and cook onion and gingerroot, stirring occasionally, until lightly browned, 5 to 6 minutes.
Add spices and salt and cook, stirring, until fragrant, about 1 minute.
Add coconut milk and bring to a gentle boil.
Add clams and boil mixture gently, covered, stirring occasionally, until clams are opened, 6 to 8 minutes. (Discard any unopened clams.)
Serve clams in bowls with cooking liquid and sprinkle with lime juice, cilantro, and grated coconut.