Around 239, when Cao Rui became ill, he resolved to pass the throne to Cao Fang. Initially, he wanted to entrust Cao Fang to his uncle Cao Yu (曹宇), who would serve as a regent along with Xiahou Xian (夏侯獻), Cao Shuang, Cao Zhao (曹肇), and Qin Lang (秦朗). However, Cao Rui's trusted officials Liu Fang (劉放) and Sun Zi (孫資) were not on good terms with Xiahou Xian and Cao Zhao, and were apprehensive about them becoming regents. Eventually, Cao Rui was persuaded to appoint Cao Shuang and Sima Yi. Cao Yu, Cao Zhao and Qin Lang were excluded from the regency.
Half a month later, when Cao Rui was on his deathbed, Sima Yi arrived at Luoyang. Cao Rui held onto Sima's hand and summoned Cao Fang and Cao Xun (another adopted son of Cao Rui) to his bedside. He pointed out Cao Fang and told the boy to hug Sima, as he would hug his father. Cao Rui then instated Cao Fang as crown prince and died on the same day.