There are several high-performance adaptive optics systems that deliver diffraction-limited imaging on ground-based telescopes, which renewed the interest of single-mode fiber (SMF) spectroscopy for exoplanet characterization. However, the fundamental mode of a telescope is not well matched to those of conventional SMFs. With the recent progress in asphere manufacturing techniques it may be possible to reshape the fundamental mode of a SMF into any arbitrary distribution. An optimization problem is setup to investigate what the optimal mode field distribution is and what the fundamental throughput limit is for SMF spectroscopy. Both single-object spectrographs and integral-field spectrographs are investigated. The optimal mode for single-object spectrographs is found to be the aperture function of the exit pupil, while for integral-field spectrographs the optimal mode depends on the spatial sampling of the focal plane. For dense sampling, a uniform mode is optimal, while for sparse sampling, the mode of a conventional SMF is near optimal. With the optimal fiber mode, high throughput (>80%) can be achieved when the focal plane is (super) Nyquist sampled. For the Nyquist sampled cases, the optimal mode has almost 20% more throughput than a conventional SMF.