UserPromptSubmit API

August 29, 2025 ยท View on GitHub

Available when inheriting from ClaudeHooks::UserPromptSubmit:

Input Helpers

Input helpers to access the data provided by Claude Code through STDIN.

๐Ÿ“š Shared input helpers

MethodDescription
promptGet the user's prompt text
user_promptAlias for prompt
current_promptAlias for prompt

Hook State Helpers

Hook state methods are helpers to modify the hook's internal state (output_data) before yielding back to Claude Code.

๐Ÿ“š Shared hook state methods

MethodDescription
add_additional_context!(context)Add context to the prompt
add_context!(context)Alias for add_additional_context!
empty_additional_context!Remove additional context
block_prompt!(reason)Block the prompt from processing
unblock_prompt!Unblock a previously blocked prompt

Output Helpers

Output helpers provide access to the hook's output data and helper methods for working with the output state.

๐Ÿ“š Shared output helpers

MethodDescription
output.decisionGet the decision: "block" or nil (default)
output.reasonGet the reason for the decision
output.blocked?Check if the prompt has been blocked (decision == 'block')
output.additional_contextGet the additional context that was added

Hook Exit Codes

Exit CodeBehavior
exit 0Operation continues
STDOUT added as context to Claude
exit 1Non-blocking error
STDERR shown to user
exit 2Blocks prompt processing
Erases prompt
STDERR shown to user only