We present a wireless electro-optic headstage that uses a 0.13- μm CMOS custom integrated circuit (IC) implementing a digital neural decoder (ND-IC) for enabling real-time closed-loop (CL) optogenetics. The ND-IC processes the neural activity data using three digital cores: 1) the detector core detects and extracts the action potential (AP) of individual neurons by using an adaptive threshold; 2) the data compression core compresses the detected AP by using an efficient Symmlet-2 discrete wavelet transform (DWT) processor for decreasing the amount of data to be transmitted by the low-power wireless link; and 3) the classification core sorts the compressed AP into separated clusters on the fly according to their wave shapes. The ND-IC encompasses several innovations: 1) the compression core decreases the complexity from O(n 2) to O(n · log(n)) compared to the previous solutions, while using two times less memory, thanks to the use of a new coefficient sorting tree; and 2) the AP classification core reuses both the compressed DWT coefficients to perform implicit dimensionality reduction, which allows for performing intensive signal processing on-chip, while increasing power and hardware efficiency. This core also reuses the signal standard deviation already computed by the AP detector core as threshold for performing automatic AP sorting. The headstage also introduces innovations by enabling a new wireless CL scheme between the neural data acquisition module and the optical stimulator. Our CL scheme uses the AP sorting and timing information produced by the ND-IC for detecting complex firing patterns within the brain. The headstage is also smaller (1.13 cm 3), lighter (3.0 g with a 40 mAh battery) and less invasive than the previous solutions, while providing a measured autonomy of 2h40, with the ND-IC. The whole system and the ND-IC are first validated in vivo in the LD thalamus of a Long-Evans rat, and then in freely-moving CL experiments involving a mouse virally expressing ChR2-mCherry in inhibitory neurons of the prelimbic cortex, and the results show that our system works well within an in vivo experimental setting with a freely moving mouse.