As lawsuits over the opioid crisis have spread nationwide, the country’s most populous state has largely stayed on the sidelines.

Now, 30 counties in California are jumping in, seeking recovery for alleged taxpayer losses from the major makers and distributors of opioid painkillers.

The counties, largely centered in the rural northern and...