Galaxy clusters are usually detected in blind optical surveys via suitable filtering methods. We present an optimal matched filter which maximizes their signal-to-noise ratio by taking advantage of the knowledge we have of their intrinsic physical properties and of the data noise properties. In this paper we restrict our application to galaxy magnitudes, positions and photometric redshifts if available, and we also apply the filter separately to weak lensing data. The method is suitable to be naturally extended to a multi-band approach which could include not only additional optical bands but also observables with different nature such as X-rays. For each detection, the filter provides its significance, an estimate for the richness and for the redshift even if photo-z are not given. The provided analytical error estimate is tested against numerical simulations. We finally apply our method to the COSMOS field and compare the results with previous cluster detections obtained with different methods. Our catalogue contains 27 galaxy clusters with minimal threshold at 3σ level including both optical and weak-lensing information.