T cell development and selection are coordinated in the thymus by a specialized niche of diverse stromal populations1-3. Although much progress has been made over the years in identifying the functions of the different cell types of the thymic stromal compartment, there is no comprehensive characterization of their diversity and heterogeneity. Here we combined massively parallel single-cell RNA-sequencing4,5, spatial mapping, chromatin profiling and gene targeting to characterize de novo the entire stromal compartment of the mouse thymus. We identified dozens of cell states, with thymic epithelial cells (TECs) showing the highest degree of heterogeneity. Our analysis highlights four major medullary TEC (mTEC I-IV) populations, with distinct molecular functions, epigenetic landscapes and lineage regulators. Specifically, mTEC IV constitutes a new and highly divergent TEC lineage with molecular characteristics of the gut chemosensory epithelial tuft cells. Mice deficient in Pou2f3, a master regulator of tuft cells, have complete and specific depletion of mTEC IV cells, which results in increased levels of thymus-resident type-2 innate lymphoid cells. Overall, our study provides a comprehensive characterization of the thymic stroma and identifies a new tuft-like TEC population, which is critical for shaping the immune niche in the thymus.