For an ocean shipment, it depends -- the shipment will clear U.S. Customs between 5 days before arrival and the time of cargo recovery from port.
For an air shipment, U.S. Customs clearance will happen between uplift on the U.S.-bound plane and the time of cargo recovery from airport terminal.
So, no matter how your shipment is traveling, it's possible that you may see a "Customs cleared" message even before your shipment arrives in the United States.
Clearing your goods prior to arrival at the port helps to ensure any issues can be resolved and your freight is picked up as soon as it's made available by the carrier.
*Disclaimer: U.S. Customs has the right to suspend customs release within 30 days. *