silk. Zhang Fei was also appointed as the Administrator () of Baxi Commandery. Hanzhong Campaign Battle of Baxi In around 215, Cao Cao attacked and defeated Zhang Lu, after which Hanzhong Commandery came under his control. Cao Cao left Xiahou Yuan, Zhang He and others behind to defend Hanzhong while he returned to Ye. During that time, Zhang He led his forces to attack Baxi Commandery with the aim of forcing Baxi's residents to relocate to Hanzhong Commandery. His army passed through Dangqu (), Mengtou () and Dangshi () counties, and encountered Zhang Fei's troops. Both sides held their positions for over 50 days, after which Zhang Fei led about 10,000 elite soldiers and took an alternative route to attack Zhang He. As the mountain paths were very narrow and inaccessible, Zhang He's army was effectively divided into two because the troops at the front and the rear were unable to contact and assist each other, resulting in a victory for Zhang Fei. Zhang He and about ten of his men escaped on foot through a shortcut and retreated back to Nanzheng. Peace was restored in Baxi Commandery. Conquest of Hanzhong In 217, Liu Bei mobilised his forces and personally led a campaign to seize control of Hanzhong Commandery from Cao Cao. He ordered Zhang Fei and Ma Chao to supervise Wu Lan (), Lei Tong () and Ren Kui () to attack Wudu Commandery, which was defended by Cao Hong. Zhang Fei attempted to trick Cao Hong into believing that they were planning to seal his retreat route, but Cao Xiu saw through the ruse, and Wu Lan suffered a major defeat which absolved Zhang Fei from continuing the campaign – Lei Tong and Ren Kui were killed in action while Wu Lan fled to Yinping Commandery (陰平郡) and was killed by a Di chieftain, Qiangduan (). In 219, Liu Bei emerged victorious in the Hanzhong Campaign and proclaimed himself "King of Hanzhong" (). He appointed Zhang Fei as General of the Right (). Liu Bei later planned to return to Chengdu and he wanted to leave a veteran general behind to guard Hanzhong. Many people believed that Zhang Fei would receive this responsibility and even Zhang Fei himself thought so too. However, to everyone's surprise, Liu Bei chose Wei Yan instead and appointed him as the Administrator of Hanzhong. Service in Shu Han In 221, Liu Bei declared