Many westerners are most familiar with the Taode jing (Tao Te Ching) and Zhuangzi (Chuang Tzu), but there are thousands of Taoist scriptures. Earlier than most of the texts now classified as Taoist, the Taode jing and Zhuangzi belong to the age during which scholars produced discourses about the way, or Tao, rather than to subsequent centuries of "received" or "channeled" transmissions from divine beings.
Both the Taode jing and Zhuangzi are polemical texts; that is, they criticize or mock other popular views, especially those of Confucius. Other texts that engaged in the early debates about the way, or path, from a point of view that would later be identified with "Taoism" include the Liezi, a text similar in style to the Zhuangzi and containing some of the same material, and the Neiye, which concerns self-cultivation practices. The Neiye is a chapter in the Guanzi, a text that would be now classified as "Legalist," but also contains Taoist and Confucian ideas.
All of these texts were written sometime during the Eastern Zhou Dynasty (770-221 B.C.E.). When Qin Shihuangdi unified all Zhou territories as well as lands beyond the boundaries of the Zhou empire to form the Qin empire (221-206 B.C.E.), one of the totalitarian measures he undertook to solidify his power was to order the burning of all books. Although the original texts may have been hundreds of years older, most of the editions that are now available are recreations dating from the Han Dynasty (206 B.C.E.-220 C.E.) or later.
Unlike these early texts, the vast majority of Taoist texts purport to be records of communications from immortals or deities, a practice that began in the 2nd century C.E., if not before. One such scripture, now lost but often mentioned in other texts, was the Taiping jing, or Scripture of Great Peace, sacred to the Yellow Turban rebellion of the 2nd century C.E. Other messianic or apocalyptic religious movements that did not survive also produced scriptures, now lost, but referred to in texts that have survived.
It was with the Way of the Celestial Masters that the process of accumulating texts associated with a particular religious group began. Beginning with the teachings transmitted to the founder, Zhang Taoling, by the deified Laozi, the Way of the Celestial Masters produced a great many scriptures communicated by deities or immortals.
In the 4th century C.E., the shaman Yang Xi began to receive visits from Taoist immortals and saints who dictated messages, poems, and book-length texts to him. These were gathered under the rubric Shangqing, or Highest Purity, because Yang Xi was told that they came from the Highest Heaven. Another set of revealed scriptures appeared in the early 5th century. Called Lingbao, or Sacred Jewel, these borrowed heavily from Buddhism and the Way of the Celestial Masters. It was only later that religious groups, now called Shangqing and Lingbao Taoism, formed around these texts. Originally it was the texts that defined the tradition.
So many scriptures had accumulated by the 5th century that the emperor asked an important Taoist, Lu Xiujing (406-477), to select the most authentic ones so that they could be placed in the imperial library. Lu Xiujing divided his selections into three categories, which he called the Three Caverns: the Cavern of Truth, or Dongzhen; the Cavern of Mystery, Dongxuan; and the Cavern of Divinity, or Dongshen. These divisions were based on three different ways of practicing Taoism at the time, and also on ranking: the Cavern of Divinity was ranked lowest and contained texts about the holy mountains and saints, primarily talismans and spells; the Cavern of Mystery contained primarily Lingbao texts, which were liturgical in nature; and the highest rank, the Cavern of Truth, contained Shangqing texts, primarily those that pertained to individual practices such as meditation and alchemy.
Each of the Three Caverns was subdivided into twelve sections: original revelations, divine talismans, exegeses, sacred diagrams, histories and genealogies, codes of conduct, ceremonial protocols, prescriptive rituals, self-cultivation techniques, biographies of saints, hymns, and memorials. In the Sui dynasty (581-618), the Four Auxiliaries were added, which included the Taode jing and all the Celestial Masters texts. This classification system was retained in subsequent editions, but as the Taozang, or Taoist Canon, expanded, matching of texts with categories and subdivisions became less and less exact.