Common API Methods

July 14, 2026 ยท View on GitHub

Those methods are available in all hook types and are inherited from ClaudeHooks::Base:

Input Helpers

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

MethodDescription
input_dataInput data reader
session_idGet the current session ID
transcript_pathGet path to the transcript file
cwdGet current working directory
hook_event_nameGet the hook event name
permission_modeGet the permission mode: 'default', 'plan', 'acceptEdits', 'auto', 'dontAsk', 'bypassPermissions' (defaults to 'default')
prompt_idGet the current prompt ID
agent_idGet the agent ID (present in subagent contexts)
agent_typeGet the agent type (present in subagent contexts)
effortGet the effort level string (reads effort.level)
read_transcriptRead the transcript file
transcriptAlias for read_transcript

Hook State Helpers

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

MethodDescription
allow_continue!Allow Claude to continue (default)
prevent_continue!(reason)Stop Claude with reason
suppress_output!Hide stdout from transcript
show_output!Show stdout in transcript (default)
clear_specifics!Clear hook-specific output
system_message!(message)Set a system message shown to the user (not to Claude)
clear_system_message!Clear the system message
terminal_sequence!(seq)Emit an ANSI/terminal escape sequence in the output

Output Helpers

From a hook, you can always access the output object via hook.output. This object provides helpers to access output data, for merging multiple outputs as well as sending the right exit codes and data back to Claude Code.

Output data access

MethodDescription
outputOutput object accessor
output_dataRAW output data accessor
output.continue?Check if Claude should continue processing
output.stop_reasonGet the stop reason if continue is false
output.suppress_output?Check if output should be suppressed from transcript
output.hook_specific_outputGet the hook-specific output data
output.system_messageGet the system message if any
output.terminal_sequenceGet the terminal escape sequence (if set)

Output data merging

For each hook type, the output object provides a class method merge that will try to intelligently merge multiple hook results, e.g. ClaudeHooks::Output::UserPromptSubmit.merge(output1, output2, output3).

MethodDescription
merge(*outputs)Intelligently merge multiple outputs of the same type into a single output

Exit Control and Yielding back to Claude Code

MethodDescription
output.output_and_exitAutomatically output to correct stream and exit with proper code
output.exit_codeGet the calculated exit code based on hook state
output.output_streamGet the proper output stream (:stdout or :stderr) depending on hook state
output.to_jsonGenerates a JSON string of the output

Configuration and Utility Methods

Utility Methods

MethodDescription
log(message, level: :info)Log to session-specific file (levels: :info, :warn, :error)

Configuration Methods

MethodDescription
home_claude_dirGet the home Claude directory ($HOME/.claude)
project_claude_dirGet the project Claude directory ($CLAUDE_PROJECT_DIR/.claude, or nil)
home_path_for(relative_path)Get absolute path relative to home Claude directory
project_path_for(relative_path)Get absolute path relative to project Claude directory (or nil)
base_dirGet the base Claude directory (deprecated)
path_for(relative_path, base_dir=nil)Get absolute path relative to specified or default base dir (deprecated)
configAccess the merged configuration object
config.get_config_value(env_key, config_file_key, default)Get any config value with fallback
config.logs_directoryGet logs directory path (always under home directory)
config.your_custom_keyAccess any custom config via method_missing