It is not known when Zhang Wenwei was born. His family claimed ancestry from the early Han Dynasty general Zhang Er. The traceable ancestry of Zhang Wenwei's included officials of Sui Dynasty and Tang Dynasty. His grandfather Zhang Junqing was a copyeditor at Jixian Pavilion, and his father Zhang Shang served in a number of prominent positions, including, eventually, the military governorship of Tianping Circuit. Zhang Wenwei had at least two younger brothers, Zhang Jimei and Zhang Yixian, both of whom, like he, would eventually pass the imperial examinations in the Jinshi class. However, only Zhang Yixian would go on to serve as an imperial official; Zhang Jimei would be stricken by mental ailments, and it was said that Zhang Wenwei, while eventually progressing in his career, would care for Zhang Jimei's health for over 30 years, drawing praise from the gentry of the day. Zhang Wenwei himself was said to be good at writing in his youth, and he was both studious and friendly with people, gaining the reputation of being a gentleman.
Early career
Zhang Wenwei passed the imperial examinations in the Jinshi class in 875, during the reign of Emperor Xizong. He thereafter served as a surveyor for the office of salt and iron monopolies; he then served as a sheriff of a county near the imperial capitalChang'an, as well as a scholar at an imperial institute. After his father Zhang Shang died in 877, he left governmental service to observe a mourning period and to attend to the household. Sometime during Emperor Xizong's Zhonghe era, when Emperor Xizong had fled to Chengdu due to the major agrarian rebellion led by Huang Chao, who captured Chang'an and declared his own state of Qi as its emperor, Emperor Xizong, in order to raise funds for the military campaigns against Qi, moved the office of salt and iron monopolies to Yang Prefecture and put the official Li Du in charge of the office. At Li Du's recommendation, Zhang Wenwei was made a roving surveyor for the office. After Huang was defeated and Emperor Xizong returned to Chang'an in 885, Zhang was first made an imperial censor with the title Jiancha Yushi ; then Zuo Bujue, a low-level advisory official at the examination bureau of government ; an imperial censor with the title Dianzhong Shi Yushi ; an imperial chronicler with the title Qiju Sheren ; and Sixun Yuanwailang, a low-level official at the ministry of civil service affairs. He was then promoted to a supervisory position at the ministry of civil service affairs, with the title Sixun Langzhong and put in charge of drafting edicts. After serving in those roles for a year, he was made Zhongshu Sheren. After his mother's death, he left governmental service to observe a mourning period for her. After Zhang finished observing the mourning period, he returned to the imperial government as a Zhongshu Sheren. He was soon thereafter made the chief imperial scholar. As then-reigning Emperor Zhaozong had just returned to Chang'an, and the imperial authority was extremely weak at that time, edicts that Zhang drafted had to be, and were, appropriately delicate in language but assertive, and was much praised for their propriety. He was then given the additional post of deputy minister of census, and later was made the deputy minister of rites but no longer imperial scholar by that point.
Chancellorship
As of 905, Zhang was still serving as the deputy minister of rites—at that time, at Luoyang, which had been made the capital after the powerful warlord Zhu Quanzhong the military governor of Xuanwu Circuit had forcibly moved Emperor Zhaozong from Chang'an to Luoyang in 904,—under Emperor Zhaozong's son and successor Emperor Ai, as Zhu had had Emperor Zhaozong assassinated late in 904. In 905, the chancellor Liu Can, an associate of Zhu's, had alienated Zhu from the other chancellors Pei Shu, Dugu Sun, and Cui Yuan; Pei, Dugu, and Cui were therefore removed from chancellor offices, while Zhang and Yang She were made chancellors, with the designation Tong Zhongshu Menxia Pingzhangshi. He was also made Zhongshu Shilang, the deputy head of the legislative bureau, and acting director of taxation. Later in the year, when Zhu carried out a purge of many prominent Tang officials at the instigation of Liu and Li Zhen, Liu had initially prepared an even larger list of officials to purge. It was said that it was at Zhang's urging that the purge was not expanded. After Liu himself was killed by Zhu around the new year 906, Zhang also took over the duties of the directors of finances and salt and iron monopolies. In 907, Emperor Ai was preparing to yield the throne to Zhu Quanzhong. As part of the ceremonial passage of the throne, Zhang, acting as the head of the legislative bureau, was put in charge of announcing the passage of the throne. He, as well as Yang and Xue Yiju, went in a grand procession from Luoyang to Daliang, where Zhu was at the time, for the ceremony. Zhu accepted the throne, ending Tang and starting a new Later Liang. It was said that, at a subsequent feast that the new emperor held for Zhang and the other Tang officials, most of them, including Zhang, were prostrate and unable to speak.
During Later Liang
After the transition to Later Liang, Zhang remained chancellor. He was said to be the drafter of much of the regulations that the Later Liang imperial government used. When Emperor Taizu left Luoyang in 908 to battle the state of Jin, he left Zhang in charge of Luoyang. Zhang died later in 908, while still serving as a Later Liang chancellor.