UserPromptExpansion API

July 14, 2026 ยท View on GitHub

Available when inheriting from ClaudeHooks::UserPromptExpansion:

Runs when a slash command or other prompt-expansion mechanism is triggered. Can block the expansion.

Input Helpers

๐Ÿ“š Shared input helpers

MethodDescription
expansion_typeType of expansion (e.g. 'slash_command')
command_nameThe command name (without the /)
command_argsThe arguments passed to the command
command_sourceWhere the command was defined ('user', 'project', etc.)
promptThe expanded prompt text

Hook State Helpers

๐Ÿ“š Shared hook state methods

MethodDescription
block!(reason)Block the expansion with a reason
add_additional_context!(context)Add additional context visible to Claude

Output Helpers

๐Ÿ“š Shared output helpers

MethodDescription
output.blocked?Check if the expansion was blocked
output.decisionGet the decision ('block' or nil)
output.reasonGet the block reason

Hook Exit Codes

Exit CodeBehavior
exit 0Expansion proceeds
exit 2Blocks the expansion; STDERR shown to Claude