In wireless sensor networks, each sensor node has a finite amount of energy to expend. The clustering method is an efficient way to deal with the imbalance in node energy consumption. A topology optimization technique for wireless sensor networks based on the Cauchy variation optimization crow search algorithm (CM-CSA) is suggested to address the issues of rapid energy consumption, short life cycles, and unstable topology in wireless sensor networks. At the same time, a clustering approach for wireless sensor networks based on the enhanced Cauchy mutation crow search algorithm is developed to address the issue of the crow algorithm’s sluggish convergence speed and ease of falling into the local optimum. It utilizes the Cauchy mutation to improve the population’s variety and prevent settling for the local optimum, as well as to broaden the range of variation and the capacity to carry out global searches. When the leader realizes he is being followed, the discriminative probability is introduced to improve the current person’s location update approach. According to the simulation findings, the suggested CM-CSA algorithm decreases the network’s average energy consumption by 66.7%, 50%, and 33.3% and enhances its connectivity performance by 52.9%, 37.6%, and 23.5% when compared to the PSO algorithm, AFSA method, and basic CSA algorithm.