$ recombobulate _
home / tips / auto-load-your-dev-environment-when-changing-directories
45

Auto-Load Your Dev Environment When Changing Directories

recombobulate @recombobulate · Mar 26, 2026 · Configuration
auto-load-your-dev-environment-when-changing-directories

If you use direnv to manage per-project environment variables, Claude Code won't automatically pick up those environments when you switch directories. The CwdChanged hook fixes this by running a command every time Claude changes its working directory.

Add this to your .claude/settings.json:

{
  "hooks": {
    "CwdChanged": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "eval \"$(direnv export bash)\" && if [ -n \"$CLAUDE_ENV_FILE\" ]; then direnv export bash | grep 'export' >> \"$CLAUDE_ENV_FILE\"; fi"
          }
        ]
      }
    ]
  }
}

The CLAUDE_ENV_FILE variable is a special file Claude Code provides in hooks. Anything you write to it as export VAR=value lines gets loaded into Claude's environment for the rest of the session.

You can also watch .envrc files directly with the FileChanged hook so Claude reloads the environment whenever that file changes — without you needing to switch directories:

{
  "hooks": {
    "FileChanged": [
      {
        "matcher": ".envrc",
        "hooks": [
          {
            "type": "command",
            "command": "eval \"$(direnv export bash)\" && if [ -n \"$CLAUDE_ENV_FILE\" ]; then direnv export bash | grep 'export' >> \"$CLAUDE_ENV_FILE\"; fi"
          }
        ]
      }
    ]
  }
}

Keep Claude's environment in sync with your project without ever thinking about it.


via Claude Code Docs — Hooks

~/recombobulate $ tip --comments --count=0

Log in to leave a comment.

~/recombobulate $ tip --related --limit=3
0
Describe Your Users in CLAUDE.md So Claude Writes Appropriate Copy, Error Messages, and UX

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.

recombobulate @recombobulate · 1 day ago
1
Create Custom Agents with --agent for Scoped Sessions

Use the --agent flag with custom markdown files in .claude/agents/ to launch purpose-built Claude sessions with restricted tools and scoped system prompts.

recombobulate @recombobulate · 1 day ago
106
Add Known Gotchas and Pitfalls to Your CLAUDE.md So Claude Avoids Mistakes Your Team Already Made

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.

recombobulate @recombobulate · 1 day ago