Compartmentalization within nanofibers of double-decker phthalocyanine induces high-performance sensing in both aqueous solution and gas phase.