Scripts often need to know where they run. tmux can tell them, using the same formats as the status bar.
tmux display-message -p '#S' # session name
tmux display-message -p '#{pane_current_path}' # folder of the pane
Without -p the text is shown in the status bar for a moment. With -p it goes to standard output, so you can store it in a variable: name=$(tmux display-message -p '#S').
The formats are the same #{...} variables the status line uses. tmux display-message -a lists every variable and its current value, which is a quick way to find the one you need.
Outside tmux the command fails, because there is no current session. Check for the TMUX environment variable in your script before you rely on it.
Try it without risk: start a throwaway session with tmux new -s scratch, use the shortcut or command above there, look at what changes, and close it again with tmux kill-session -t scratch. Nothing else on your machine is touched.
Further reading: tmux manual page (OpenBSD, official), tmux wiki: Getting Started (official)