The effects of N-doping and the lithiation mechanism of TiO2 nanotubes were elucidated by integrated in situ microscopy and electrochemical measurements.