We develop an algorithmic framework for graph colouring that reduces the problem to verifying a local probabilistic property of the independent sets. With this we give, for any fixed k ≥ 3 and ε > 0, a randomised polynomial-time algorithm for colouring graphs of maximum degree ∆ in which each vertex is contained in at most t copies of a cycle of length k, where 1/2 ≤ t ≤ ∆^(2ε / (1+2ε)) / (log ∆) 2 , with (1 + ε)∆/ log(∆/ √ t) colours. This generalises and improves upon several notable results including those of Kim (1995) and Alon, Krivelevich and Sudakov (1999), and more recent ones of Molloy (2019) and Achlioptas, Iliopoulos and Sinclair (2019). This bound on the chromatic number is tight up to an asymptotic factor 2 and it coincides wit...