I discussed this with Alain Caron during a masterclass. His answer was to be conscious of your playing and know exactly where you are and what you're doing at all moments. Key, scale, degree, note, chord. Then after a few years doing it on all tunes even the most simple, it supposedly becomes 2nd nature.
It sounds like a tremendous work and it is, at first at least. I don't do it most of the time but I have this approach for specific tunes I really want to master. I learn them inside out and put a lot of work into knowing exactly how and why I'd play a note. It really pays.