A thermodynamics-based unsaturated hydro-mechanical-chemical (HMC) coupling model is developed to analyze the coupled response and stability of boreholes in chemically active gas formations. The newly coupled constitutive relations are formulated by incorporating the chemical effect into the solid-gas-liquid unsaturated framework to account for the interactions between rock deformation, gas-liquid two-phase flow, and chemical potential difference. Compared with previous models, the present model shows significant prediction differences in field variables and wellbore stability evolution. The maximum absolute difference of pore pressure, effective radial stress, effective tangential stress, and collapse pressure can reach 8.98 MPa, 7.64 MPa, 7.29 MPa, 7.65 MPa, respectively. It is more conservative to select a long-term wellbore collapse pressure rather than a short-term one to guide drilling operations. The two-phase flow behavior, jointly controlled by wellbore pressure, capillary pressure, and chemical osmosis effect, provides a more realistic observation of the mud intrusion process. Compared with low salinity muds, high salinity muds can effectively impede the mud intrusion into the formation, which is more conducive to preventing wellbore collapse, but at the same time increases the risk of wellbore fracture. Sensitivity analysis shows that solute diffusion and reflection coefficients affect early wellbore stability through pore pressure and solute transport, while the chemical swelling coefficient has a long-term effect through chemically induced deformation. The results can provide theoretical guidance for quantitative optimization of mud parameters and prevention of wellbore instability when drilling in chemically active gas formations.