@@ -36,8 +36,6 @@ def ensure_claude_hook() -> bool:
36
36
CLAUDE_CONFIG_DIR .mkdir (exist_ok = True )
37
37
38
38
# Build the shell command that will create session via API and write session data
39
- start_hook_script_path = Path (__file__ ).parent / "config" / "claude_session_hook.py"
40
- start_hook_command = f"python3 { start_hook_script_path } > { SESSION_FILE } "
41
39
42
40
# Build the stop hook command to mark session COMPLETE
43
41
stop_hook_script_path = Path (__file__ ).parent / "config" / "claude_session_stop_hook.py"
@@ -63,28 +61,23 @@ def ensure_claude_hook() -> bool:
63
61
# Ensure proper structure exists
64
62
if "hooks" not in hooks_config :
65
63
hooks_config ["hooks" ] = {}
66
- if "SessionStart" not in hooks_config ["hooks" ]:
67
- hooks_config ["hooks" ]["SessionStart" ] = []
68
64
if "Stop" not in hooks_config ["hooks" ]:
69
65
hooks_config ["hooks" ]["Stop" ] = []
70
66
if "UserPromptSubmit" not in hooks_config ["hooks" ]:
71
67
hooks_config ["hooks" ]["UserPromptSubmit" ] = []
72
68
73
69
# Get existing hooks
74
- session_start_hooks = hooks_config ["hooks" ]["SessionStart" ]
75
70
stop_hooks = hooks_config ["hooks" ]["Stop" ]
76
71
active_hooks = hooks_config ["hooks" ]["UserPromptSubmit" ]
77
72
78
73
# Check if we're replacing existing hooks
79
- replaced_existing = (len (session_start_hooks ) > 0 ) or ( len ( stop_hooks ) > 0 ) or (len (active_hooks ) > 0 )
74
+ replaced_existing = (len (stop_hooks ) > 0 ) or (len (active_hooks ) > 0 )
80
75
81
76
# Create the new hook structures (following Claude's format)
82
- new_start_hook_group = {"hooks" : [{"type" : "command" , "command" : start_hook_command }]}
83
77
new_stop_hook_group = {"hooks" : [{"type" : "command" , "command" : stop_hook_command }]}
84
78
new_active_hook_group = {"hooks" : [{"type" : "command" , "command" : active_hook_command }]}
85
79
86
80
# Replace all existing hooks with our single hook per event
87
- hooks_config ["hooks" ]["SessionStart" ] = [new_start_hook_group ]
88
81
hooks_config ["hooks" ]["Stop" ] = [new_stop_hook_group ]
89
82
hooks_config ["hooks" ]["UserPromptSubmit" ] = [new_active_hook_group ]
90
83
@@ -97,7 +90,6 @@ def ensure_claude_hook() -> bool:
97
90
console .print ("✅ Replaced existing Claude hooks (SessionStart, Stop)" , style = "green" )
98
91
else :
99
92
console .print ("✅ Registered new Claude hooks (SessionStart, Stop)" , style = "green" )
100
- console .print (f" Start hook: { start_hook_command } " , style = "dim" )
101
93
console .print (f" Stop hook: { stop_hook_command } " , style = "dim" )
102
94
console .print (f" Active hook:{ ' ' if len ('Active hook:' ) < 1 else '' } { active_hook_command } " , style = "dim" )
103
95
@@ -106,13 +98,6 @@ def ensure_claude_hook() -> bool:
106
98
with open (HOOKS_CONFIG_FILE ) as f :
107
99
verify_config = json .load (f )
108
100
109
- # Check that our hooks are in the config
110
- found_start_hook = False
111
- for hook_group in verify_config .get ("hooks" , {}).get ("SessionStart" , []):
112
- for hook in hook_group .get ("hooks" , []):
113
- if SESSION_FILE .name in hook .get ("command" , "" ):
114
- found_start_hook = True
115
- break
116
101
found_stop_hook = False
117
102
for hook_group in verify_config .get ("hooks" , {}).get ("Stop" , []):
118
103
for hook in hook_group .get ("hooks" , []):
@@ -126,7 +111,7 @@ def ensure_claude_hook() -> bool:
126
111
found_active_hook = True
127
112
break
128
113
129
- if found_start_hook and found_stop_hook and found_active_hook :
114
+ if found_stop_hook and found_active_hook :
130
115
console .print ("✅ Hook configuration verified" , style = "dim" )
131
116
else :
132
117
console .print ("⚠️ Hook was written but verification failed" , style = "yellow" )
0 commit comments