Skip to content

fix: hooks.json schema validation fails with "Expected array, but received undefined"#288

Merged
tirth8205 merged 2 commits intotirth8205:mainfrom
jakeefr:fix/hooks-json-schema
Apr 18, 2026
Merged

fix: hooks.json schema validation fails with "Expected array, but received undefined"#288
tirth8205 merged 2 commits intotirth8205:mainfrom
jakeefr:fix/hooks-json-schema

Conversation

@jakeefr
Copy link
Copy Markdown
Contributor

@jakeefr jakeefr commented Apr 15, 2026

Fixes #283. The hooks.json had two schema violations that caused Claude Code to reject the config at startup:

What changed

  1. Removed {"hooks": {...}} wrapper — Claude Code expects hook events (SessionStart, PostToolUse, etc.) at the top level of hooks.json, not nested inside a "hooks" property. The extra nesting caused Claude Code to find the event keys but then fail to resolve the inner hooks array (hence "Expected array, but received undefined").

  2. Added missing "matcher" field to SessionStart — every hook entry requires a "matcher" (tool name, pipe-separated list, or "" to match all). The SessionStart entry was missing it entirely.

This matches the schema documented at https://docs.anthropic.com/en/docs/claude-code/hooks and the fix pattern from anthropics/claude-code#31278 (identical root cause in the ralph-loop plugin).

Before / After

-{
-  "hooks": {
-    "SessionStart": [
-      {
-        "hooks": [...]
+{
+  "SessionStart": [
+    {
+      "matcher": "",
+      "hooks": [...]

I maintain PRISM, a post-session diagnostics tool for Claude Code — CLAUDE.md adherence analysis and session health scoring. Both tools do deeper analysis beyond surface-level code review.

Two issues caused Claude Code to reject the hooks config:

1. Events were nested inside {"hooks": {...}} wrapper — Claude Code
   expects hook events at the top level of hooks.json
2. SessionStart entry was missing the required "matcher" field

Matches the schema documented at https://docs.anthropic.com/en/docs/claude-code/hooks
and the fix pattern from anthropics/claude-code#31278.

Fixes tirth8205#283

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@tirth8205
Copy link
Copy Markdown
Owner

This PR now conflicts with main after #257 was merged (both touch hooks.json). Could you rebase on main? Thanks!

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tirth8205 tirth8205 merged commit d7e61d8 into tirth8205:main Apr 18, 2026
1 check passed
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.

hooks: Expected array, but received undefined

2 participants