To set up this underhook counter using a butterfly guard sweep. Nick Albin starts by showing a side control escape vs a tight opponent and using the underhook.

Then he pairs it together with butterfly guard sweep counter When the person comes up with the underhook.

There are many times in BJJ where a person from the bottom will come up with an under hook. If you look for it, often times there is a butterfly guard sweep opportunity there.