In 621, Wang Shichong's Zheng state was destroyed by forces from the faction that would later become the
Tang dynasty. As Zhang had been a Sui official before, he was made the sheriff of Gushou County (穀熟, in modern
Shangqiu,
Henan). Later, after he passed an imperial examination, he was made the secretary general of Fuping County (富平, in modern
Weinan,
Shaanxi), and was considered capable in his position. After his term of office was over, he was made an assistant imperial censor, and was known for willing to submit accusations against other officials for misbehavior notwithstanding their honorable positions. The second Tang emperor,
Emperor Taizong, the reigning emperor at the time, was impressed by him, and stated to his
chancellor Fang Xuanling, "In both history and current times, officials often came into their offices due to recommendations by others. But I selected Zhang Xincheng myself, without anyone else's recommendations." On one occasion, possibly in 627, when Emperor Taizong, at an imperial feast, began to talk about differences between people from the
Guanzhong region and those from the Shandong region (i.e., those from east of modern
Sanmenxia,
Henan, not those from modern
Shandong), Zhang found the talk to be inappropriate, and stated, "Your subject has heard that the
Son of Heaven should view the entire empire as his home, and should not divide it through geographical limitations; if you do so, you will show prejudice." Emperor Taizong was impressed, and awarded Zhang a horse, a set of clothing, and money. He also began to consult Zhang on important matters and promoted Zhang to the post of imperial attendant. In 641, Emperor Taizong, at an imperial gathering, made the comment, "Although I am the lord of the empire, but I also often have to serve as general and chancellor." After Zhang withdrew from Emperor Taizong's presence, he submitted a note indicating his belief that the comment was inappropriate—noting that it sounded like he was arguing over achievements with his subjects. Emperor Taizong approved of his comment. By 643, when Emperor Taizong deposed his eldest son and
crown prince Li Chengqian (over Li Chengqian's plotting to overthrow him) and replaced him with
Li Zhi, Zhang was the assistant minister of justice. Emperor Taizong, when selecting staff members for Li Zhi, selected Zhang as an assistant head of the crown prince's household. In 645, during Emperor Taizong's campaign against
Goguryeo, Emperor Taizong left Li Zhi at Zhang's home, Ding Prefecture, to be in charge of logistics, assisted by a number of officials led by the chancellor
Gao Shilian, and Zhang was a member of Li Zhi's staff there. Li Zhi told Zhang, "This gives you a chance to return home in honor." He also gave Zhang supplies to allow him to worship his ancestors, and Zhang took this opportunity to recommend a number of scholars from his home, and while Li Zhi rejected making them officials (on the account that they were too old in age), he gave them rewards. After Emperor Taizong returned to the capital
Chang'an after the Goguryeo campaign, he had Zhang serve as surveyor of the
Henan region, and after that tour made him the acting assistant head of the executive bureau of government. In 646, Emperor Taizong, in the aftermaths of the collapse of Tang's one-time vassal and adversary
Xueyantuo to the north, went to the important northern defense prefecture of Ling Prefecture (靈州, roughly modern
Yinchuan,
Ningxia), to try to affirm the faith of the former vassals of Xueyantuo, who were by now directly Tang vassals. Initially, he was taking Li Zhi with him, but Zhang submitted a petition stating that this would better serve as an opportunity for Li Zhi to serve as regent at Chang'an, so that he could become familiar with imperial governance. Emperor Taizong agreed, and rewarded Zhang by giving him the honorific title of
Yinqing Guanglu Daifu (). == During Emperor Gaozong's reign ==