Evidence suggests that a longer version of the saying was circulating prior to the early- to mid-19th century. The meaning is thought to come from the way clams are protected during high tide, and although the connotations have changed slightly, this original concept is still is the heart of the expression today.
First Usage
This phrase is actually a part of the bigger phrase “happy as a clam in high water” or “at high tide.”
Source