A significant proportion of people with clozapine-treated schizophrenia develop 'checking' compulsions, a phenomenon yet to be understood. To use habit formation models developed in cognitive neuroscience to investigate the dynamic interplay between psychosis, clozapine dose and obsessive-compulsive symptoms (OCS). Using the anonymised electronic records of a cohort of clozapine-treated patients, including longitudinal assessments of OCS and psychosis, we performed longitudinal multi-level mediation and multi-level moderation analyses to explore associations of psychosis with obsessiveness and excessive checking. Classic bivariate correlation tests were used to assess clozapine load and checking compulsions. The influence of specific genetic variants was tested in a subsample. A total of 196 clozapine-treated individuals and 459 face-to-face assessments were included. We found significant OCS to be common (37.9%), with checking being the most prevalent symptom. In mediation models, psychosis severity mediated checking behaviour indirectly by inducing obsessions (r = 0.07, 95% CI 0.04-0.09; P < 0.001). No direct effect of psychosis on checking was identified (r = -0.28, 95% CI -0.09 to 0.03; P = 0.340). After psychosis remission (n = 65), checking compulsions correlated with both clozapine plasma levels (r = 0.35; P = 0.004) and dose (r = 0.38; P = 0.002). None of the glutamatergic and serotonergic genetic variants were found to moderate the effect of psychosis on obsession and compulsion (SLC6A4, SLC1A1 and HTR2C) survived the multiple comparisons correction. We elucidated different phases of the complex interplay of psychosis and compulsions, which may inform clinicians' therapeutic decisions.