Class: ClaudeHooks::Output::PostToolUse
- Inherits:
-
Base
- Object
- Base
- ClaudeHooks::Output::PostToolUse
show all
- Defined in:
- lib/claude_hooks/output/post_tool_use.rb
Instance Attribute Summary
Attributes inherited from Base
#data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#continue?, for_hook_type, #hook_specific_output, #initialize, #output_and_exit, #stop_reason, #suppress_output?, #system_message, #terminal_sequence, #to_json
Class Method Details
.merge(*outputs) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 59
def self.merge(*outputs)
compacted_outputs = outputs.compact
return compacted_outputs.first if compacted_outputs.length == 1
return super(*outputs) if compacted_outputs.empty?
merged = super(*outputs)
merged_data = merged.data
contexts = []
compacted_outputs.each do |output|
output_data = output.respond_to?(:data) ? output.data : output
merged_data['decision'] = 'block' if output_data['decision'] == 'block'
merged_data['reason'] = [merged_data['reason'], output_data['reason']].compact.reject(&:empty?).join('; ')
context = output_data.dig('hookSpecificOutput', 'additionalContext')
contexts << context if context && !context.empty?
end
unless contexts.empty?
merged_data['hookSpecificOutput'] = {
'hookEventName' => 'PostToolUse',
'additionalContext' => contexts.join("\n\n")
}
end
new(merged_data)
end
|
Instance Method Details
#additional_context ⇒ Object
18
19
20
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 18
def additional_context
hook_specific_output['additionalContext'] || ''
end
|
#blocked? ⇒ Boolean
32
33
34
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 32
def blocked?
decision == 'block'
end
|
#decision ⇒ Object
10
11
12
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 10
def decision
@data['decision']
end
|
#exit_code ⇒ Object
EXIT CODE LOGIC ===
PostToolUse hooks use the advanced JSON API with exit code 0.
Per Anthropic guidance: when using structured JSON with decision/reason fields,
always output to stdout with exit 0 (not stderr with exit 2).
Reference: https://github.com/anthropics/claude-code/issues/10875
46
47
48
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 46
def exit_code
0
end
|
#output_stream ⇒ Object
OUTPUT STREAM LOGIC ===
PostToolUse hooks always output to stdout when using the JSON API.
53
54
55
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 53
def output_stream
:stdout
end
|
#output_updated? ⇒ Boolean
36
37
38
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 36
def output_updated?
!updated_tool_output.nil? || !updated_mcp_tool_output.nil?
end
|
#reason ⇒ Object
14
15
16
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 14
def reason
@data['reason'] || ''
end
|
26
27
28
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 26
def updated_mcp_tool_output
hook_specific_output['updatedMCPToolOutput']
end
|
22
23
24
|
# File 'lib/claude_hooks/output/post_tool_use.rb', line 22
def updated_tool_output
hook_specific_output['updatedToolOutput']
end
|