The inappropriate and excessive use of chlorpyrifos has caused major damage to food safety and human health. Developing a simple yet sensitive detection method for chlorpyrifos residues is urgently needed. Photoelectrochemical (PEC) sensor with high photoelectric conversion efficiency is of great significance for the detection of chlorpyrifos residues in food. In this work, a novel PEC sensor based on polythiophene derivative film (PS2TTz) for the detection of chlorpyrifos is constructed via simple one-step electropolymerization within only 3.5 min. Scanning electron microscopy, raman spectroscopy, X-ray photoelectron spectroscopy, and other characterizations verified the effective decoration of PS2TTz film on the GCE, and the possible reaction mechanism between PS2TTz and chlorpyrifos was discussed. The PEC signal could be greatly decreased by PS2TTz film with chlorpyrifos due to the blocked transfer of electrons, leading to high sensitivity and good selectivity. On the basis of the proposed photoelectrochemical mechanism, the PEC sensor exhibited significant detection performance toward chlorpyrifos in the range of 1 to 218.92 μg/L with a LOD of 0.36 μg/L (S/N = 3). Impressively, the constructed PEC sensor was successfully applied in green vegetables, which expanded the scope for the detection of chlorpyrifos in practical application.