Annelids have repeatedly evolved symbioses that allow them to colonise extreme ecological niches, like hydrothermal vents and whale falls. Yet, the genetic principles sustaining these symbiotic lifestyles remain unclear. Here we show that different genomic adaptations underpin the symbioses of phylogenetically related annelids with distinct nutritional strategies. While genome compaction and extensive gene losses distinguish the heterotrophic symbiosis of the bone-eating worm Osedax frankpressi, gene gains define the chemoautotrophic symbiosis of deep-sea Vestimentifera. Endosymbionts ultimately compensate most metabolic deficiencies of the host, which include the loss of pathways to recycle nitrogen and synthesise carbohydrates and amino acids enriched in bones in O. frankpressi. Unlike in chemoautotrophic symbioses, innate immunity genes to acquire and control endosymbionts are reduced in O. frankpressi, which, however, has a unique expansion of matrix metalloproteases to digest collagen. Altogether, our study supports that the type of nutritional interaction influences host genome evolution in highly specialized symbioses.