The development of lithium-ion batteries using transition metal oxides has recently become more attractive, due to their higher specific capacities, better rate capability, and high energy densities. Herein, the in situ growth of advanced mesoporous CuO/O-doped g-C3N4 nanospheres is carried out in a two step hydrothermal process at 180 °C and annealing in air at 300 °C. When used as an anode material, the CuO/O-doped g-C3N4 nanospheres achieve a high reversible discharge specific capacity of 738 mAhg-1 and a capacity retention of ∼75.3% after 100 cycles at a current density 100 mAg-1 compared with the pure CuO (412 mAhg-1, 47%) and O-doped g-C3N4 (66 mAhg-1, 53%). Even at high current density 1 Ag-1, they exhibit a reversible discharge specific capacity of 503 mAhg-1 and capacity retention ∼80% over 500 cycles. The excellent electrochemical performance of the CuO/O-doped g-C3N4 nanocomposite is attributed to the following factors: (I) the in situ growing CuO/O-doped g-C3N4 avoids CuO nanoparticle aggregation, leading to the improved lithium ion transfer and electrolyte penetration inside the CuO/O-doped g-C3N4 anode, thus promoting the utilization of CuO; (II) the porous structure provides efficient space for Li+ transfer during the insertion/extraction process to avoid large volume changes; (III) the O-doping g-C3N4 decreases its band gap, ensuring the increased electrical conductivity of CuO/O-doped g-C3N4; and (IV) the strong interaction between CuO and O-doped g-C3N4 ensures the stability of the structure during cycling.