Lin et al. reveal that tumor-infiltrating bystander CD8+ T cells are heterogeneous and undergo a TCM-to-TEM-to-TRM differentiation trajectory driven by Treg-derived TGF-β signaling through suppression of KLF2. This mechanism sustains bystander CD8+ T cell heterogeneity and accumulation in tumors and provides a targetable mechanism for cancer immunotherapy.