Nearby neurons in mammalian neocortex demonstrate a great diversity of cell types and connectivity patterns. The importance of this diversity for computation is not understood. While extracellular recording studies in visual cortex have provided a particularly rich description of behavioral modulation of neural activity, new methods are needed to dissect the contribution of specific circuit elements in guiding visual perception. Here, we describe a method for three-dimensional cellular imaging of neural activity in the awake mouse visual cortex during active discrimination and passive viewing of visual stimuli. Head-fixed mice demonstrated robust discrimination for many hundred trials per day after initial task acquisition. To record from multiple neurons during operant behavior with single-trial resolution and minimal artifacts, we built a sensitive microscope for two-photon calcium imaging, capable of rapid tracking of neurons in three dimensions. We demonstrate stable recordings of cellular calcium activity during discrimination behavior across hours, days, and weeks, using both synthetic and genetically encoded calcium indicators. When combined with molecular and genetic technologies in mice (e.g., cell-type specific transgenic labeling), this approach allows the identification of neuronal classes in vivo. Physiological measurements from distinct classes of neighboring neurons will enrich our understanding of the coordinated roles of diverse elements of cortical microcircuits in guiding sensory perception and perceptual learning. Further, our method provides a high-throughput, chronic in vivo assay of behavioral influences on cellular activity that is applicable to a wide range of mouse models of neurologic disease.