[BUG] UserPromptSubmit hook not triggering consistently

Resolved 💬 5 comments Opened Jan 10, 2026 by internationils Closed Jan 15, 2026

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?

UserPromptSubmit hook fails to fire for prompts submitted early in session or after context compaction

UPDATE - appears to work more consistently with 2.1.3 (was not working with 2.0.76). Will monitor for a day or two then close if it works.
UPDATE-2: - appears NOT to work if a skill is triggered - like me saying "commit and push" (triggering the skill immediately), but "please use the gen pdf skill" did get logged.

Environment

| Component | Version |
|-----------|---------|
| Claude Code CLI | 2.0.76 |
| Claude Code VSCode Extension | anthropic.claude-code-2.1.4-darwin-arm64 |
| VSCode | 1.108.0 |
| OS | macOS (Darwin 25.2.0) (also on Win11 with and without WSL) |
| Architecture | Apple Silicon (arm64) |

Hook Configuration

.claude/settings.local.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "type": "command",
        "command": "./50_process/log_user_prompt.sh"
      }
    ],
    "SessionStart": [
      {
        "type": "command",
        "command": "./50_process/log_user_prompt.sh '[SESSION START]'"
      }
    ]
  }
}


### What Should Happen?

**Description**
The UserPromptSubmit hook does not trigger for user prompts submitted early in a session or immediately after context compaction. The SessionStart hook works reliably, but UserPromptSubmit appears to require some initialization time before it becomes active.

**Expected Behavior**
UserPromptSubmit should fire for every user prompt, including:

- The first prompt after session start
- Prompts submitted immediately after context compaction

**Impact**
Users relying on UserPromptSubmit for logging, automation, or auditing lose data for early-session prompts. This is particularly problematic after context compaction, where important prompts may go unrecorded.

**Workaround**
Manual logging via script invocation, but this requires the AI assistant to remember to do so and defeats the purpose of automatic hooks.

**Hypothesis**
The UserPromptSubmit hook registration may be happening asynchronously after session initialization completes. Early prompts arrive before the hook handler is fully registered. The fact that SessionStart works reliably suggests it's registered synchronously during startup, while UserPromptSubmit may have a race condition.

### Error Messages/Logs

```shell
**Observed Behavior**
Debug log output:


[20260110-084555] === Hook triggered ===
[20260110-084555] Args: [SESSION START]
[20260110-084555] Mode: argument
[20260110-084555] Prompt from arg: [SESSION START]
[20260110-084642] === Hook triggered ===
[20260110-084642] Args: 
[20260110-084642] Mode: stdin
[20260110-084642] Raw stdin: {"session_id":"...","prompt":"If there is stdin and argument..."}


- SessionStart fires at 084555 ✓
- Multiple user prompts submitted between 084555 and 084642 — no hook invocations
- UserPromptSubmit finally fires at 084642 for a later prompt

Steps to Reproduce

Steps to Reproduce

  • Configure both SessionStart and UserPromptSubmit hooks as shown above
  • Add debug logging to the hook script to track when it's triggered
  • Start a new session or trigger context compaction
  • Submit several prompts in quick succession
  • Check debug log to see which hook invocations occurred

Claude Model

Opus

Is this a regression?

No, this never worked

Last Working Version

_No response_

Claude Code Version

2.0.76 and 2.1.3 (better but not completely OK)

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

VS Code integrated terminal

Additional Information

Using vscode with claude code extension on macos. Need to log every prompt as I am currently working on some authoring tasks and need to analyze how content develops later.

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗