We study the counterparty risk for a credit default swap (CDS) in a regime-switching market driven by an underlying continuous-time Markov chain. We model the default dependence via some correlated Cox processes with regime-switching shot noise intensities containing common shock. Under the proposed model, the general bilateral counterparty risk pricing formula for CDS contracts with the possibility of joint defaults is presented. Based on some expressions for the conditional Laplace transform of the integrated intensity processes, semi-analytical solution for the bilateral credit valuation adjustment (CVA) is derived. When the model parameters satisfy some conditions, explicit formula for the bilateral CVA at time 0 is also given.