Chlorpyrifos (CPF) is an insecticide and acaricide that interrupts nerve conduction by reducing the activity of the enzyme acetylcholinesterase. It can enter the human body through a variety of channels and produce serious physiological effects. However, excessive use of CPF in herbal production produces excessive pesticide residues and reduces the yield of high-quality herbs. Therefore, the development of effective and convenient CPF residue detection technology is critical for pesticide residue monitoring as well as danger avoidance. Based on this, an electrochemical enzyme biosensor using acetylcholinesterase (AChE) as the recognition element was constructed for highly sensitive and rapid detection of chlorpyrifos in traditional Chinese medicine. The electrode substrate modification material was a polyaniline/gold nanoparticles (PANI/AuNPs) composite material prepared by PANI functional modification of AuNPs with high conductivity and large specific surface area, which has excellent electrical conductivity and biocompatibility. Specifically, the PANI/AuNPs offered an exceptional active site for AChE immobilization, greatly enhancing the electrical signals resulting from AChE-catalyzed iodination of acetylthiocholine and accelerating electron transfer. In contrast, AChE's better identification of the target analyte CPF meant that the sensor was highly selective for organophosphorus pesticide residues. Under optimized conditions, the sensor showed good linearity in the range of 1.00 × 10− 3 ~ 1.00 × 101 ppm with a detection limit of 7.90 × 10− 5 ppm. During practical sample testing, the sensor exhibited remarkable stability, reproducibility, and sensitivity in detecting CPF pesticide residues in Chinese herbal medicines. This offers a reliable tool for precise monitoring and propels the progress of enzyme-based biosensors, both in fostering the cultivation and production of superior-quality herbal medicines, as well as in enabling rapid on-site pesticide residue detection.