fix: valid Claude Code hook schema + merge existing hooks on install#203
fix: valid Claude Code hook schema + merge existing hooks on install#203lngyeen wants to merge 1 commit intotirth8205:mainfrom
Conversation
|
This PR addresses the hooks schema bug (#97, #114, #172, #188, #191, #201) which is still not fixed in main. The current skills.py:generate_hooks_config() still generates the invalid schema. This PR provides exactly what's needed: proper nested hooks arrays, removal of PreCommit/SessionStart (invalid events), narrowed PostToolUse matcher, and merge-based installation with backup. Worth reviving — this is the #1 most-reported bug in the issue tracker. |
Two fixes for Claude Code hooks integration: 1. Hook schema: use proper Claude Code format with nested hooks array and remove unsupported PreCommit event. Narrow PostToolUse matcher from Edit|Write|Bash to Edit|Write since Bash commands do not directly modify source files. (cherry-picked from PR tirth8205#180) 2. Merge logic: install_hooks now merges new entries into existing hooks instead of overwriting them. Creates a backup of settings.json before modification. (based on PR tirth8205#145) Closes tirth8205#97, tirth8205#114, tirth8205#172.
13ddcba to
cf756f4
Compare
|
Rebased onto latest |
Summary
hooks: [{type, command}]arrays instead of flatcommand:fields. Remove unsupportedPreCommitevent. Narrow PostToolUse matcher fromEdit|Write|BashtoEdit|Writesince Bash commands don't directly modify source files.install_hooks()now merges new entries into existing hooks instead of overwriting them viaexisting.update(). Creates asettings.json.bakbackup before modification.Motivation
code-review-graph installgenerates invalidsettings.jsonthat causes Claude Code to fail on startup with:Additionally, the
existing.update(hooks_config)call replaces the entirehookskey, silently destroying user-defined hooks (e.g., linters, formatters, safety checks).Closes #97, #114, #172
Changes
skills.py:generate_hooks_config()skills.py:install_hooks()tests/test_skills.pyTest plan