Longitudinal calcium imaging in the medial prefrontal cortex reveals the emergence of de novo task representations and reward-associated replay.