Hanshi were samurai who served Edo period clans. However Hanshi include all samurai ranging from Joshi (superior warriors) to Kashi (non-commissioned officers), and in a narrow sense, they also include those without samurai status such as ashigaru (common foot soldiers) and chugen (a rank below common soldiers). Therefore it may be said that hanshi are not necessarily samurai. In other words, it may be correct to say that the Hanshi refers to all people who owned Hanseki (domain registers). However, in many cases, Hanshi refers to the samurai class.
Although they mainly served as soldiers playing military roles during the early Edo period, they gradually became bureaucrats and lost most of their military function during the mid-to-late Edo period.
In fact, they didn't call themselves Hanshi during the Edo period.
For example, the names of Hanshi in the Satsuma Domain preceded by 'Shimazu Family Retainer' as opposed to 'Satsuma Domain Retainer.'
The name 'Hanshi' is also commonly used in the case of domains, such as the Satsuma Domain and Choshu Domain, which had not come under provincial rule the time of the first lord until the Haihan-chiken (abolition of feudal domains and establishment of prefectures) in the Meiji period. However, the term is not appropriate for domains, such as the Kuwana Domain, of which the lord family itself came under provincial rule as a result of orders from the Edo bakufu (Japanese feudal government headed by a shogun).