Zhang Yi was from
Chengdu, the capital of
Yi Province (covering present-day
Sichuan and
Chongqing). He was an avid reader of the
Gongyang Zhuan and studied conscientiously the
Book of Han along with the
Shiji. When
Xu Jing from Runan who was famous for his appraisals entered the Yi Province. He praised Zhang Yi as a nimble man in actions and perspicacious in reasons; even said that he was the equivalent of
Zhong Yao from the central plains. He started his official career after
Liu Zhang, the Governor of Yi Province, nominated him as a
xiaolian (civil service candidate), later assigned as the Chief of Yufu. And was recalled to serve as an official in the Yi's staff. Between 212 and 214, when conflict broke out between Liu Zhang and another warlord
Liu Bei, Liu Zhang sent Zhang Yi to Deyang County to block Liu Bei's reinforcements from entering Yi Province. However, Liu Bei's general
Zhang Fei defeated the force led by Zhang Yi, who was forced to return to Chengdu. In 214, as Liu Bei's forces besieged Liu Zhang in Chengdu, Liu Zhang sent Zhang Yi as his envoy to negotiate the terms of surrender with Liu Bei. Liu Bei reassured the people of his intention and promised that he would treat Liu Zhang well if he surrendered, which Liu Zhang did. Liu Bei's adviser,
Zhuge Liang, named Zhang Yi as one of the most capable officials who served under Liu Zhang, and urged Liu Bei to employ him. Liu Bei then appointed Zhang Yi as the Administrator (太守) of Ba Commandery (巴郡) and was promoted to Managing Metal Internal Cadet General. Here, he managed the manufacture of the warfare equipment and the production and distribution of the agriculture. In late 222 or early 223, after Liu Bei lost the
Battle of Xiaoting against his ally-turned-rival
Sun Quan, the local tribes in southern Yizhou Commandery (益州郡; covering parts of present-day
Yunnan), led by an elderly Yong Kai (雍闓) who was known as a kind man and trusted by them started a rebellion, killed Zheng Ang (正昂) the Shu-appointed Administrator of Jianning Commandery and secretly communicates with Sun Quan. Zhang Yi was sent to reclaim the prefecture, Yong Kai at first pretended that he wanted to yield but later refused to meet him. Then, he falsely declared that Zhang Yi is like a gourd; although impressed by his appearance, his inside is empty. After that, the rebels captured Zhang Yi but did not dare to kill him and instead sent him as a captive to Sun Quan. ==As a prisoner of Wu==