Skip to content

[BUG] UserPromptSubmit hook fires when Task/subagent completes instead of only on user prompt submission #16952

@TyceHerrman

Description

@TyceHerrman

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • 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

  1. Add a UserPromptSubmit hook to ~/.claude/settings.json:
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "echo 'This should only appear on user prompt submission'"
          }
        ]
      }
    ]
  }
}
  1. Start Claude Code
  2. Ask Claude to perform a task that spawns a subagent (e.g., "Search the codebase for X" which triggers an Explore agent)
  3. Observe the output when the subagent completes
  4. Bug: The UserPromptSubmit hook 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:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:toolsbugSomething isn't workinghas reproHas detailed reproduction stepsplatform:macosIssue specifically occurs on macOSstaleIssue is inactive

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions