In 640, Zhang was recalled to the capital Chang'an to serve as the minister of public works. In 641, he was made the head of the household for Emperor Taizong's son and crown prince, Li Chengqian, but was also sent out of the capital to serve as the commandant at Luo Prefecture (i.e., modern-day Luoyang, Henan). The general Hou Junji, who was unhappy that he had been briefly imprisoned on accusations of embezzlement after he conquered Gaochang, tried to instigate Zhang by asking him, "Who squeezed you out?" Zhang, in jest, responded, "Other than you, who can squeeze me out?" Hou responded, "I conquered a kingdom, but I ran into someone throwing a tamper tantrum big enough to overturn a house. What strength do I have to squeeze you out?" He then rolled up his sleeves and yelled, "I am so unhappy that I would rather die. Do you want to commit treason? I will commit treason with you!" Zhang secretly reported this exchange to Emperor Taizong, but Emperor Taizong pointed out that this was a private conversation with no corroboration, and took no action on it. After Hou was revealed to have plotted with Li Chengqian to overthrow Emperor Taizong in 643, Li Chengqian was deposed and exiled, while Hou was executed. Because Zhang had previously warned Emperor Taizong about Hou, Emperor Taizong rewarded him by recalling him to the capital to serve as the minister of justice and also bestowing him the additional designation of "Canyu Chaozheng" (), making him a "de facto" chancellor. (Earlier in 643, when Emperor Taizong commissioned the Portraits at Lingyan Pavilion to commemorate the 24 great contributors to Tang rule, Zhang's was one of the portraits commissioned.)