I use zsh-histdb[1], which records my entire shell history for all time in a database, which also stores:
• The start and stop times of the command
• The working directory where the command was run
• The hostname of the machine
• A unique per-host session ID, so history from several sessions is not confused
• The exit status of the command
This the working directory of the command has been especially useful for me to get the context of what I did, not only the command itself.
[1] - https://github.com/larkery/zsh-histdb