Both cases seem like a "tragedy of the commons" - using antibiotics/hookworm treatments (aggressively/preemptively) causes your own livestock/dog to become healthier (or stay healthy in the first place), but increases the chance of mutations that will be resistant to the treatment, which affects everyone (even those not actively using the treatment).
This problem seems not solvable except through regulation, unless I'm missing something.
Actually (and this might sound crazy, but I encourage you to think through it and respond), why not apply this logic to COVID-19 vaccines, as well? That is, why not use non-pharmaceutical means to try to control the virus (which would be equivalent to dog racetrack owners trying to keep their racetrack clean (alcohol misting? dehydration of the track? I don't know anything about this) or farms that raise livestock making their environments less dense and cleaner) and only administer the vaccine to those who are truly at risk? That seems like it would minimize the rate of mutations that specifically affect the effectiveness of the existing treatments. Or is there a difference between SARS-CoV-2 and hookworms/common livestock bacterial infections that matters in this case?