During their lifetime, animals must adapt their behavior to survive in changing environments. This ability requires the nervous system to adjust through dynamic expression of neurotransmitters and receptors but also through growth, spatial reorganization and connectivity while integrating external stimuli. For instance, despite having a fixed neuronal cell lineage, the nematode Caenorhabditis elegans’ nervous system remains plastic throughout its development. Here, we focus on a specific example of nervous system plasticity, the C. elegans dauer exit decision. Under unfavorable conditions, larvae will enter the non-feeding and non-reproductive dauer stage and adapt their behavior to cope with a new environment. Upon improved conditions, this stress resistant developmental stage is actively reversed to resume reproductive development. However, how different environmental stimuli regulate the exit decision mechanism and thereby drive the larva’s behavioral change is unknown. To fill this gap, we developed a new open hardware method for long-term imaging (12h) of C. elegans larvae. We identified dauer-specific behavioral motifs and characterized the behavioral trajectory of dauer exit in different environments to identify key decision points. Combining long-term behavioral imaging with transcriptomics, we find that bacterial ingestion triggers a change in neuropeptide gene expression to establish post-dauer behavior. Taken together, we show how a developing nervous system can robustly integrate environmental changes, activate a developmental switch and adapt the organism’s behavior to a new environment.