Every action has its origin in a thought. Every thought, of course, does not get translated into action, which means that the mind analyzes the thoughts before taking the next step. Any reasonable person will therefore think before acting. There are actions that are instinctive but these are exceptions. In general, actions taken without thinking are either ineffective or destructive. The completed action gives a sense of pleasure directly or indirectly through the satisfaction of some desire. The pleasure may be physical or nonphysical. If the sensation of pleasure is strong enough, the mind craves for it and the action is repeated. It is this repetition that develops into habit. So habit is essentially a continuation of some action and it can be carried on consciously or subconsciously.
Habits can be good or bad, innocuous or grave and they may even determine the kind of life one has. That is why so much emphasis is given to cultivating good habits. In that sense man creates his own destiny through his actions.
It is important to remember, though, that the person creates the habit, the habit does not create the person. Irrespective of the nature of the habit (good or bad) one should never lose the control. It is therefore essential to watch the action constantly and not let it become a mechanical process.
A clear understanding of what habit is helps one in keeping control over the action. If one loses this control, one becomes slave to the habit; this may lead to bad, even disastrous consequences. At the very least one loses sight of the goal of the action and the mind is no longer aware of what is happening.
One of my favorite stories of Noble Laureate Tagore* gives a vivid example of what happens when the habit becomes purely mechanical. The complete story (a poem in the original) is quoted below.
Before him the endless ocean roared. The garrulous waves ceaselessly talked of hidden treasures, mocking the ignorance that knew not their meaning.
Maybe he now had no hope remaining, yet he would not rest, for the search had become his life -- just as the ocean forever lifts its arms to the sky for the unattainable. Even so on the lonely shore the madman with dusty tawny locks still roamed in search of the touchstone.
One day a village boy came up and asked, "Tell me, where did you come at this golden chain about your waist?" The madman startled - the chain that once was iron was verily gold; it was not a dream, but he did not know when it had changed. He struck his forehead wildly - where, O where had he without knowing it achieved success? It had grown into a habit, to pick up pebbles and touch the chain, and to throw them away without looking to see if a change had come; thus the madman found and lost the touchstone.
The sun was sinking low in the west, the sky was gold. The madman returned on his footsteps to seek anew the lost treasure, with his strength gone, his body bent, and his heart in the dust, like a tree uprooted.
(Taken from 'Collected Poems and Plays of Ravindranath Tagore', MacMillan Company, 1961, pp 107-108.)