Galaxy clusters are the most massive collapsed structures in the universe whose potential wells are filled with hot, X-ray emitting intracluster medium. Observations however show that a significant number of clusters (the so-called cool-core clusters) also contain large amounts of cold gas in their centres, some of which is in the form of spatially extended filaments spanning scales of tens of kiloparsecs. These findings have raised questions about the origin of the cold gas, as well as its relationship with the central active galactic nucleus (AGN), whose feedback has been established as a ubiquitous feature in such galaxy clusters. Here we report a radiation hydrodynamic simulation of AGN feedback in a galaxy cluster, in which cold filaments form from the warm, AGN-driven outflows with temperatures between $10^4$ and $10^7$ K as they rise in the cluster core. Our analysis reveals a new mechanism, which, through the combination of radiative cooling and ram pressure, naturally promotes outflows whose cooling time is shorter than their rising time, giving birth to spatially extended cold gas filaments. Our results strongly suggest that the formation of cold gas and AGN feedback in galaxy clusters are inextricably linked and shed light on how AGN feedback couples to the intracluster medium.