Skip to content
BENIBIX Learn

UserPromptSubmit Hook

AI⌨️ Claude CodeConfiguration

Also known as UserPromptSubmit

The event when you send a prompt, before Claude reads it.

Think of it like

It is like a clerk who reads your form. Then it goes to the office.

Example

Jack's hook adds the current git branch to each prompt, so Claude always knows which branch it is on.

Why it matters

It is the one place to add facts to every prompt without typing them.

Definition

UserPromptSubmit is the hook event that fires when you send a prompt, before Claude reads it. A hook here can add context, such as today's tickets, or block the prompt. Plain text the hook prints is added for Claude to see. It also fires on turns Claude Code starts on its own, such as a /loop run.

Example code

bash
#!/bin/bash
# add the current git branch to every prompt
echo "Current branch: $(git branch --show-current)"
Plain text printed here reaches Claude.
It opens each turn.

Common mistake

Printing debug lines to stdout. They all reach Claude as context. Send them to stderr.

Key takeaways

  1. 1
    Before Claude reads. Each prompt.
  2. 2
    Add or block. Context or stop.
  3. 3
    Stdout reaches Claude. Plain text.