A habit is basically rebirth. Looking for rebirth, we find SN12.23:
I say that suffering has a vital condition. And what is it? You should say: ‘Rebirth.’
I say that rebirth has a vital condition. And what is it? You should say: ‘Continued existence.’
I say that continued existence has a vital condition. And what is it? You should say: ‘Grasping.’
I say that grasping has a vital condition. And what is it? You should say: ‘Craving.’
I say that craving has a vital condition.
And what is it? You should say: ‘Feeling.’ … You should say: ‘Contact.’ … You should say: ‘The six sense fields.’ … You should say: ‘Name and form.’ … You should say: ‘Consciousness.’ … You should say: ‘Choices.’ … I say that choices have a vital condition, they don’t lack a vital condition. And what is the vital condition for choices? You should say: ‘Ignorance.’
Notice the phrase "six sense fields." This includes the five senses as well as thought. Therefore Dependent Origination describes the connection between thought and habit.
The cure is the Noble Eight-Fold Path. Even though we may understand that clinging to our delights causes us suffering, to actually get rid of habitual suffering does require practicing the Path, relinquishing identity view. And identity view is just the craving in habits (MN44):
“Ma’am, they speak of this thing called ‘the origin of identity’. What is the origin of identity that the Buddha spoke of?”
“It’s the craving that leads to future rebirth, mixed up with relishing and greed, taking pleasure in various different realms. That is, craving for sensual pleasures, craving to continue existence, and craving to end existence. The Buddha said that this is the origin of identity.”
To end suffering, one replaces unskillful habits (e.g., smoking) with skillful habits (e.g., observing precepts).