Herbivore insects acquire microorganisms from host plants or soil, but it remains unclear how the diversity and functional composition of host plants contribute to structuring herbivore microbiomes. Within a controlled tree-diversity setting, we used DNA metabarcoding of 16S rRNA to assess the contribution of Lepidoptera species and their local environment (particularly, tree diversity, host tree species, and leaf traits) to the composition of associated bacterial communities. In total, we obtained 7,909 bacterial OTUs from 634 caterpillar individuals comprising 146 species. Tree diversity was found to drive the diversity of caterpillar-associated bacteria both directly, and indirectly via effects on caterpillar communities, and tree diversity was a stronger predictor of bacterial diversity than diversity of caterpillars. Leaf toughness and dry matter content were important traits of the host plant determining bacterial species composition, while leaf calcium and potassium concentration influenced bacterial richness. Our study reveals previously unknown linkages between trees and their characteristics, herbivore insects, and their associated microbes, which contributes to developing a more nuanced understanding of functional dependencies between herbivores and their environment, and has implications for the consequences of plant diversity loss for trophic interactions.