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.
When Claude writes error messages, button labels, validation text, or onboarding flows, it defaults to generic developer-speak. Add a "Users" section to your CLAUDE.md describing who your actual users are — their technical level, industry jargon, and what they care about — so Claude writes copy that makes sense to THEM, not to developers.
Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.
Every project has traps — the billing module that silently fails if you forget to queue the job, the legacy table with column names that don't match the model, the config value that must be set before tests run. Document these gotchas in your CLAUDE.md so Claude avoids the same mistakes your team spent days debugging.