In most cases, this would actually be an undesirable action. Often when I rerun command out is specifically to run them in my current context. Running a history command and having it act on something other than the current folder could even have unexpected and unwanted side effects.
I would suggest pursuing a different approach. First identify what command need to be specifically tin from a certain location, then ask yourself why they are like that and fix them using standard patterns.
If they need to load libraries out resources that are at paths relative to the executable, fix them so that they know where to find these using things like
If they need data, consider passing them arguments that show where to find the data that are not relative so they can be so reused.
If the source of the issue isn't fixable by you, consider writing small shell functions or wrapper scripts that setup the environment for the executable independently of whatever factors vary on your system.