Long-term in vivo multimodal studies that combine optogenetics and electrophysiology are essential for investigating the functional connectivity of local neuronal circuits. Graphene holds unique advantages for implantable neural systems by combining properties like optical transparency, flexibility, high conductivity, and biocompatibility. Here we report a graphene-based compact closed-loop optogenetics system with the capability of simultaneous recording and processing of neural data in real time to guide selective control of neural activity through optogenetic stimulation. We report a fabrication process for high-yield large area fabrication of low impedance transparent graphene microelectrode arrays on clear flexible substrates. We extensively investigate light-induced artifacts for graphene microelectrodes in comparison to conventional metal-based microelectrodes through experiments and modeling. We develop an equivalent circuit model which successfully explains the recorded waveforms for metal electrodes under various light intensity and duration conditions. Unlike conventional metal-based microelectrodes, which suffer from huge light-induced artifacts, transparent graphene microelectrodes completely eliminate the artifact problem and thus allow the design of compact closed-loop optogenetics systems. We design and build a compact battery-powered system incorporating transparent graphene microelectrode arrays, fiber-coupled μLEDs and a custom circuit board that integrates different modules. Finally, we successfully demonstrate closed-loop operation based on electrical sensing with transparent graphene microelectrodes and optogenetic stimulation with μLEDs without any crosstalk between the two modalities. This compact system offers fast control of specific neural populations, which can significantly facilitate in vivo studies on neuronal dynamics, neural plasticity, and identification of how specific neuron type contributes to the local neural circuits.