Goguryeo–Tang War
Later in 644, when Emperor Taizong launched a major attack against Goguryeo, he had the generals Li Shiji and Li Daozong lead the forward forces, while commanding the main forces himself, assisted by Zhangsun, Cen, and Yang Shidao. In summer 645, at a major battle against the main Goguryeo forces commanded by the generals Go Yeonsu (高延壽) and Go Hyezin (高惠真) engaged Tang forces, Emperor Taizong had Li Shiji command 15,000 men to serve as decoy, and when Goguryeo forces attacked Li Shiji, Zhangsun Wuji attacked them from behind with 11,000 men, and Li Shiji and Zhangsun, as well as Emperor Taizong himself, defeated Goguryeo forces, forcing their surrender. He then considered directly attacking Goguryeo's capital Pyongyang itself, but Li Shiji believed that if Ansi (安市, in modern Anshan, Liaoning) was not captured first, the general in command of Ansi (a capable general known in Korean popular legends as Yang Manch'un, although whether that was his real name is unknown), might attack Tang forces from the rear. Emperor Taizong agreed, and therefore put Ansi under siege again. However, the commander at Ansi was a capable defender, and the resolve of the defenders was strengthened when Li Shiji, in anger, declared that after the fall of the city all residents would be slaughtered. With the Tang forces bogged down in sieging Ansi, a number of officials suggested skipping past Ansi and attacking Ogol (烏骨, in modern Dandong, Liaoning) and then head toward Pyongyang. Zhangsun opposed, believing the strategy to be too risky without first capturing Ansi and Geonan (建安, in modern Yingkou, Liaoning) first. Emperor Taizong agreed and continued sieging Ansi, but still could not capture it. In fall 645, with winter approaching, Emperor Taizong was forced to withdraw. (The Song dynasty historian Hu Sanxing, the commentator to the Zizhi Tongjian, commented that overcautiousness was what cost Emperor Taizong the victory, indirectly blaming Zhangsun for opposing the strategy to attack Pyongyang directly.) As the army retreated, Zhangsun was responsible for building a temporary bridge over the Liao River to allow the army to cross.
In 647, when Zhangsun's uncle Gao Shilian died, Emperor Taizong, who had just recently himself recovered from an illness, wanted to attend Gao's wake, but Zhangsun lay down in the path of his horse, blocking him, reasoning that as someone who had recently recovered, it was inappropriate for Emperor Taizong to attend the wake. Emperor Taizong, due to Zhangsun's opposition, relented. In summer 647, Emperor Taizong made Zhangsun the commandant at Yang Prefecture (i.e., Jiangdu), but did not actually send him to Yang Prefecture. In fall 647, when a commoner named Duan Zhichong (段志沖) submitted a petition to Emperor Taizong, asking him to yield the throne to Li Zhi, Li Zhi became concerned that Emperor Taizong would suspect that the proposal came from him, and Zhangsun requested that Duan be executed. Emperor Taizong, however, was unfazed, and took no actions against Duan.
In spring 648, Emperor Taizong made Zhangsun the acting head of the legislative bureau—also a chancellor post—and further gave instructions that he also be in charge of the other two main bureaus of government, the executive and the examination bureaus, effectively putting Zhangsun in command of all of the government.
In summer 649, Emperor Taizong was seriously ill, while at the summer palace Cuiwei Palace (翠微宮). He summoned Zhangsun and Chu to his bedside and entrusted Li Zhi to them. He soon died, and by Zhangsun's orders, his death was kept a secret until his casket, accompanied by Li Zhi, was returned to Chang'an. Li Zhi then took the throne (as Emperor Gaozong).