Abstract Deciphering the neural code underlying goal-directed behavior is a long-term mission in neuroscience 1,2 . Neurons exhibiting preparation and movement-related activity are intermingled in the premotor and motor cortices 3,4 , thus concealing the neural code of planned movements. We employed a combination of electrophysiology, pathway-specific optogenetics, phototagging, and inverse reinforcement learning (RL) to elucidate the role of defined neuronal subpopulations in the rat rostral and caudal forelimb areas (RFA and CFA), which correspond to the premotor and motor cortical areas. The inverse RL enabled the functional dissection of spatially intermingled neuronal subpopulations, complementing our pathway-specific optogenetic manipulations and unveiling differential functions of the preparation and movement subpopulations projecting from RFA to CFA. Our results show that the projecting preparation subpopulation suppresses movements, whereas the projecting movement subpopulation promotes actions. We found the influence of RFA on CFA to be adaptable, with the projection either inhibiting or exciting neurons in the superficial and deep CFA layers, depending on context and task phase. These complex interactions between RFA and CFA likely involve the differential recruitment of inhibitory interneurons in the CFA, which is supported by our electron microscopy analysis of the connectivity between these regions. We provide here unprecedented mechanistic insights into how the premotor and primary motor cortices are functionally and structurally interlinked with the potential to advance neuroprosthetics. Graphical abstract This study provides mechanistic insights into the interactions between the rostral forelimb area (RFA) and the caudal forelimb area (CFA). Specifically, we provide evidence for a differential impact of RFA on CFA depending on the task phase and the targeted CFA layers. RFA contains at least two spatially intermingled subpopulations - one related to movement preparation and one to movement execution. Both subpopulations project to CFA. Here we investigated the impact of these two subpopulations on the activity of the local CFA circuit as well as on the behavior in different contexts. When rats were not involved in a task, the effect of RFA was mainly excitatory in the deep CFA layers, while the superficial layers remained unaffected. This can be interpreted as a non-selective activation of the deep CFA neurons enabling a variety of spontaneous movements. During the preparation phase before a movement, the RFA had an opposite impact on the superficial and deep layers: while the superficial CFA layers were excited by RFA input, the deeper layers were mostly inhibited, minimizing movements and enabling continued holding of a lever. During the movement phase, the inhibitory effect on neurons in the deep CFA layers was counterbalanced by excitation, thus enabling a selected conduction of movements. The opposing effects during preparation and movement phase on CFA deep layers were correlated with increased firing rates of the RFA preparation and movement subpopulations, respectively, making it likely that the inhibition resulted from increased activities of these subpopulation specifically. With an electron microcopy approach we demonstrate that inhibitory and excitatory CFA neurons are directly targeted by RFA, thus providing a mechanism for the bidirectional control of CFA activity. Please note that the depicted impact of RFA on excitatory or inhibitory CFA neurons refers to net effects in this figure, not to the targeting of individual neurons.