[BUG] UserPromptSubmit hooks not working when Claude Code is started from subdirectories
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Summary
UserPromptSubmit hooks defined in ~/.claude/settings.json are not executed when Claude Code is started from
subdirectories, while PreToolUse hooks work correctly in all directories.
Environment
- Claude Code version: [2.0.5]
- OS: Linux (WSL2)
- Settings location: ~/.claude/settings.json
Steps to Reproduce
- Configure UserPromptSubmit hooks in ~/.claude/settings.json:{
"hooks": {
"UserPromptSubmit": [
{
"type": "command",
"command": "~/.claude/hooks/critical/enforce_japanese.sh"
}
]
}
}
- Start Claude Code from home directory → UserPromptSubmit hooks work ✅
- Start Claude Code from any subdirectory → UserPromptSubmit hooks don't work ❌
Expected Behavior
According to https://docs.claude.com/en/docs/claude-code/settings:
"User settings are defined in ~/.claude/settings.json and apply to all projects."
UserPromptSubmit hooks should work regardless of the working directory.
Actual Behavior
- UserPromptSubmit hooks: Only work when started from home directory
- PreToolUse hooks: Work correctly from all directories
Additional Context
The hook scripts themselves execute correctly when tested manually:
echo '{"prompt":"test"}' | ~/.claude/hooks/critical/enforce_japanese.sh
Returns expected output
This suggests the issue is in how Claude Code loads/executes UserPromptSubmit hooks based on the working
directory.
What Should Happen?
UserPromptSubmit hooks defined in ~/.claude/settings.json should execute regardless of which directory Claude Code is started from, since the documentation states that "User settings are defined in ~/.claude/settings.json and
apply to all projects."
The hook should:
- Execute when the user submits a prompt
- Process the prompt content
- Return additionalContext that gets injected into the system prompt
- Work consistently across all working directories
Error Messages/Logs
Steps to Reproduce
- Create a UserPromptSubmit hook script at ~/.claude/hooks/test_hook.sh:
#!/bin/bash
cat << 'EOF'
{
"additionalContext": "Hook is working!"
}
EOF
- Make it executable: chmod +x ~/.claude/hooks/test_hook.sh
- Add the hook to ~/.claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"type": "command",
"command": "~/.claude/hooks/test_hook.sh"
}
]
}
}
- Start Claude Code from home directory and send a prompt → Hook executes ✅
- Start Claude Code from any subdirectory and send a prompt → Hook does not execute ❌
Claude Model
Sonnet (default)
Is this a regression?
No, this never worked
Last Working Version
_No response_
Claude Code Version
2.0.5
Platform
Anthropic API
Operating System
Windows
Terminal/Shell
PowerShell
Additional Information
_No response_
This issue has 7 comments on GitHub. Read the full discussion on GitHub ↗