-
Notifications
You must be signed in to change notification settings - Fork 3
Description
Problem
In internal/hooks/hooks.go at lines 136-138, if the hooks key exists in .claude/settings.json but contains malformed JSON, the parse error is silently swallowed and existingHooks is reset to an empty map:
if hooksRaw, ok := rawJSON["hooks"]; ok {
if err := json.Unmarshal(hooksRaw, &existingHooks); err != nil {
existingHooks = make(map[string][]Hook) // silent data loss
}
}
mergeHooks then merges Uncompact hooks into the empty map and writes the result back, permanently overwriting any hooks the user had installed with no warning, log, or error returned.
Impact
Any user whose .claude/settings.json hooks section is malformed (e.g. written by a different tool, manually edited, or partially written during a previous crash) will silently lose all existing hooks the next time uncompact hooks install runs.
Suggested fix
Return an error when the existing hooks cannot be parsed rather than resetting to an empty map:
if err := json.Unmarshal(hooksRaw, &existingHooks); err != nil {
return nil, fmt.Errorf("existing hooks section is not valid JSON: %w", err)
}
File: internal/hooks/hooks.go:136-138
@claude please implement this