Cancer driver mutations often display mutual exclusion or co-occurrence, underscoring the key role of epistasis in carcinogenesis. However, estimating the magnitude of epistasis and quantifying its effect on tumor evolution remains a challenge. We develop a method (Coselens) to quantify conditional selection on the excess of nonsynonymous substitutions in cancer genes. Coselens infers the number of drivers per gene in different partitions of a cancer genomics dataset using covariance-based mutation models and determines whether coding mutations in a gene affect selection for drivers in any other gene. Using Coselens, we identify 296 conditionally selected gene pairs across 16 cancer types in the TCGA dataset. Conditional selection affects 25%-50% of driver substitutions in tumors with >2 drivers. Conditionally co-selected genes form modular networks, whose structures challenge the traditional interpretation of within-pathway mutual exclusivity and across-pathway synergy, suggesting a more complex scenario where gene-specific across-pathway epistasis shapes differentiated cancer subtypes.