Zhang Zhongwu thereafter ruled Lulong in de facto independence from the imperial government, but followed Emperor Wuzong's orders during Emperor Wuzong's campaigns against the Huigu Khanate remnants and the warlord Liu Zhen, and therefore enjoyed a strong relationship with the imperial government.
[5] When Zhang Zhifang arrived at Chang'an, Emperor Xuānzong sent messengers to welcome him, and made him a general of the imperial guards.
As Zhang had a large family with him, Emperor Xuānzong awarded the salary of an honorary minister of public works (工部尚書, Gongbu Shangshu).
On one occasion, when he killed an imperial guard messenger by caning due to a minor fault that should not have been punished with death, he was reduced in title from Jinwu Dajiangjun (金吾大將軍) to Yulin Tongjun (羽林統軍).
However, thereafter, he was accused of allowing his subordinates to commit banditry, and he was demoted to be the military advisor to the prefect of Kang Prefecture (康州, in modern Zhaoqing, Guangdong).
Emperor Xizong therefore made Zhang Zhifang an honorary You Pushe and also returned him to the title of Jinwu Dajiangjun.
Zhang Zhifang led a group of Tang officials and generals to Bashang (霸上, in modern Xi'an, Shaanxi) to welcome Huang.