He studied literature and history extensively, and often spoke in grand terms; because of that latter characteristic, the well-learned did not have good opinions of him.
Zhang was subsequently made Duzhi Yuanwailang (度支員外郎), a low-level official at the ministry of census (戶部, Hubu).
[3] In 880, as the major agrarian rebel Huang Chao approached the Tang capital Chang'an, Zhang claimed to be ill, and he took his mother and his family to take refuge at Shang Prefecture (商州, in modern Shangluo, Shaanxi).
Meanwhile, while Emperor Xizong was fleeing through Xingyuan (興元, in modern Hanzhong, Shaanxi), his train was running out of food supplies.
With the soldiers agreeing with Zhang, Wang Jingwu rejoined the Tang cause and sent forces to aid in the operations against Huang.
[7] After Huang was defeated and Emperor Xizong returned to Chang'an, Zhang was made the deputy minister of census (戶部侍郎, Hubu Shilang).
[3] In 887, he was made the deputy minister of defense (兵部侍郎, Bingbu Shilang) and chancellor de facto with the designation Tong Zhongshu Menxia Pingzhangshi (同中書門下平章事).
[8] (When the edict announcing this commission reached the warlord Li Keyong the military governor of Hedong Circuit (河東, headquartered in modern Taiyuan, Shanxi), Li Keyong, who was unimpressed with Zhang, stated, "Lord Zhang likes to talk but has no real abilities, and he is someone who can overturn the empire.
When Emperor Zhaozong requested opinions from imperial officials, most opposed, including the chancellors Du Rangneng and Liu Chongwang, but Zhang and Kong, who wanted to try to use this as an opportunity to reassert imperial power, advocated for the campaign against Li Keyong and to then use that power to suppress the eunuchs, strenuously advocated for the campaign.
Emperor Zhaozong, despite misgivings, agreed, and he put Zhang in overall command of the operations, assisted by the official Sun Kui (孫揆).
This demoralized the imperial army, and subsequently, with Li Cunxiao putting Lu Prefecture under siege, the Xuanwu forces withdrew from Zhaoyi.
[6] The imperial forces engaged Li Keyong's at Fen Prefecture (汾州, in modern Lüliang, Shanxi).
The Hedong forces gave chase, catching Zhang at Jin Prefecture (晉州, in modern Linfen, Shanxi).
After three days, Li Cunxiao decided that no benefit could come from capturing a chancellor and slaughtering imperial forces, and therefore lifted the siege to allow Zhang and Han to flee, and they did so.
[6] Zhang Jun set off to his place of exile, but just after he left Chang'an, when he got to Lantian (藍田, in modern Xi'an, Shaanxi), he fled from his escorts, to Han Jian's headquarters at Hua Prefecture (華州), and both he and Kong Wei wrote to Zhu Quanzhong to ask him to plead for them.
Emperor Zhaozong decided thereafter to release them from their exile orders, and both Zhang and Kong thereafter resided at Hua Prefecture with Han.
He thus summoned Zhang Jun, who was then no longer at Hua Prefecture but residing at his vacation estate in Changshui (長水, in modern Luoyang, Henan), and Kong Wei to the capital, initially giving them the honorary post of advisor to the Crown Prince Li Yu, Prince of De, and then making Kong chancellor, while making Zhang the minister of defense (兵部尚書) and the director of circuit commerce.
[9] Zhang, who followed Emperor Zhaozong to Hua Prefecture, was relieved of his post as the director of circuit commerce, and thereafter was made You Pushe (右僕射), one of the heads of the executive bureau (尚書省, Shangshu Sheng).
(However, early in 901, the Shence Army officers Sun Dezhao (孫德昭), Dong Yanbi (董彥弼), and Zhou Chenghui (周承誨), at the urging of the chancellor Cui Yin, made a surprise countercoup, killing the eunuchs who removed Emperor Zhaozong and restoring him, without further military campaign by the military governors.
Meanwhile, Yang's men arrived, surrounded Zhang Jun's vacation estate, and slaughtered the entire household.
[3][13] Li Yan would remain at Huainan after Yang's death and Tang's destruction, until he was killed by Xu Wen in 918.