Identifying vulnerable individuals before they transition to a compulsive pattern of drug seeking and taking is a key challenge in addiction to develop efficient prevention strategies. Oscillatory activity within the subthalamic nucleus (STN) has been associated with compulsive-related disorders. To study compulsive cocaine-seeking behavior, a core component of drug addiction, we have used a rat model in which cocaine seeking despite a foot-shock contingency only emerges in some vulnerable individuals having escalated their cocaine intake. We show that abnormal oscillatory activity within the alpha/theta and low-beta bands during the escalation of cocaine intake phase predicts the subsequent emergence of compulsive-like seeking behavior. In fact, mimicking STN pathological activity in noncompulsive rats during cocaine escalation turns them into compulsive ones. We also find that 30 Hz, but not 130 Hz, STN deep brain stimulation (DBS) reduces pathological cocaine seeking in compulsive individuals. Our results identify an early electrical signature of future compulsive-like cocaine-seeking behavior and further advocates the use of frequency-dependent STN DBS for the treatment of addiction.