We introduce a novel electrochemical sensor based on a glassy carbon electrode (GCE) modified with polyaniline nanowires (PANI-NWs/GCE) for the detection of Lamivudine (LMV), an anti-HIV drug. The modified electrode underwent comprehen- sive characterization using various techniques, and crucial parameters such as pH and scan rate were systematically optimized. Under optimal conditions, the electrochemical behavior of LMV was thoroughly investigated at a working potential of − 1.4 V (vs. Ag/AgCl). Our developed sensor exhibited a remarkable detection limit of 44 nM within the linear concentration range of 12–110 μM for LMV in aqueous solutions. Furthermore, the modified electrode demonstrated successful application in the determination of low levels of LMV in pharmaceutical tablet samples. The method showcases excellent sensitivity and stability, making it suitable for routine quantification of drugs in pharmaceutical formulations. Importantly, our fabricated electrode exhibited minimal interference from common substances such as ascorbic acid, uric acid, and Zidovudine at an applied detection potential of − 1.4 V (vs. Ag/AgCl).