The COnstrain Dark Energy with X-ray clusters (CODEX) sample contains the largest flux limited sample of X-ray clusters at 0.35 < z < 0.65. It was selected from ROSAT data in the 10 000 square degrees of overlap with BOSS, mapping a total number of 2770 high-z galaxy clusters. We present here the full results of the CFHT CODEX programme on cluster mass measurement, including a reanalysis of CFHTLS Wide data, with 25 individual lensing-constrained cluster masses. We employ lensfit shape measurement and perform a conservative colour–space selection and weighting of background galaxies. Using the combination of shape noise and an analytic covariance for intrinsic variations of cluster profiles at fixed mass due to large-scale structure, miscentring, and variations in concentration and ellipticity, we determine the likelihood of the observed shear signal as a function of true mass for each cluster. We combine 25 individual cluster mass likelihoods in a Bayesian hierarchical scheme with the inclusion of optical and X-ray selection functions to derive constraints on the slope α, normalization β, and scatter σln λ|μ of our richness–mass scaling relation model in log-space: ${\langle {\rm In}\,\, \lambda\!\!\mid\!\!\mu\rangle = \alpha\mu + \beta,} $ with μ = ln (M200c/Mpiv), and Mpiv = 1014.81M⊙. We find a slope $\alpha = 0.49^{+0.20}_{-0.15}$, normalization $\exp (\beta) = 84.0^{+9.2}_{-14.8}$, and $\sigma _{\ln \lambda | \mu } = 0.17^{+0.13}_{-0.09}$ using CFHT richness estimates. In comparison to other weak lensing richness–mass relations, we find the normalization of the richness statistically agreeing with the normalization of other scaling relations from a broad redshift range (0.0 < z < 0.65) and with different cluster selection (X-ray, Sunyaev–Zeldovich, and optical).