Here we describe an approach for making targeted patch-clamp recordings from single neurons in vivo, visualized by two-photon microscopy. A patch electrode is used to perfuse the extracellular space surrounding the neuron of interest with a fluorescent dye, thus enabling the neuron to be visualized as a negative image ('shadow') and identified on the basis of its somatodendritic structure. The same electrode is then placed on the neuron under visual control to allow formation of a gigaseal ('shadowpatching'). We demonstrate the reliability and versatility of shadowpatching by performing whole-cell recordings from visually identified neurons in the neocortex and cerebellum of rat and mouse. We also show that the method can be used for targeted in vivo single-cell electroporation of plasmid DNA into identified cell types, leading to stable transgene expression. This approach facilitates the recording, labeling and genetic manipulation of single neurons in the intact native mammalian brain without the need to pre-label neuronal populations.