[BUG] UserPromptSubmit hook fires when Task/subagent completes instead of only on user prompt submission
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 hooks fire when a Task tool (subagent) completes, not just when the user submits a prompt. The hook output is displayed alongside the agent completion message in the UI.
Example output showing the bug:
Agent "Explore getAllObjectIds implementation" completed.
⎿ UserPromptSubmit hook succeeded: REMINDER: Use run_in_background: true for Task and Bash tool calls when the operation may take time and does not need immediate output.
The UserPromptSubmit hook should only fire when I (the user) submit a prompt, not when an internal subagent finishes.
What Should Happen?
UserPromptSubmit should fire only when the user submits a prompt, per the documentation:
"Fires when you submit a prompt, before Claude processes it"
Agent/Task completion should not trigger this hook. SubagentStop exists for that purpose.
Error Messages/Logs
No errors - the hook executes successfully, but at the wrong time.
Steps to Reproduce
- Add a
UserPromptSubmithook to~/.claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "echo 'This should only appear on user prompt submission'"
}
]
}
]
}
}
- Start Claude Code
- Ask Claude to perform a task that spawns a subagent (e.g., "Search the codebase for X" which triggers an Explore agent)
- Observe the output when the subagent completes
- Bug: The
UserPromptSubmithook output appears after the agent completion message
Claude Model
Opus 4.5
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.1
Platform
Claude Max subscription
Operating System
macOS
Terminal/Shell
Ghostty
Additional Information
Possibly related issues:
- #14859 - Agent hierarchy problems where hooks share session context incorrectly
- #7881 - SubagentStop cannot identify which subagent finished (shared session_id problem)
This may be related to the underlying architecture where all agents share the same session context, causing hook events to fire incorrectly or be attributed to the wrong event source.
This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗