Humans and animals have a remarkable capacity to collectively coordinate their behavior to respond to environmental challenges. However, the underlying neurobiology remains poorly understood. Here, we found that groups of mice self-organize into huddles at cold ambient temperature during the thermal challenge assay. We found that mice make active (self-initiated) and passive (partner-initiated) decisions to enter or exit a huddle. Using microendoscopic calcium imaging, we found that active and passive decisions are encoded distinctly within the dorsomedial prefrontal cortex (dmPFC). Silencing dmPFC activity in some mice reduced their active decision-making, but also induced a compensatory increase in active decisions by non-manipulated partners, conserving the group's overall huddle time. These findings reveal how collective behavior is implemented in neurobiological mechanisms to meet homeostatic needs during environmental challenges.