We construct a linear filter optimised for detecting dark-matter halos in weak-lensing data. The filter assumes a mean radial profile of the halo shear pattern and modifies that shape by the noise power spectrum. Aiming at separating dark-matter halos from spurious peaks caused by large-scale structure lensing, we model the noise as being composed of weak lensing by large-scale structures and Poisson noise from random galaxy positions and intrinsic ellipticities. Optimal filtering against the noise requires the optimal filter scale to be smaller than typical halo sizes. Although a perfect separation of halos from spurious large-scale structure peaks is strictly impossible, we use numerical simulations to demonstrate that our filter produces substantially more sensitive, reliable and stable results than the conventionally used aperture-mass statistic.