UserPromptSubmit hook does not fire after /compact command
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
- Configure a
UserPromptSubmithook that creates a file:
"UserPromptSubmit": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "powershell -Command \"New-Item -Path .claude/userprompt-fired -ItemType File -Force\"",
"timeout": 5
}
]
}
]
- Start a session and use context until compaction triggers (or run
/compact) - Send a prompt after compaction completes
- 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
PostCompacthook: #14258, #17237
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗