It turns out that IsRunningCommandlet() does work to exclude cooking. The code it encloses won’t run when any other commandlet is run, which may not be desired.
There is also a global, GIsCookerLoadingPackage, which is set to true when packages are being loaded/saved for cooking.