Human behaviour is highly flexible. Cognitive control is the basis of this flexibility. Imagine reading a book in the park and not being able to focus on the novel because constantly disturbed by irrelevant sounds (children playing) or internal thoughts (did I switch the light off?). Reading a book seems an easy task, in which, however, we often fail! In normal development, ageing or some pathological conditions (like attention deficit hyperactivity disorder–ADHD), this type of self-control can be highly challenging, seriously impacting daily life. Now, imagine having an external device capable of decoding your brain activity in real-time and detecting when your attention is deviating from the relevant task (e.g. book reading). Imagine that this device will also help compensate for attention drops by triggering a cascade of processes in the brain so that attention will be focused again. Would this device help you read the book? Or even induce changes in brain networks so that attention will be generally enhanced? This project (Ctrl Code) ventures to put this idea into practice. Thanks to the latest technical advances in analysing brain signals, it is possible to compute brain activity (e.g. brain oscillations) online and read-out 'brain states' in real-time (is attention focused? to follow with the example). We propose a proactive closed-loop brain-state dependent stimulation (cl-BSDS) approach to trigger attention adjustments. We know that after the experience of cognitive conflict (i.e. when competing responses must be overcome), performance is better, which laid the groundwork for theories emphasising the role of cognitive conflict for recruitment of control processes and the importance of coordinated brain network (frontal-parietal) for flexible behaviour. It seems that one of the functions of control (e.g. enhanced attention) is to prevent cognitive conflict, and at the same time, conflict seems to be helpful for the regulation of control. Therefore, cognitive conflict and attention adjustments seem to be parts of a proactive mechanism used by the brain for flexible behaviour. Ctrl Code is articulated in two steps. First, we need to test the specific hypothesis that post-conflict attention adjustments are implemented in a preparatory way from one trial to the next. Second, we design the cl-BSDS, in which cognitive conflict will be used to trigger attention at need in a controlled laboratory setting, with the aim of (a) promoting a virtuous loop of brain states (i.e. self-regulation) and (b) favour human performance. Adopting cl-BSDS in the investigation of cognitive control is critical because it allows capturing one of the essential features of cognitive control, namely its flexibility. Furthermore, Ctrl Code will overcome another substantial limitation of standard treatments for attention boosting (i.e. neuro-feedback): the extensive training the participants must adopt for its effectiveness, which confines the applicability only to responders and negatively impacts research and clinical costs. Finally, Ctrl Code will test hypotheses on the role of brain oscillations in cognitive control by focusing on specific brain waves.