> how are you supposed to defend yourself against attacks like this?

You can try not installing malware like Claude Code or, if you absolutely must, doing it in a sandbox.