In 907, Zhu Quanzhong had Emperor Ai yield the throne to him, ending Tang Dynasty and starting a new Later Liang with him as its Emperor Taizu. Wang Jian the military governor of Xichuan, along with several other regional governors, refused to recognize the new Later Liang emperor, but after a joint declaration by Wang and Yang Wo the military governor of Huainan Circuit (淮南, headquartered in modern Yangzhou, Jiangsu) failed to caused a mass uprising by Later Liang subjects, Wang decided to declare himself emperor of a new state of Shu (known in history as Former Shu).[4] He respected the Tang officials who fled to his realm, and Zhang Ge was among those people that he treated well.[1] As of 908, Zhang was serving as an imperial scholar (翰林學士, Hanlin Xueshi) when there was a Buddhist monk who gauged one eyeball out and offered to Wang as a sign of his devotion. Wang was initially touched and was ready to award food enough to feed 10,000 monks. Zhang urged against it, pointing out that mutilating oneself was not something that should be rewarded for. Wang agreed. Shortly after, Zhang, who was also by that point referred to as the deputy minister of census (戶部侍郎, Hubu Shilang), was made Zhongshu Shilang (中書侍郎, deputy head of the legislative bureau of government (中書省, Zhongshu Sheng)) and a chancellor with the designation Tong Zhongshu Menxia Pingzhangshi (同中書門下平章事). It was said that while Zhang served as chancellor, he flattered and agreed with Wang, and found ways to eliminate people who were more talented than he was.[4]
In 912, when Former Shu was engaged in a war with its northern neighbor Qi, Later Liang's Emperor Taizu, hoping to exploit the situation, sent a group of emissaries, headed by the official Lu Ci (盧玼), to Former Shu, hoping to establish friendly relations, and his letter to Wang went as far as addressing Wang as "older brother."[5] However, one of the seals on the letter bore the text, "From the Great Liang to Shu," and Zhang pointed out that this was a form of address that treated Shu as a vassal. Wang, in reaction, wanted to kill the emissaries, but Zhang persuaded him not to, pointing out that this was the fault of the Later Liang officials who drafted the text, and should not be blamed against the emissaries or cause disruption of the relationship. Thereafter, Wang treated Zhang with even greater respect.[1]
In 913, Former Shu's then-crown prince Wang Yuanying, who was locked in a power struggle against the director of palace communications Tang Daoxi, killed Tang in an armed confrontation, but shortly after was himself killed by his own soldiers. Wang Jian initially mourned Wang Yuanying deeply and suspected his adoptive son, the general Wang Zonghan (王宗翰), of killing Wang Yuanying without first receiving his approval, and there were fears that Wang Jian would carry out wide-scale reprisals. However, at that time, Zhang, who was drafting Wang Jian's declaration to the people regarding the incident, submitted his draft, and the draft contained language that read, "Without carrying out the execution by the axe, the imperial shrine would be severely harmed." Wang Jian realized that despite his love for Wang Yuanying, he could not let it damage the state's foundations, and therefore ordered that Wang Yuanying be posthumously demoted to commoner rank; no reprisals occurred for Wang Yuanying's death besides the execution of the actual killer and some executions or exiles of Wang Yuanying's staff members.[5]
Shortly after Wang Yuanying's death, the official Pan Kang urged Wang Jian to create a new crown prince. Wang Jian initially considered Wang Zonglu (王宗輅) the Prince of Ya, whom he considered to most like himself, and Wang Zongjie (王宗傑) the Prince of Xin, whom he considered to be most talented. However, Wang Jian's favorite concubine Consort Xu wanted to have her son Wang Zongyan the Prince of Zheng, who was Wang Jian's youngest son, become crown prince, and she had Tang Wenyi (唐文扆) the overseer of imperial stables persuade Zhang to support Wang Zongyan. Zhang drafted a petition supporting Wang Zongyan, and then met with a number of generals with great accomplishments, falsely informing them that it was Wang Jian's wishes that they publicly support Wang Zongyan; those generals, believing Zhang, signed the petition. After Wang Jian received the petition, he, despite his doubts about Wang Zongyan's youth and lack of ability, believed that this was actually the wishes of the officials and created Wang Zongyan crown prince.[5] Later, after Wang Jian realized Zhang's role in Wang Zongyan's becoming crown prince and saw that Wang Zongyan was wasting time in cockfighting and polo with the other princes, became angry at Zhang. However, with Consort Xu protecting Zhang, Wang Jian never removed Zhang from his post.[6]
In 918, Wang Jian grew deathly ill, and he entrusted Wang Zongyan to a group of officials led by his adoptive son, the general Wang Zongbi. However, Tang Wenyi wanted to hold onto power, and therefore, when Wang Jian grew even sicker, used the imperial guard soldiers he commanded to prevent the officials from entering the palace to see Wang Jian. However, his associate Pang Zaiying (潘在迎) betrayed him and allowed Wang Zongbi and the other officials inside the palace to take charge. Tang was exiled and, as soon as Wang Jian died, executed. Wang Zongyan took the throne.[6] (Shortly after, Wang Zongyan changed his name to Wang Yan.)[7]
Zhang Ge remained chancellor in the immediate aftermaths of Wang Yan's ascension to the throne, but was fearful of what would happen to him due to his long-term association with Tang Wenyi. He considered resigning his post first himself, but was dissuaded from doing so by his associate Yang Fen (楊玢) the minister of rites. However, shortly after, both Zhang and Yang were demoted, and Zhang was initially made the prefect of Mao Prefecture (茂州, in modern Ngawa Tibetan and Qiang Autonomous Prefecture, Sichuan), then further demoted to be the census officer at Wei Prefecture (維州, in modern Ngawa as well). Upon further accusations by the director of palace communications, Yu Ningji, Zhang was then further removed from all offices and exiled to Heshui Base (合水鎮, in Mao Prefecture). Yu further directed the prefect of Mao, Gu Chengyan (顧城郾) to guard Zhang carefully and submit further accusations against him. The wife of the prominent general Wang Zongkan (王宗侃, also adoptive son of Wang Jian's), however, was also named Zhang and wanted to protect him, and therefore persuaded Gu, through Gu's mother, not to do so, leading to Yu later finding excuses to punish Gu, but allowing Zhang's life to be saved.[6]
By 924, however, Zhang had returned to the Former Shu imperial government to serve as You Pushe (右僕射, one of the heads of the executive bureau (尚書省, Shangshu Sheng)). That year, he was again made Zhongshu Shilang and chancellor. He took vengeance on an administrator at the legislative bureau, Wang Lurou (王魯柔), who had joined in the accusations against him in 918, and had Wang caned to death. (This led his associate Xu Ji (許寂) to comment, "Lord Zhang is talented but unwise. His killing of Wang Lurou will cause other people to feel insecure. This is a way to bring disaster." However, no actual repercussions of Wang Lurou's death appeared to have occurred.)[8]