As researched by Ingrid Fritsch in the early 1970's:
There is no certain information about the origin of the shakuhachi. Some ethnomusicologists assume that its development can be traced back to the Egyptian sebi: this instrument, or rather a variation of it, was carried by Alexander the Great to India, and was taken further to China by Buddhist priests during the Han dynasty (202 B.C.-220 A.D.). There it was amalgamated with the sho panpipe and was called the t'ung hsiao (jap. dosho). According to the T'ang shu (jap. Tosho), a book written at the beginning of the tenth century A.D., the first man to build a set of twelve end-blown flutes, one for each of the chromatic notes of the octave, was Lu Ts'ai (jap. Ryosai), who from 627 to 649 was a member of a society dedicated to reforming the Chinese musical system of that time. The longest instrument, the ch'ih pa', had a length of one shaku and eight sun, from which the Japanese term shakuhachi (jap. hachi=eight) was probably derived. It was in about the seventh century that the shakuhachi was introduced to Japan, where it was employed in the performance of Chines T'ang music--togaku--by the Japanese court orchestra: old manuscripts in the Horyuji and Saidaiji temples in Nara bear witness to this as does the Dajokan-pu of 804 A.D. (containing records of the Heian imperial cabinet), in which a shakuhachi player is mentioned as a togaku musician. In the Shosoin in Nara, where the property of the emperor Shomu (724-749) is maintained, there are eight shakuhachi of differing lengths and material to be seen; all have six finger-holes, and none is more than 43 cm. in length. The lower end of the instrument with its present-day crown of roots is however absent. In the tenth century, the gagaku shakuhachi was removed from the court orchestra and replaced by transverse flutes with seven holes (yokobue, oteki, ryuteki). It was thereafter employed by Buddhist monks for the performance of Chinese hymns, before slowly becoming obsolete.
There are no specific documents concerning the precursor of the present-day shakuhachi; the instrument was probably imported from China a second time. Only in the early Edo period (1600-1867) do we find the beginnings of shakuhachi music as it sometimes sounds today; an important role in the development was played by mendicant Buddhist priests called Komuso (="priests of emptiness and nothingness"). Originally a loosely organised guild of begging musicians with the nominal status of Buddhist lay brothers--they were at one time possibly identical with the Komoso (="priests of rice-straw"), a group of mendicant monks, who according to conflicting theories used to play the hitiyogiri, an instrument related to the shakuhachi--they became a subsect of Rinzai Zen when their numbers rapidly increased in the early seventeenth century. Most of their new numbers were ronin, masterless samurai, who had lost their rank and priveleges through the strife which prevailed between Japanese clans in the late sixteenth century. The guild offered them the opportunity of withdrawal from worldly life; it guaranteed anonymity through the obligatory wearing of the Komuso-apparel, which consisited in part of a hat that left only the eyes free, and it included to a certain extent an aspect of institutionalized trampdom and banditry. Their transformation into a Rinzai Zen subsect ( called Fuke-shu) was probably the result not only of religious but also of political motivation, since membership in a Buddhist sect provided them with protection against the Tokugawa government (Bakufu). The Ichigetsuji in the eastern Kanto area and the Reihoji in Tokyo were chosen as mother-houses by the Fuke-shu, although the Myoanjo in Kyoto also gained the semblance of a main temple somewhat later. In an attempt to justify their existence, they laid claim to a long tradition reaching back to China by forging a series of documents; the Kyotaku Denki Kokujikai, which exerted a strong influence on the entire Japanese and Western understanding of Fukeshu history, even until recent times, is the most prominent of these. This "chronicle" attributes the founding of the sect to a Chinese monk named Chen-chou P'u-k'o (jap. Fuke), who lived during the T'ang period (618-907), and whose follower Chang Po (jap. Chohaku) used to imitate his religious bell-ringing by playing a melody called Kyotaku (empty or false bell) on his flute. The Fukeshu is then supposed to have been introduced to Japan by the Buddhist monk Kakushin in 1254.
Another document which was probably also forged is the Charter of 1614, in which the first Tokugawa shogun, Ieyasu, is said to have granted special priveleges to the Komuso; according to this edict, they possessed the exclusive rights to the playing of the shakuhachi, were exempt from taxes, and were allowed to carry weapons highly unusual for Buddhist monks. In addition, only samurai were eligible for membership. This document was granted recognition by the Tokugawa government around 1680: in return, the Komuso pledged their services to the Bakufu for occasional cases of espionage.
The shakuhachi was used by the Komuso primarily not as a musical instrument, but as a tool of religious meditaion (hoki). This connection between the flute and Zen was of especial importance in Myoanji in Kyoto. Although it was forbidden under pain of severe penalties to compose or play worldly melodies, a certain degree of secularization did however set in as time went on. In 1847, the government revoked the Charter of 1614, and as a result of this, the Fukeshu lost their special priveleges as well as their exclusiveness of class (samurai membership). This period was marked by an intensification of the use of the shakuhachi outside the sect, especially after it was temporarily prohibited in 1871 as a result of the collapse of the shogun state. The instrument now officially acquired secular character.
Although the Komuso are no longer extant, they have been succeeded by the Myoan Kyokai, a society of traditionalistic character, which maintains the historic repetoire. The Kinko school, founded around 1770 by Kinko Kurosawa, has in addition preserved thirty-six old compositions, which have however been somewhat adapted and artistically refined. The recognition of the shakuhachi as a secular instrument led at the end of the nineteenth century to a basic change in its function, and thus its repetoire; this provided the base for its further development into a concert instrument.