UserPromptSubmit hook does not fire after /compact command

Resolved 💬 3 comments Opened Feb 18, 2026 by abecutter Closed Feb 22, 2026

Description

The UserPromptSubmit hook does not fire on the first user prompt after compaction completes. This breaks workflows that depend on restoring context after compaction.

Steps to Reproduce

  1. Configure a UserPromptSubmit hook that creates a file:
"UserPromptSubmit": [
  {
    "matcher": "*",
    "hooks": [
      {
        "type": "command",
        "command": "powershell -Command \"New-Item -Path .claude/userprompt-fired -ItemType File -Force\"",
        "timeout": 5
      }
    ]
  }
]
  1. Start a session and use context until compaction triggers (or run /compact)
  2. Send a prompt after compaction completes
  3. Check if the marker file was created

Expected Behavior

UserPromptSubmit hook fires on every user prompt, including the first prompt after compaction.

Actual Behavior

The hook does not fire on the first prompt after compaction. Subsequent prompts may or may not trigger it (inconsistent).

Environment

  • Claude Code version: latest (as of 2026-02-18)
  • Platform: Windows 11
  • Shell: PowerShell + Git Bash

Use Case

We use PreCompact to write a marker file (.claude/compaction-pending) and UserPromptSubmit to detect the marker and restore context. Since UserPromptSubmit doesn't fire, the context restoration doesn't happen automatically.

Workaround

Using PreToolUse with runOnce: true as a backup trigger. This works because the agent will use a tool in its first response, but it's a workaround rather than a fix.

Related

  • Feature request for PostCompact hook: #14258, #17237

View original on GitHub ↗

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