mirror of
https://github.com/imjasonh/cnotes
synced 2026-07-20 13:08:53 +00:00
Only register PostToolUse hook during installation
Since cnotes only handles PostToolUse events (and ignores all others), update the installation to only register for that specific event rather than all available hook events. This reduces unnecessary hook calls. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
caa1834d58
commit
01ba9278ba
3 changed files with 29 additions and 105 deletions
|
|
@ -106,40 +106,30 @@ func InstallHooksToPath(binaryPath, settingsPath string) error {
|
|||
Hooks: []HookAction{hookAction},
|
||||
}
|
||||
|
||||
// Map our event names to Claude's event names
|
||||
eventMap := map[string]string{
|
||||
"pre_tool_use": "PreToolUse",
|
||||
"post_tool_use": "PostToolUse",
|
||||
"user_prompt_submit": "UserPromptSubmit",
|
||||
"stop": "Stop",
|
||||
"subagent_stop": "SubagentStop",
|
||||
"notification": "Notification",
|
||||
"pre_compact": "PreCompact",
|
||||
}
|
||||
// Only register for PostToolUse events since that's all we handle
|
||||
claudeEvent := "PostToolUse"
|
||||
|
||||
for _, claudeEvent := range eventMap {
|
||||
// Check if our hook is already installed
|
||||
found := false
|
||||
for i, def := range settings.Hooks[claudeEvent] {
|
||||
for j, action := range def.Hooks {
|
||||
if action.Command == binaryPath {
|
||||
// Update existing hook
|
||||
settings.Hooks[claudeEvent][i].Hooks[j] = hookAction
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if found {
|
||||
// Check if our hook is already installed
|
||||
found := false
|
||||
for i, def := range settings.Hooks[claudeEvent] {
|
||||
for j, action := range def.Hooks {
|
||||
if action.Command == binaryPath {
|
||||
// Update existing hook
|
||||
settings.Hooks[claudeEvent][i].Hooks[j] = hookAction
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
// Add new hook
|
||||
settings.Hooks[claudeEvent] = append(settings.Hooks[claudeEvent], hookDef)
|
||||
if found {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !found {
|
||||
// Add new hook
|
||||
settings.Hooks[claudeEvent] = append(settings.Hooks[claudeEvent], hookDef)
|
||||
}
|
||||
|
||||
return SaveSettings(settingsPath, settings)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue