fix: generate valid Claude Code hook schema (closes #138)#141
fix: generate valid Claude Code hook schema (closes #138)#141sebastianbreguel wants to merge 1 commit intotirth8205:mainfrom
Conversation
|
@tirth8205 hey! could you review this one too? it fixes the hook schema generation (issue #138) |
tirth8205
left a comment
There was a problem hiding this comment.
This is a critical correctness fix — the hook schema rewrite looks solid. 4 regression tests, clean approach.
Please rebase on latest main (PR #152 just merged and touches the same skills.py file). Once rebased and CI passes, this is good to merge.
The hooks config emitted by `generate_hooks_config()` did not match the
Claude Code schema, so `code-review-graph install` was writing an
invalid ~/.claude/settings.json. Three problems:
1. `PreCommit` is not a valid hook event — removed.
2. Every event entry needs an inner `hooks: [{type: "command", ...}]`
array; the old output put `command`/`timeout` directly on the entry,
which Claude Code rejects with "hooks: Expected array, but received
undefined".
3. Timeouts were in milliseconds (5000, 3000, 10000), but the schema
uses seconds — the PostToolUse hook effectively had an 83-minute
timeout. Converted to 5 and 3 seconds.
Verified against the official schema at
https://docs.claude.com/en/docs/claude-code/hooks.
Tests updated to assert the new nested structure and guard against
regressions (PreCommit not emitted, all handlers wrapped in inner
hooks array with type=command).
573b855 to
27c0cc3
Compare
|
@tirth8205 Rebased on latest main, conflicts resolved, CI is green. Ready to merge when you are! |
|
@tirth8205 up |
|
Closing in favor of #208 which was just merged. Your PR is very solid — it correctly fixes all three schema bugs (nested hooks array, removes PreCommit, converts timeouts to seconds), has excellent regression tests ( The reason #208 was chosen over this PR is one feature: #208 restores the pre-commit behavior that was lost when removing the invalid One minor note: this PR keeps Thank you for the thorough fix and detailed write-up — it was the clearest description of the three bugs. |
Closes #138
Problem
generate_hooks_config()emits a hooks config that Claude Code rejects with schema errors, socode-review-graph installcorrupts~/.claude/settings.json. Three bugs in the same function:PreCommitis not a valid Claude Code hook event →Invalid key in record.hooksarray wrapper. Each entry must havehooks: [{type: "command", command, timeout}], but the old output putcommand/timeoutdirectly on the entry →hooks: Expected array, but received undefined(the exact error in the issue forSessionStart).5000,3000,10000— thePostToolUsehook effectively had an 83-minute timeout.Verified against the official schema: https://docs.claude.com/en/docs/claude-code/hooks
Fix
Rewrite
generate_hooks_config()to match the documented schema:PreCommitentry (no equivalent Claude Code event; pre-commit behavior belongs in a git hook).PostToolUseandSessionStarthandlers inhooks: [{type: "command", ...}].5000→5,3000→3).Testing
test_has_post_tool_use/test_has_session_startupdated for the nested structuretest_does_not_emit_precommit— regression guard for this issuetest_all_commands_wrapped_in_inner_hooks_array— structural invariantruff checkclean