Small-molecule signaling in nematode dauer formation has emerged as a major model to study chemical communication in development and evolution. Developmental arrest as nonfeeding and stress-resistant dauer larvae represents the major survival and dispersal strategy. Detailed studies in Caenorhabditis elegans and Pristionchus pacificus revealed that small-molecule communication changes rapidly in evolution resulting in extreme structural diversity of small-molecule compounds. In C. elegans, a blend of ascarosides constitutes the dauer pheromone, whereas the P. pacificus dauer pheromone includes additional paratosides and integrates building blocks from diverse primary metabolic pathways. Despite this complexity of small-molecule structures and functions, little is known about the biosynthesis of small molecules in nematodes outside C. elegans. Here, we show that the genes encoding enzymes of the peroxisomal β-oxidation pathway involved in small-molecule biosynthesis evolve rapidly, including gene duplications and domain switching. The thiolase daf-22, the most downstream factor in C. elegans peroxisomal β-oxidation, has duplicated in P. pacificus, resulting in Ppa-daf-22.1, which still contains the sterol-carrier-protein (SCP) domain that was lost in C. elegans daf-22, and Ppa-daf-22.2. Using the CRISPR/Cas9 system, we induced mutations in both P. pacificus daf-22 genes and identified an unexpected complexity of functional conservation and divergence. Under well-fed conditions, ascaroside biosynthesis proceeds exclusively via Ppa-daf-22.1. In contrast, starvation conditions induce Ppa-daf-22.2 activity, resulting in the production of a specific subset of ascarosides. Gene expression studies indicate a reciprocal up-regulation of both Ppa-daf-22 genes, which is, however, independent of starvation. Thus, our study reveals an unexpected functional complexity of dauer development and evolution.