In the subconscious mind; over which we have very little power.
And look at the picture (by Dr Joe Dispenza) of our minds.
To me it explains why it is so hard to quit.
Also why meditation helped me quitting; and/or any other activity which allows one to access the subconscious mind (deep state of relaxation brought by music, painting, dancing, whatever helps the mind stay in the now, and forget the old emotions, beliefs, routine activities) and modify the patterns residing in it.
Take what you need, leave the rest.