Collective behaviour, arising from local interactions, allows groups to respond to changing conditions. Long-term studies have shown that the traits of individual mammals and birds are associated with their reproductive success, but little is known about the evolutionary ecology of collective behaviour in natural populations. An ant colony operates without central control, regulating its activity through a network of local interactions. This work shows that variation among harvester ant (Pogonomyrmex barbatus) colonies in collective response to changing conditions is related to variation in colony lifetime reproductive success in the production of offspring colonies. Desiccation costs are high for harvester ants foraging in the desert. More successful colonies tend to forage less when conditions are dry, and show relatively stable foraging activity when conditions are more humid. Restraint from foraging does not compromise a colony's long-term survival; colonies that fail to forage at all on many days survive as long, over the colony's 20-30-year lifespan, as those that forage more regularly. Sensitivity to conditions in which to reduce foraging activity may be transmissible from parent to offspring colony. These results indicate that natural selection is shaping the collective behaviour that regulates foraging activity, and that the selection pressure, related to climate, may grow stronger if the current drought in their habitat persists.