Best Way to Grab Post ID from Plugin

loop_end hook is passing WP_Query object as argument. You can use is_main_query() method on that object (don’t confuse with function of same name) and it will only be true for main query and not secondary ones.

tech