fix: emit valid Claude Code hook schema in settings.json#180
fix: emit valid Claude Code hook schema in settings.json#180pashak1207 wants to merge 1 commit intotirth8205:mainfrom
Conversation
Claude Code rejects the file generated by `code-review-graph install`
with "Expected array, but received undefined" because each entry under
PostToolUse/SessionStart needs an inner `hooks: [{type, command}]`
array, not a flat `command:` field. On top of that, the generator
emits a `PreCommit` block — which isn't a Claude Code event at all.
Consequence: the entire settings.json is discarded, so neither the
PostToolUse auto-update hook nor the SessionStart status hook ever
fires.
This rewrites generate_hooks_config() to produce the correct schema,
drops the bogus PreCommit block, and narrows the PostToolUse matcher
from `Edit|Write|Bash` to `Edit|Write`. Bash calls in Claude Code
don't modify source files directly, so running an incremental graph
update after every shell command was just noise.
Tests in TestGenerateHooksConfig were updated to assert the new
schema, plus a new regression test (test_entries_use_claude_code_hook_schema)
guards against the flat-command shape recurring.
Fixes tirth8205#97, tirth8205#163, tirth8205#172.
|
FWIW: I applied these fixed to my local setup and can confirm |
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.
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.
|
Closing in favor of #208 which was just merged and provides a more complete fix. Your PR correctly fixes the two critical bugs: nested However, there is one remaining issue in this PR: the timeouts ( PR #208 also adds a new Thank you for the contribution — identifying the timeout unit bug was a key insight. |
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.
Claude Code rejects the file generated by
code-review-graph installwith "Expected array, but received undefined" because each entry under PostToolUse/SessionStart needs an innerhooks: [{type, command}]array, not a flatcommand:field. On top of that, the generator emits aPreCommitblock — which isn't a Claude Code event at all.Consequence: the entire settings.json is discarded, so neither the PostToolUse auto-update hook nor the SessionStart status hook ever fires.
This rewrites generate_hooks_config() to produce the correct schema, drops the bogus PreCommit block, and narrows the PostToolUse matcher from
Edit|Write|BashtoEdit|Write. Bash calls in Claude Code don't modify source files directly, so running an incremental graph update after every shell command was just noise.Tests in TestGenerateHooksConfig were updated to assert the new schema, plus a new regression test (test_entries_use_claude_code_hook_schema) guards against the flat-command shape recurring.
Fixes #97, #163, #172.