Aims. We present a new sub-grid model, HYACINTH – HYdrogen And Carbon chemistry in the INTerstellar medium in Hydro simulations – for computing the non-equilibrium abundances of H2 and its carbon-based tracers, namely CO, C, and C+, in cosmological simulations of galaxy formation. Methods. The model accounts for the unresolved density structure in simulations using a variable probability distribution function of sub-grid densities and a temperature-density relation. Included is a simplified chemical network that has been tailored for hydrogen and carbon chemistry within molecular clouds and easily integrated into large-scale simulations with minimal computational overhead. As an example, we applied HYACINTH to a simulated galaxy at redshift z ~ 2.5 in post-processing and compared the resulting abundances with observations. Results. The chemical predictions from HYACINTH are in reasonable agreement with high-resolution molecular-cloud simulations at different metallicities. By post-processing a galaxy simulation with HYACINTH, we reproduced the H I − H2 transition as a function of the hydrogen column density NH for both Milky-Way-like and Large-Magellanic-Cloud-like conditions. We also matched the NCO versus NH2 relation inferred from absorption measurements towards Milky-Way molecular clouds, although most of our post-processed regions occupy the same region as (optically) dark molecular clouds in the NCO – NH2 plane. Column density maps reveal that CO is concentrated in the peaks of the H2 distribution, while atomic carbon more broadly traces the bulk of H2 in our post-processed galaxy. Based on both the column density maps and the surface density profiles oŕ the different gas species in the post-processed galaxy, we find that C+ maintains a substantially high surŕace density out to ~10 kpc as opposed to other components that exhibit a higher central concentration. This is similar to the extended [C II] emission ŕound in some recent observations at high redshifts.