X-ray clusters are conventionally divided into two classes: ‘cool core’ (CC) clusters and ‘non-cool core’ (NCC) clusters. Yet relatively little attention has been given to the origins of this apparent dichotomy and, in particular, to the energetics and thermal histories of the two classes. We develop a model for the entropy profiles of clusters starting from the configuration established by gravitational shock heating and radiative cooling. At large radii, gravitational heating accounts for the observed profiles and their scalings well. However, at small and intermediate radii, radiative cooling and gravitational heating cannot be combined to explain the observed profiles of either CC or NCC clusters. The inferred entropy profiles of NCC clusters require that material is ‘pre-heated’ prior to cluster collapse in order to explain the absence of low-entropy (cool) material in these systems. We show that a similar modification is also required in CC clusters in order to match their entropy profiles at intermediate radii. In CC clusters, this modification is unstable, and an additional process is required to prevent cooling below a temperature of a few keV. We show that this can be achieved by adding a self-consistent active galactic nuclei (AGN) feedback loop in which the lowest entropy, most rapidly cooling material is heated and rises buoyantly to mix with material at larger radii. The resulting model does not require fine-tuning and is in excellent agreement with a wide variety of observational data from Chandra and XMM–Newton, including entropy and gas density profiles, the luminosity–temperature relation and high-resolution spectra. The spread in cluster core morphologies is seen to arise because of the steep dependence of the central cooling time on the initial level of pre-heating. Some of the other implications of this model are briefly discussed.