Use the FileChanged Hook to Reload Environment Variables Automatically
When Claude edits your .envrc or .env file, your shell environment doesn't update until you manually source it. The FileChanged hook fixes that without any extra prompts.
Add this to your .claude/settings.json:
{
"hooks": {
"FileChanged": [
{
"matcher": "\\.envrc|\\.env",
"hooks": [
{
"type": "command",
"command": "direnv allow . && direnv export bash"
}
]
}
]
}
}
The matcher field uses a regex against the file basename, so .envrc|.env catches both common formats. Every time Claude writes to a matched file, the hook fires and your environment reloads automatically in the session.
If you are not using direnv, you can source the file directly instead:
{
"type": "command",
"command": "set -a && source .env && set +a"
}
The FileChanged hook also supports a companion variable CLAUDE_ENV_FILE — any env vars written to that file by your hook script will persist across subsequent bash commands in the session, so Claude picks up the refreshed values immediately.
This pairs naturally with the CwdChanged hook, which fires whenever Claude changes directory, making it easy to load project-specific environments automatically as Claude navigates between subdirectories.
Stop manually sourcing your env files — let the hook do it every time Claude touches one.
via @yokatsuki
Log in to leave a comment.
The autoUpdatesChannel setting pins Claude Code to a stable release track that skips versions with major regressions.
The language setting makes Claude respond in your preferred language by default, across every session and project.
The attribution setting lets you customize or completely remove Claude's Co-Authored-By trailer from git commits and pull requests.