The Anthology of the Patriarchal Hall tells us that in 527 during the Liang Dynasty, Bodhidharma, the first Patriarch of Chán, visited the Emperor Wu (Emperor Xiāo Yǎn 蕭衍 (posthumous name Wǔdì 武帝) of Liáng 梁 China), a fervent patron of Buddhism
The emperor asked Bodhidharma, "How much karmic merit have I earned for ordaining Buddhist monks, building monasteries, having sutras copied, and commissioning Buddha images?" Bodhidharma answered, "None. Good deeds done with worldly intent bring good karma, but no merit." The emperor then asked Bodhidharma, "So what is the highest meaning of noble truth?" Bodhidharma answered, "There is no noble truth, there is only void." The emperor then asked Bodhidharma, "Then, who is standing before me?" Bodhidharma answered, "I know not, Your Majesty."
From then on, the emperor refused to listen to whatever Bodhidharma had to say. Although Bodhidharma came from India to China to become the first patriarch of China, the emperor refused to recognize him. Bodhidharma knew that he would face difficulty in the near future, but had the emperor been able to leave the throne and yield it to someone else, he could have avoided his fate of starving to death.
According to the teaching, Emperor Wu's past life was as a bhikshu. While he cultivated in the mountains, a monkey would always steal and eat the things he planted for food, as well as the fruit in the trees. One day, he was able to trap the monkey in a cave and blocked the entrance of the cave with rocks, hoping to teach the monkey a lesson. However, after two days, the bhikshu found that the monkey had died of starvation.
Supposedly, that monkey was reincarnated into Hou Jing of the Northern Wei Dynasty, who led his soldiers to attack Nanjing. After Nanjing was taken, the emperor was held in captivity in the palace and was not provided with any food, and was left to starve to death. Though Bodhidharma wanted to save him and brought forth a compassionate mind toward him, the emperor failed to recognize him, so there was nothing Bodhidharma could do. Thus, Bodhidharma had no choice but to leave Emperor Wu to die and went into meditation in a cave for nine years.
This encounter would later form the basis of the first kōan of the collection The Blue Cliff Record. However that version of the story is somewhat different. In the Blue Cliff's telling of the story, there is no claim that Emperor Wu did not listen to Bodhidharma after the Emperor was unable to grasp the meaning. Instead, Bodhidharma left the presence of the Emperor once Bodhidharma saw that the Emperor was unable to understand. Then Bodhidharma went across the river to the kingdom of Wei.
After Bodhidharma left, the Emperor asked the official in charge of the Imperial Annals about the encounter. The Official of the Annals then asked the Emperor if he still denied knowing who Bodhidharma was? When the Emperor said he didn't know, the Official said, "This was the Great-being Guanyin (i.e., the Mahasattva Avalokiteśvara) transmitting the imprint of the Buddha's Heart-Mind."
The Emperor regretted his having let Bodhidharma leave and was going to dispatch a messenger to go and beg Bodhidharma to return. The Official then said, "Your Highness, do not say to send out a messenger to go fetch him. The people of the entire nation could go, and he still would not return."