For bash, you may be able to do something like:
function set_histfile {
export HISTFILE="$HOME/.bash_history_$(pwd | tr '/' '_')"
}
PROMPT_COMMAND="set_histfile; $PROMPT_COMMAND"
There may be other ways, but probably can't do it without PROMPT_COMMAND.
Someone else mentioned "direnv", too.