Spectrometers with ever-smaller footprints are sought after for a wide range of applications in which minimized size and weight are paramount, including emerging in situ characterization techniques. We report on an ultracompact microspectrometer design based on a single compositionally engineered nanowire. This platform is independent of the complex optical components or cavities that tend to constrain further miniaturization of current systems. We show that incident spectra can be computationally reconstructed from the different spectral response functions and measured photocurrents along the length of the nanowire. Our devices are capable of accurate, visible-range monochromatic and broadband light reconstruction, as well as spectral imaging from centimeter-scale focal planes down to lensless, single-cell-scale in situ mapping.