What you want is:
git stash list
git stash allows you to provide a message. You can use a generated token as your message so that you know it won’t conflict with other git stash messages.
Then, when you want to check whether or not to pop, simply check if the git stash list output contains your token. If so, pop the stash.