Gundai （a magistrate of a region or an administrator of a town) is the name of a post set in the bakufu (Japanese feudal government headed by a shogun) and in clan domains from the Muromachi period to the Edo period. The post was also referred to as Koribugyo (magistrate of a country).
The post of Gundai was created when a Shugodai (deputy of Shugo; provincial constable) who had been exercising military and police powers during the Kamakura period began taking charge of affairs related to taxation (tax collection) as well at the start of the Muromachi period. Gundai or Koribugyo was generally used to refer to a Daikan (local governor) who controlled a unit of Gun (country) under the direction of a Shugodai, but there were also times when these terms were also used to refer to a Shugodai. A person with this position had one or two countries under their jurisdiction.
During the Edo period, Gundai was a post set within the bakufu as well as in each domain.
Within the bakufu, the post referred to a local governor (Daikan) who controlled a relatively wide extension of government territory. Early on during the Edo period, aside from the Kanto region, a Gundai post was set in almost all of the provinces, including Kamigata, Amagasaki, Mikawa, Tanba and Kawachi. In 1642, the Kanjogashira sei (a system controlled by a chief financial officer) was established, which put Gundai and Daikan under its jurisdiction, but Kanto Gundai was brought under the control of the Roju (members of the Shogun's council of elders) later on. After the middle Edo period, the number of Gundai was reduced to four: Kanto Gundai, Mino Gundai, Saigokusuji Gundai (Kyushu region) and Hida Gundai. The status and rank of a Gundai was higher than that of a Daikan, but the scope of the work between the two was nearly the same. In the early Edo period, the post called Koridaikan (local governor of a country) was set up under control of the Roju and had nearly all the same duties, but was abolished in 1668.
A Gundai or Koribugyo was set up in each domain in order to administer government in directly controlled clan territories.