claude-code - 💡(How to fix) Fix UserPromptSubmit hooks don't fire when launched from a subdirectory [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#48179Fetched 2026-04-15 06:30:57
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1

Code Example

{
  "permissions": {
    "allow": ["Bash(myscript:*)"]
  },
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"additionalContext\": \"hook fired\"}'"
          }
        ]
      }
    ]
  }
}
RAW_BUFFERClick to expand / collapse

Bug

UserPromptSubmit hooks defined in .claude/settings.json at the project root don't fire when Claude Code is launched from a subdirectory of the repo. Other settings from the same file (e.g., permissions) load correctly.

Repro

  1. Define a UserPromptSubmit hook in <repo-root>/.claude/settings.json:
{
  "permissions": {
    "allow": ["Bash(myscript:*)"]
  },
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo '{\"additionalContext\": \"hook fired\"}'"
          }
        ]
      }
    ]
  }
}
  1. cd <repo-root>/dir1/dir2/ and run claude
  2. Type any prompt

Expected: Hook fires and injects additionalContext.

Actual: Hook does not fire. Claude processes the prompt normally with no hook involvement. Permissions from the same .claude/settings.json file are loaded and enforced correctly.

Running claude from the repo root with the same settings works as expected — the hook fires on every prompt.

Environment

  • macOS (Darwin 24.6.0)
  • Claude Code CLI

extent analysis

TL;DR

The UserPromptSubmit hook may not be firing due to the current working directory not being the repository root, suggesting a potential issue with how Claude Code resolves the settings file path.

Guidance

  • Verify that the .claude/settings.json file is being loaded correctly when running claude from a subdirectory by checking if other settings, like permissions, are applied as expected.
  • Check the documentation for Claude Code to see if there are any specific instructions for configuring hooks when running from a subdirectory.
  • Consider using an absolute path for the command in the hook definition to ensure it can be found regardless of the current working directory.
  • Test running claude with the --root or similar option (if available) to explicitly set the repository root, which might help in loading the correct settings.

Example

No code example is provided as the issue seems related to configuration and path resolution rather than code syntax.

Notes

The solution might depend on the specifics of how Claude Code handles settings and hooks, particularly when launched from subdirectories. The exact fix could require adjustments based on the version of Claude Code being used or its configuration options.

Recommendation

Apply a workaround by running claude from the repository root or by using a command that changes the directory to the root before running claude, until a more permanent solution is found, as this approach is confirmed to work as expected.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix UserPromptSubmit hooks don't fire when launched from a subdirectory [1 comments, 2 participants]