A pervasive challenge in microbial ecology is understanding the genetic level where ecological units can be differentiated. Ecological differentiation often occurs at fine genomic levels, yet it is unclear how to utilise ecological information to define ecotypes given the breadth of environmental variation among microbial taxa. Here, we present an analytical framework that infers clusters along genome‐based microbial phylogenies according to shared environmental responses. The advantage of our approach is the ability to identify genomic clusters that best fit complex environmental information whilst characterising cluster niches through model predictions. We apply our method to determine climate‐associated ecotypes in populations of nitrogen‐fixing symbionts using whole genomes, explicitly sampled to detect climate differentiation across a heterogeneous landscape. Although soil and plant host characteristics strongly influence distribution patterns of inferred ecotypes, our flexible statistical method enabled us to identify climate‐associated genomic clusters using environmental data, providing solid support for ecological specialisation in soil symbionts.