The detection of galaxy clusters in present and future surveys enables measuring mass-to-light ratios, clustering properties, galaxy cluster abundances and, therefore, constraining cosmological parameters. We present a new technique for detecting galaxy clusters, which is based on the matched filter algorithm from a Bayesian point of view. The method is able to determine the position, redshift and richness of the cluster through the maximization of a filter depending on galaxy luminosity, density and photometric redshift combined with a galaxy cluster prior that accounts for colour–magnitude relations and brightest cluster galaxy–redshift relation. We tested the algorithm through realistic mock galaxy catalogues, revealing that the detections are 100 per cent complete and 80 per cent pure for clusters up to z < 1.2 and richer than ΛCL > 20 (Abell richness ∼0, M∼ 4 × 1014 M⊙). The completeness and purity remain approximately the same if we do not include the prior information, implying that this method is able to detect galaxy cluster with and without a well-defined red sequence. We applied the algorithm to the Canada–France–Hawaii Telescope Legacy Survey (CFHTLS) Archive Research Survey data, recovering similar detections as previously published using the same or deeper data plus additional clusters which appear to be real.