Skip to content
BENIBIX Learn

FileChanged Hook

AI⌨️ Claude CodeConfiguration

Also known as FileChanged

The event when a watched file changes, no matter what changed it.

Think of it like

It is like a dog that barks when a door opens. It does not care who opened it.

Example

Jack edits .env in his own editor while Claude works. His FileChanged hook reloads it, so Claude's next command sees the new value.

Why it matters

A hook that matches Edit or Write misses changes made by a script. This one sees them all.

Definition

FileChanged is the hook event that fires when a watched file changes on disk. It does not care what changed it: an edit by Claude, a script, or another program. The matcher lists the file names to watch, split by |, such as .envrc|.env. These are plain names in the working folder, not patterns. It runs after the change and cannot block it.

Example code

json
{
  "hooks": {
    "FileChanged": [
      { "matcher": ".envrc|.env", "hooks": [{ "type": "command", "command": "direnv export bash >> \"$CLAUDE_ENV_FILE\"" }] }
    ]
  }
}
Reload variables when either file changes.
Three writers, one watch list, one hook.

Common mistake

Writing a pattern like ^\.env as the matcher. It watches a file with that exact odd name.

Key takeaways

  1. 1
    Watched files. Any writer.
  2. 2
    Plain names. Not patterns.
  3. 3
    After the change. Cannot block.

Compare