Robust models capable of maintaining strong generalization performance under data distribution shifts are crucial for real-world applications. Identifying flat minima is an effective strategy, especially the classic Sharpness-Aware Minimization (SAM). However, in domain generalization tasks, feature discrepancies of the same class across different domains can cause SAM’s uniform perturbation strategy to be dominated by domain-class pairs with large gradients, leading to inconsistent convergence and suboptimal sharp minima. To address this issue, we propose Class-Adaptive Variance-Guided Optimization (CAVGO). CAVGO adaptively calibrates perturbation directions by minimizing the variance of domain-class pair losses, achieving class-level cross-domain alignment. It further incorporates a novel gradient update strategy combined with Class-Adaptive Label Smoothing (CALS) to effectively mitigate bias toward hard-to-classify samples. By fully leveraging statistical differences across domains and classes, CAVGO significantly enhances model robustness and transferability under complex multi-source distributions. Extensive experiments on multiple domain generalization benchmarks demonstrate that CAVGO consistently outperforms existing methods, exhibiting stable generalization advantages and strong potential for practical applications.