Habits tend to form slowly but, once formed, can have great stability. We probed these temporal characteristics of habitual behaviors by intervening optogenetically in forebrain habit circuits as rats performed well-ingrained habitual runs in a T-maze. We trained rats to perform a maze habit, confirmed the habitual behavior by devaluation tests, and then, during the maze runs (ca. 3 s), we disrupted population activity in a small region in the medial prefrontal cortex, the infralimbic cortex. In accordance with evidence that this region is necessary for the expression of habits, we found that this cortical disruption blocked habitual behavior. Notably, however, this blockade of habitual performance occurred on line, within an average of three trials (ca. 9 s of inhibition), and as soon as during the first trial (<3 s). During subsequent weeks of training, the rats acquired a new behavioral pattern. When we again imposed the same cortical perturbation, the rats regained the suppressed maze-running that typified the original habit, and, simultaneously, the more recently acquired habit was blocked. These online changes occurred within an average of two trials (ca. 6 s of infralimbic inhibition). Measured changes in generalized performance ability and motivation to consume reward were unaffected. This immediate toggling between breaking old habits and returning to them demonstrates that even semiautomatic behaviors are under cortical control and that this control occurs online, second by second. These temporal characteristics define a framework for uncovering cellular transitions between fixed and flexible behaviors, and corresponding disturbances in pathologies.H abits are among the most stable and powerful behaviors that we have. Forming such strongly ingrained behaviors requires that a durable representation of the movement repertoire be acquired. Much evidence suggests that this process involves a gradual transition from flexible and goal-directed behavior to a more fixed, habitual behavioral strategy (1-7). How these properties of habits map onto neural circuitry has been the focus of classic lesion and chemical inactivation studies, which have identified regions of the striatum as essential for the expression of habits (2-4). In addition, such studies have established that a region in the medial prefrontal cortex also must be intact for habits to be expressed (7-9). This medial prefrontal region [called infralimbic (IL) cortex in rodents] is linked to emotion-related limbic circuitry and projects to sites that promote behavioral flexibility at the expense of habits (e.g., prelimbic cortex and medial striatum) (3,4,7,10). Based on this anatomy, the IL cortex is thought to be at an executive level in the control of habits and behavioral strategies (1,8,9,11).This sketch of the circuitry for habits and skilled habit-like behaviors opens key questions about how habitual behaviors are controlled on a moment-by-moment basis. The slow emergence of habits favors a gradual biasing of these behaviors toward automaticity...