Skip to content

fix: emit valid Claude Code hook schema in settings.json#180

Open
pashak1207 wants to merge 1 commit intotirth8205:mainfrom
pashak1207:fix/claude-code-hook-schema
Open

fix: emit valid Claude Code hook schema in settings.json#180
pashak1207 wants to merge 1 commit intotirth8205:mainfrom
pashak1207:fix/claude-code-hook-schema

Conversation

@pashak1207
Copy link
Copy Markdown

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 #97, #163, #172.

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

ZzAve commented Apr 9, 2026

FWIW: I applied these fixed to my local setup and can confirm code-review-graph to be working with claude.

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