Channelrhodopsins are light-sensitive ion channels whose reaction cycles involve conformation-coupled transfer of protons. Understanding how channelrhodopsins work is important for applications in optogenetics, where light activation of these proteins triggers changes in the transmembrane potential across excitable membranes. A fundamental open question is how the protein environment ensures that unproductive proton transfer from the retinal Schiff base to the nearby carboxylate counterion is avoided in the resting state of the channel. To address this question, we performed combined quantum mechanical/molecular mechanical proton transfer calculations with explicit treatment of the surrounding lipid membrane. The free energy profiles computed for proton transfer to the counterion, either via a direct jump or mediated by a water molecule, demonstrate that, when retinal is all-trans, water and protein electrostatic interactions largely favour the protonated retinal Schiff base state. We identified a conserved lysine group as an essential structural element for the proton transfer energetics in channelrhodopsins.