In 689, by which time Empress Wu was serving as empress dowager and regent over her son Emperor Ruizong, she held a competition for scholars willing to offer suggestions for the imperial administration. Zhang participated in the competition and was ranked first among the thousands of contestants. She promoted him to be an imperial censor.
In 698, Wu Zetian was set to enter into a marriage treaty with Ashina Mochuo, the khan of Eastern Tujue, where her grandnephew Wu Yanxiu (武延秀) the Prince of Huaiyang would marry a daughter of Ashina Mochuo. Zhang opposed, stating, "In ancient times, no Chinese imperial prince had ever married a barbarian woman as his wife." This opposition drew displeasure from Wu Zetian, as she wanted peace with Eastern Tujue, and she demoted Zhang to be the prefect of He Prefecture (合州, modern northern Chongqing). (However, the marriage treaty would be doomed, as Ashina Mochuo, not actually having any intent to give a daughter to Wu Yanxiu or to make peace with Wu Zetian, used the excuse that he had intended to marry his daughter to a prince of the Tang imperial Li clan to instead detain Wu Yanxiu and launch a major attack on Zhou.) Later that year, Zhang was serving as the prefect of Shu Prefecture (蜀州, in modern Chengdu), when he made the suggestion that Shu Prefecture, which was required to send 500 conscript soldiers to take up garrison at Yao Prefecture (姚州, roughly modern Chuxiong Yi Autonomous Prefecture, Yunnan), no longer be required to do so, as the road was treacherous and the conditions were so severe that many would die -- and further that no garrison be put up at Yao Prefecture at all, treating it as vassal territory rather than part of Zhou proper. Wu Zetian did not accept his suggestion.
At some time prior to 700, Zhang was serving as the secretary general of Jing Prefecture (荊州, roughly modern Jingzhou, Hubei), when, on one occasion, Wu Zetian was having a conversation with the senior chancellor Di Renjie, asking Di's recommendation for someone with extraordinary talent, to serve as chancellor or general. Di responded, "As far as literary talent is concerned, Your Imperial Majesty already have them in Su Weidao and Li Jiao [Di's fellow chancellors], but if you truly want extraordinary talent, I know Zhang Jianzhi, the secretary general of Jing Prefecture. Even though he is old, he is capable of being chancellor." In response, Wu Zetian promoted Zhang to be the military advisor to the prefect of the capital prefecture Luo Prefecture (洛州, roughly modern Luoyang, Henan), sending Yang Yuanyan (楊元琰) to replace him. (When Yang reached Jing Prefecture, Zhang and Yang rowed a boat on the Yangtze River together, and they secretly discussed Wu Zetian's overthrow of Tang Dynasty. During the conversation, Yang expressed sentiment that he wanted to see Tang's restoration -- a sentiment that Zhang kept in his mind for later.) A few days after Zhang's promotion, Wu Zetian was again asking Di for a recommendation, and Di responded, "I had just recommended Zhang Jianzhi, and Your Imperial Majesty has not yet promoted him." She responded, "I already did." Di responded, "I recommended a chancellor, not a military advisor." Wu Zetian then, while not promoting Zhang to be chancellor at that time, promoted him to be the deputy minister of justice (秋官侍郎, Qiuguan Shilang).
In 704, as the chancellor Yao Yuanzhi was set to briefly leave Luoyang to serve as the commander of the forces in the Lingwu region, Wu Zetian also asked him to recommend a talented official. Yao responded, "Zhang Jianzhi is deep-thinking and capable of ruling on great things. He is already old. Please promote him quickly." Wu Zetian therefore gave Zhang the designation Tong Fengge Luantai Pingzhangshi (同鳳閣鸞臺平章事), making him a chancellor de facto at the age of 79.
In spring 705, with Wu Zetian being ill, Zhang entered into a plot with a number of officials and generals, including Cui Xuanwei, Huan Yanfan, Jing Hui, and Yuan Shuji, to kill Wu Zetian's lovers Zhang Yizhi and Zhang Changzong, who had become powerful much to the distaste of the chancellors. Zhang reminded Yang of his prior desire to restore Tang, and put him, Huan, Jing, and a general who agreed to the plot, Li Dan (李湛), in charge of some of the corps of the imperial guards. He further persuaded the ethnically Mohe general Li Duozuo to join the plot as well, persuading Li Duozuo, who felt indebted to Emperor Gaozong for having promoted him, that Zhang Yizhi and Zhang Changzong were endangering the positions of Emperor Gaozong's sons with Wu Zetian, Li Xian the Crown Prince and Li Dan the Prince of Xiang (note different character than the general). He also received agreement from Yao. With agreement from Li Xian as well, the coup leaders acted on February 20, killing Zhang Yizhi and Zhang Changzong, and then surrounding Wu Zetian. She, in fear, asked, "Who is disturbing me?" Zhang Jianzhi responded, in a formalistic manner:
Wu Zetian subsequently tried to have Li Xian returned to the palace of the Crown Prince, but the coup leaders ignored her. While the coup leaders allowed Wu Zetian to retain the title of "emperor," they had her put under house arrest at the secondary palace Shangyang Palace (上陽宮) and forced her to yield the throne to Li Xian, who was formerly emperor, and he was restored to the throne (as Emperor Zhongzong).
In summer 705, by which time Emperor Zhongzong's trust in Zhang and his colleagues had completely been lost, Emperor Zhongzong, following Wu Sansi's recommendation, created the five coup leaders princes -- in Zhang's case, Prince of Hanyang -- but stripped them of chancellor positions. Zhang soon requested to retire back to his home prefecture Xiang Prefecture, and Emperor Zhongzong agreed, making him the prefect of Xiang Prefecture, but not putting him in actual responsibility of the prefecture. His son Zhang Yi (張漪) was made a low level imperial official but ordered to follow his father to Xiang Prefecture.
In spring 706, with all five of the coup leaders already out of the capital, Wu Sansi and Empress Wei made accusations against them, and they were demoted to more remote prefectures (although Zhang was not moved). Wu Sansi then had his strategist Zheng Yin further accuse the five of them of having participated in the plot of Emperor Zhongzong's son-in-law Wang Tongjiao (王同皎) -- who was executed early in 706 after having been accused of plotting to kill Wu Sansi and deposing Empress Wei. The five were further demoted with the provisions that they would never be allowed to return to the capital Chang'an, with Zhang becoming the military advisor to the prefect of Xin Prefecture (新州, roughly modern Yunfu, Guangdong). Wu Sansi then had accusations that Empress Wei was having affairs posted publicly in Luoyang (now eastern capital, with the capital moved back to Chang'an), with the intent of incensing Emperor Zhongzong -- and then accused the five coup leaders of being behind this public humiliation. He then had his associates propose that the five be killed. Emperor Zhongzong, citing that the five had been previously awarded iron certificates that guaranteed that they would not be executed in recognition of their contribution, ordered that they be reduced to commoner rank and permanently exiled to the Lingnan region with their families -- in Zhang's case, to Long Prefecture (瀧州, in modern Ganzhou, Jiangxi). At the suggestion of Cui Shi, Wu Sansi then sent the censor Zhou Lizhen (周利貞) to the Lingnan region under guise of reviewing the affairs of the region but with instructions to kill the five. By the time that Zhou reached the region, though, Zhang had already died. After Emperor Zhongzong's death in 710 and Li Dan, himself a former emperor, was restored (as Emperor Ruizong), Zhang and his colleagues were posthumously honored.

