Between 2000-2017, China was not very active in Afghanistan. China did not contribute troops to fight the Taliban, though it did provide several hundred million dollars of foreign aid to the Afghan government. During this time, Chinese companies also made several significant investments in Afghanistan's mineral and energy industries. However, as argued here, these investments likely were not made at the direction of the Chinese government.
Starting in 2017, China began to take a more active role in Afghanistan's politics and economy. It began serving as a negotiator between Pakistan and Afghanistan in 2017. In 2018, China started to meet with Taliban for preliminary peace talks that aimed to end the war in Afghanistan. Around that time, Afghan officials also began engaging with China economically by joining in on discussions related to China's Belt and Road Initiative. By 2018, China was considered Afghanistan's "biggest foreign investor."
Today, China has two main interests in Afghanistan: security and economic.
China's Xinjiang province shares a border with 8 countries, including Afghanistan. The Uyghurs, most of whom identify as Muslim, have historically lived in the territory that makes up Xinjiang province. There have been several separatist movements among the Uyghurs since the start of the 20th century, all of which seek to establish an independent state of East Turkestan.
For this discussion, the most relevant of these organizations is the East Turkestan Islamic Movement (ETIM, also known as the Turkistan Islamic Movement), which emerged in the late 1980s/early 1990s. ETIM embraced terrorism as a way to further its political agenda, and group members have bombed buses, stores, and hotels in China.
ETIM has long maintained a relationship with militants based in Afghanistan, including the Taliban and Al Qaeda. The United Nations, China, and the United States have all alleged that ETIM received financial support and training from Al Qaeda and the Taliban. Moreover, ETIM maintained a presence in Afghanistan and staged attacks from there into China and other neighboring countries.
Thus, China's security concerns regarding Uyghur separatists are directly tied to the situation in Afghanistan. Perpetual instability in Afghanistan has enabled the Taliban to thrive and ETIM militants to benefit from Taliban training, funds, and other resources. The Taliban could potentially provide additional aid to other Uyghur separatist groups in the future, which is highly worrying to China.
In an effort to avoid this potential Uyghur-Taliban cooperation, China has recently focused on building a positive relationship with the Taliban. Given the strength of the Taliban, it will undoubtedly continue to be an influential actor in Afghanistan. China has recognized that the Taliban will stick around and has begun to cultivate positive relations. China reportedly promised to help the Taliban rebuild post-war Afghanistan's infrastructure if the Taliban promised to limit its ties to Uyghur separatists and prevent them from using Afghanistan as a base.
China is also interested in Afghanistan for its economic potential. China's Belt and Road Initiative (BRI) is a multi-country investment strategy to "to build infrastructure and win influence overseas." China's BRI investments in Pakistan are directly threatened by militants on the Pakistan-Afghanistan border, and China has an interest in encouraging a stable Afghanistan where these militants will not be able to thrive.
Additionally, with the withdrawal of U.S. troops, China also sees an opportunity to expand BRI projects into Afghanistan. Afghanistan is in need of infrastructure repair after a 20-year long war, and the Taliban has been in talks with the Chinese government to negotiate an economic deal.