The association between mental illness and all-cause mortality (adjusted for age, sex, year of ART initiation, treatment programme, and CD4 cell count and WHO clinical stage at ART initiation) was greater (aHR 3·49 [95% CI 3·09–3·94]) in sensitivity analysis, when we considered patients to be affected by mental illness (exposed) for 1 year after each mental health treatment (ie, dispensing of psychiatric medication or hospital admission for mental disorder) and as unexposed thereafter. Here, CD4 is linked to mental disorder.