Class: ClaudeHooks::Output::WorktreeCreate
- Defined in:
- lib/claude_hooks/output/worktree_create.rb
Overview
WorktreeCreate has a special bare-stdout contract: the last non-empty stdout line is interpreted as the worktree path. An empty/missing path causes Claude Code to treat creation as failed.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #exit_code ⇒ Object
-
#output_and_exit ⇒ Object
Overrides the default JSON output — prints the bare path instead.
- #output_stream ⇒ Object
- #worktree_path ⇒ Object
Methods inherited from Base
#continue?, for_hook_type, #hook_specific_output, #initialize, #stop_reason, #suppress_output?, #system_message, #terminal_sequence, #to_json
Constructor Details
This class inherits a constructor from ClaudeHooks::Output::Base
Class Method Details
.merge(*outputs) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/claude_hooks/output/worktree_create.rb', line 34 def self.merge(*outputs) compacted_outputs = outputs.compact return compacted_outputs.first if compacted_outputs.length == 1 return super(*outputs) if compacted_outputs.empty? # Last set path wins merged = super(*outputs) merged_data = merged.data last_path = nil compacted_outputs.each do |output| output_data = output.respond_to?(:data) ? output.data : output p = output_data.dig('hookSpecificOutput', 'worktreePath') || output_data['_worktree_path'] last_path = p if p && !p.empty? end if last_path merged_data['hookSpecificOutput'] ||= { 'hookEventName' => 'WorktreeCreate' } merged_data['hookSpecificOutput']['worktreePath'] = last_path merged_data['_worktree_path'] = last_path end new(merged_data) end |
Instance Method Details
#exit_code ⇒ Object
15 16 17 |
# File 'lib/claude_hooks/output/worktree_create.rb', line 15 def exit_code worktree_path && !worktree_path.empty? ? 0 : 1 end |
#output_and_exit ⇒ Object
Overrides the default JSON output — prints the bare path instead.
24 25 26 27 28 29 30 31 32 |
# File 'lib/claude_hooks/output/worktree_create.rb', line 24 def output_and_exit path = worktree_path if path && !path.empty? $stdout.puts path exit 0 else exit 1 end end |
#output_stream ⇒ Object
19 20 21 |
# File 'lib/claude_hooks/output/worktree_create.rb', line 19 def output_stream :stdout end |
#worktree_path ⇒ Object
11 12 13 |
# File 'lib/claude_hooks/output/worktree_create.rb', line 11 def worktree_path @data['hookSpecificOutput']&.dig('worktreePath') || @data['_worktree_path'] end |