Skip to content

fix: valid Claude Code hook schema + merge existing hooks on install#203

Open
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:fix/hooks-schema-and-merge
Open

fix: valid Claude Code hook schema + merge existing hooks on install#203
lngyeen wants to merge 1 commit intotirth8205:mainfrom
lngyeen:fix/hooks-schema-and-merge

Conversation

@lngyeen
Copy link
Copy Markdown

@lngyeen lngyeen commented Apr 10, 2026

Summary

  • Hook schema fix: Use proper Claude Code format with nested hooks: [{type, command}] arrays instead of flat command: fields. Remove unsupported PreCommit event. Narrow PostToolUse matcher from Edit|Write|Bash to Edit|Write since Bash commands don't directly modify source files.
  • Merge logic: install_hooks() now merges new entries into existing hooks instead of overwriting them via existing.update(). Creates a settings.json.bak backup before modification.

Motivation

code-review-graph install generates invalid settings.json that causes Claude Code to fail on startup with:

hooks.PostToolUse.0.hooks: Expected array, but received undefined
hooks.SessionStart.0.hooks: Expected array, but received undefined

Additionally, the existing.update(hooks_config) call replaces the entire hooks key, silently destroying user-defined hooks (e.g., linters, formatters, safety checks).

Closes #97, #114, #172

Changes

File Change
skills.py:generate_hooks_config() Proper Claude Code schema, removed Bash matcher and PreCommit
skills.py:install_hooks() Merge-based hook installation with backup
tests/test_skills.py Updated tests for schema validation and merge behavior

Test plan

  • All 29 skills tests pass
  • All 621 tests pass with zero regressions
  • Verified generated hooks load correctly in Claude Code v2.1.92

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.
@tirth8205
Copy link
Copy Markdown
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plugin hooks fail to load - Hooks use a matcher + hooks array.

2 participants