[Bug] Environment Variable Not Propagated in Plugin Hooks

Status Fixed / completed
Maintainer reply None cached
Activity 4 comments · opened Oct 12, 2025 · closed Nov 18, 2025

Bug Description
I'm trying to use the $CLAUDE_PROJECT_DIR environment variable in a plugin hook and it doesn't seem to be filled. Consider this hook configuration:

{
  "hooks": {
    "SessionStart": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo \"${CLAUDE_PROJECT_DIR}\" > ~/claude-debug.txt"
          }
        ]
      }
    ]
  }
}

This works as expected when I have this hook as part of my global ~/.claude/settings.json file or the project-specific .claude/settings.local.json file, but when I put it in a plugin's hooks.json file, the CLAUDE_PROJECT_DIR variable is empty so my debug file is also empty.

Changing the variable to CLAUDE_PLUGIN_ROOT does populate the file with a proper path but I do need the project path.

Environment Info

  • Platform: darwin
  • Terminal: iTerm.app
  • Version: 2.0.14
  • Feedback ID: 1a029692-a434-47f4-935a-b2ff351f017a

Errors

[]

View original on GitHub ↗

4 Comments

Hsinin · 1 year ago

why my plugin hooks not work?

hooks/hooks.json
{
"description": "test",
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [
{
"type": "command",
"command": "echo 'hello world'"
}
]
}
]
}
}

elct9620 · 1 year ago

Same here, I create a Node.js script, but the environment variable is undefined.

// ....
const configPath = `${process.env.CLAUDE_PROJECT_DIR}/example.json`;
const content = await await fs.readFile(configPath, "utf-8"); // Error, the project specified config cannot be found

// Debug CLAUDE_PROJECT_DIR
console.log(process.env.CLAUDE_PROJECT_DIR) // undefined
gpambrozio · 11 months ago

As of v2.0.45 this seems to be working.

github-actions[bot] · 10 months ago

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.