Class: ClaudeHooks::Stop
Overview
Stop hook for preventing Claude Code from stopping execution.
When using continue_with_instructions!, this hook outputs JSON to stdout with exit code 0 (advanced JSON API approach).
References:
Direct Known Subclasses
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#config, #input_data, #logger, #output, #output_data
Class Method Summary collapse
Instance Method Summary collapse
- #add_additional_context!(context) ⇒ Object
- #background_tasks ⇒ Object
-
#continue_with_instructions!(instructions) ⇒ Object
(also: #block!)
Block Claude from stopping (force it to continue).
-
#ensure_stopping! ⇒ Object
Ensure Claude stops normally (default behavior).
- #last_assistant_message ⇒ Object
- #session_crons ⇒ Object
-
#stop_hook_active ⇒ Object
INPUT DATA ACCESS ===.
Methods inherited from Base
#agent_id, #agent_type, #allow_continue!, #base_dir, #call, #clear_specifics!, #clear_system_message!, #cwd, #effort, #home_claude_dir, #home_path_for, #hook_event_name, #hook_type, #initialize, #log, #output_and_exit, #path_for, #permission_mode, #prevent_continue!, #project_claude_dir, #project_path_for, #prompt_id, #read_transcript, #session_id, #show_output!, #stringify_output, #suppress_output!, #system_message!, #terminal_sequence, #terminal_sequence!, #transcript_path
Constructor Details
This class inherits a constructor from ClaudeHooks::Base
Class Method Details
.hook_type ⇒ Object
15 16 17 |
# File 'lib/claude_hooks/stop.rb', line 15 def self.hook_type 'Stop' end |
.input_fields ⇒ Object
19 20 21 |
# File 'lib/claude_hooks/stop.rb', line 19 def self.input_fields %w[stop_hook_active] end |
Instance Method Details
#add_additional_context!(context) ⇒ Object
56 57 58 59 |
# File 'lib/claude_hooks/stop.rb', line 56 def add_additional_context!(context) @output_data['hookSpecificOutput'] ||= { 'hookEventName' => hook_event_name } @output_data['hookSpecificOutput']['additionalContext'] = context end |
#background_tasks ⇒ Object
33 34 35 |
# File 'lib/claude_hooks/stop.rb', line 33 def background_tasks @input_data['background_tasks'] || @input_data['backgroundTasks'] || [] end |
#continue_with_instructions!(instructions) ⇒ Object Also known as: block!
Block Claude from stopping (force it to continue)
44 45 46 47 |
# File 'lib/claude_hooks/stop.rb', line 44 def continue_with_instructions!(instructions) @output_data['decision'] = 'block' @output_data['reason'] = instructions end |
#ensure_stopping! ⇒ Object
Ensure Claude stops normally (default behavior)
51 52 53 54 |
# File 'lib/claude_hooks/stop.rb', line 51 def ensure_stopping! @output_data.delete('decision') @output_data.delete('reason') end |
#last_assistant_message ⇒ Object
29 30 31 |
# File 'lib/claude_hooks/stop.rb', line 29 def @input_data['last_assistant_message'] || @input_data['lastAssistantMessage'] end |
#session_crons ⇒ Object
37 38 39 |
# File 'lib/claude_hooks/stop.rb', line 37 def session_crons @input_data['session_crons'] || @input_data['sessionCrons'] || [] end |
#stop_hook_active ⇒ Object
INPUT DATA ACCESS ===
25 26 27 |
# File 'lib/claude_hooks/stop.rb', line 25 def stop_hook_active @input_data['stop_hook_active'] end |