Technologies for peripheral nerve stimulation have conventionally relied on the anatomic placement of electrodes adjacent to subsets of sensory fibres or motor fibres that selectively target an end effector. Here, we demonstrate the use of optogenetics to directly target the innervating fibres of an end effector by relying on retrograde transfection of adeno-associated virus serotype 6 to restrict axonal opsin expression to the desired fibre targets. By using an in vivo screen in rats, we identify the first channelrhodopsins as well as a halorhodopsin that respond to red light in the peripheral nerve. Combining two channelrhodopsins with spectrally distinct activation profiles allowed us to drive opposing muscle activity via two-colour illumination of the same mixed nerve. We also show halorhodopsin-mediated reductions in electrically evoked muscle tremor spectrally optimized for deep peripheral nerves. Our non-invasive peripheral neurostimulator with targeted multi-fascicle resolution enables scientific and clinical exploration, such as motor control in paralysis, biomimetic sensation feedback for amputees and targeted inhibition of muscle tremor.