The diet of coconut crabs consists primarily of fleshy fruits (particularly Ochrosia ackeringae, Arenga listeri, Pandanus elatus, P. christmatensis); nuts (Aleurites moluccanus), drupes (Cocos nucifera) and seeds (Annona reticulata);[44] and the pith of fallen trees.[45] However, as they are omnivores, they will consume other organic materials such as tortoise hatchlings and dead animals.[18][46] They have been observed to prey upon crabs such as Gecarcoidea natalis and Discoplax hirtipes, as well as scavenge on the carcasses of other coconut crabs.[44] During a tagging experiment, one coconut crab was observed killing and eating a Polynesian rat (Rattus exulans).[47] In 2016, a large coconut crab was observed climbing a tree to disable and consume a red-footed booby on the Chagos Archipelago.[48][49]
The coconut crab can take a coconut from the ground and cut it to a husk nut, take it with its claw, climb up a tree 10 m (33 ft) high and drop the husk nut, to access the coconut flesh inside.[50] They often descend from the trees by falling, and can survive a fall of at least 4.5 m (15 ft) unhurt.[51] Coconut crabs cut holes into coconuts with their strong claws and eat the contents, although it can take several days before the coconut is opened.[45]
Thomas Hale Streets discussed the behaviour in 1877, doubting that the animal would climb trees to get at the coconuts.[43] In the 1980s, Holger Rumpf was able to confirm Streets' report, observing and studying how they open coconuts in the wild.[45] The animal has developed a special technique to do so; if the coconut is still covered with husk, it will use its claws to rip off strips, always starting from the side with the three germination pores, the group of three small circles found on the outside of the coconut. Once the pores are visible, the coconut crab bangs its pincers on one of them until it breaks. Afterwards, it turns around and uses the smaller pincers on its other legs to pull out the white flesh of the coconut. Using their strong claws, larger individuals can even break the hard coconut into smaller pieces for easier consumption.[52]