Kinoko's TIL Log

ZDOTDIR Relocates Zsh Config and Runtime Out of HOME

The Point

After setting ZDOTDIR, zsh reads all startup config files from that directory (instead of $HOME) and writes runtime data (.zsh_history, .zsh_sessions) there too. This means $HOME only needs a single ~/.zshenv as the bootstrap.

Explanation

Zsh’s startup order always reads /etc/zshenv first, then $HOME/.zshenv – this is the only file hardcoded to $HOME. Once ~/.zshenv does export ZDOTDIR=..., all subsequent files (.zprofile / .zshrc / .zlogin) are looked up from $ZDOTDIR instead. At the same time, HISTFILE defaults and macOS’s shell session mechanism both use ${ZDOTDIR:-$HOME} as their base, so history and session restore data also land in ZDOTDIR automatically. The result is that $HOME only has a symlink-level .zshenv, while everything else can be centralized in ~/.config/zsh and managed through dotfiles.

Knowledge Sugar

#zsh #dotfiles #zdotdir #macos #shell #til

← Back to Main Page