In this article, headspace solid-phase microextraction (HS-SPME) analysis of thiol compounds with both solid and aqueous samples was investigated using N-phenylmaleimide as an in-fiber derivatization reagent. The derivatives were analyzed using GC-MS. The HS-SPME method was executed on an automatic sampler and optimized by studying a variety of factors such as the selection of the fiber, extraction time, temperature, agitation speed, etc. Method validation was carried out by spiking known amounts of thiol compounds into the sample and calculating the concentration by standard addition. The relative standard deviations (RSD) for the majority of the thiols were less than 10%. The developed method resulted in a limit of detection (LOD) in the low microgram per liter for most of the thiols analyzed, which was about one order of magnitude lower than the HS-SPME without derivatization. Finally, the overall method was successfully applied for the determination of thiols in yellow onion, green onion and garlic.