ABSTRACT The E-isomer of cyanomethanimine (HNCHCN) was first identified in Sagittarius B2(N) (Sgr B2(N)) by a comparison of the publicly available Green Bank Telescope (GBT) PRIMOS survey with laboratory rotational spectra. Recently, Z-cyanomethanimine was detected in the quiescent molecular cloud G+0.693−0.027 with the IRAM 30-m telescope. Cyanomethanimine is a chemical intermediate in the proposed synthetic routes of adenine, and may play an important role in forming biological molecules in the interstellar medium. Here we present a new modelling study of cyanomethanimine, using the nautilus gas–grain reaction network and code with the addition of over 400 chemical reactions of the three cyanomethanimine isomers and related species. We apply cold isothermal core, hot core, and C-type shock models to simulate the complicated and heterogeneous physical environment in and in front of Sgr B2(N), and in G+0.693−0.027. We identify the major formation and destruction routes of cyanomethanimine, and find that the calculated abundances of the cyanomethanimine isomers and the ratio of Z-isomer to E-isomer are both in reasonable agreement with observations for selected environments. In particular, we conclude that these isomers are most likely formed within or near the hot core without the impact of shocks, or in the cold regions with shocks.