Background Lichens are symbiotic organisms composed of a fungus and a photosynthetic partner, which are key ecological bioindicators due to their sensitivity to environmental changes. The endolichenic fungi (ELF) living inside lichen thalli, are an important but understudied component of playing crucial ecological roles such as nutrient cycling and protection against environmental stressors. Therefore ELF community investigation is vital for fostering sustainable ecosystems and leveraging their ecological benefits. Deciphering the intricate relationships between ELF and their lichen hosts, alongside the influence of environmental factors on these communities, presents a significant challenge in pinpointing the underlying drivers of community structure and diversity.Results Our research demonstrated that locational factors were the main drivers of the ELF community structure, rather than host haplotype. Several climatic factors affected the diversity of the ELF community and contributed to the prevalence of different types of fungal residents within the ELF community. A decrease in isothermality was associated with a greater prevalence of pathotrophic and saprotrophic fungi within the ELF community, resulting in an overall increase in community diversity. By conducting a structural equation modeling analysis, we identified a robust link between climatic variables, fungal trophic mode abundance, and the species diversity of the ELF community.Conclusion This study's discoveries emphasize the significance of examining climate-related factors when investigating ELF's structure and function. The connection between fungi and climate is intricate and complex, and can be influenced by various other factors. Investigating the potential for ELF to adapt to changing climatic conditions, as well as the potential effects of changes in ELF communities on lichen function, would be valuable research areas. We anticipate that our research results will establish a basis for numerous future ELF research projects and have a significant impact on the field.