I recently got an M0 clone. I favor using my own tooling using cmake, hence why I'm using avrdude manually.
Considering it was an issue from where avrdude was invoked and not necessarily what is invoked, I investigated the issue.
I found that avrdude provides a -u flag which says "Disable safemode, default when running from a script." Because the IDE uses Java and probably calls the upload as a separate process of some kind, it is added by default. The running from script detection mechanism is probably not perfect.
However, once I read that, I tried again flashing using avrdude, this time with -u, via the command line and I found that it worked perfectly.