Skip to content
BENIBIX Learn

CwdChanged Hook

AI⌨️ Claude CodeConfiguration

Also known as CwdChanged

The event when Claude moves to a new folder with cd.

Think of it like

It is like a light that turns on. It does so when you walk into a room.

Example

Emma's repo has two apps with their own settings. Her CwdChanged hook loads the right ones each time Claude moves between them.

Why it matters

Without it, Claude keeps the old folder's settings after a cd.

Definition

CwdChanged is the hook event that fires when a shell command in the main chat moves to a new folder. A cd is the usual cause. It has no matcher and fires every time. It can write to CLAUDE_ENV_FILE, so it is the place to load a folder's own settings. Those values last until the next change of folder.

Example code

bash
#!/bin/bash
# load the new folder's direnv settings
direnv export bash >> "$CLAUDE_ENV_FILE"
Later commands see this folder's variables.

Common mistake

Expecting the values to stay after the next cd. Claude Code clears them each time the folder changes.

Key takeaways

  1. 1
    When the folder changes. After cd.
  2. 2
    No matcher. Every time.
  3. 3
    Can set variables. Until next move.