# CwdChanged Hook

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

**Field:** Artificial Intelligence  
**Category:** Claude Code  
**Also known as:** CwdChanged

## Think of it like

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

## 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

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

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

- **When the folder changes.** After cd.
- **No matcher.** Every time.
- **Can set variables.** Until next move.

## Related terms

- [FileChanged Hook](https://learn.benibix.com/term/ai/filechanged-hook)
- [CLAUDE_ENV_FILE](https://learn.benibix.com/term/ai/claude-env-file-variable)
- [Primary Working Directory](https://learn.benibix.com/term/ai/primary-working-directory)

---

Source: https://learn.benibix.com/term/ai/cwdchanged-hook
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-16
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
