Two-photon calcium imaging in awake, head-fixed animals enables the measurement of neuronal activity during behaviour. Often, licking for the retrieval of water reward is used as a measurable report of the animal's decision during reward-driven behaviour. However, licking behaviour can induce severe motion artifacts that interfere with two-photon imaging of cellular activity. Here, we describe a simple method for the online correction of licking-induced focus shifts for two-photon calcium imaging of neocortical neurons in the head-fixed mouse. We found that licking causes a stereotyped drop of neocortical tissue, shifting neurons up to 20 μm out of focus. Based on the measurement of licking with a piezo film sensor, we developed a feedback model, which provides a corrective signal for fast optical focus adjustments with an electrically tunable lens. Using online correction with this feedback model, we demonstrate a reduction of licking-related focus changes below 3 μm, minimizing motion artifact contamination of cellular calcium signals. Focus correction with a tunable lens is a simple and effective method to improve the ability to monitor neuronal activity during reward-based behaviour.