{"record":{"id":"64c9bd5d03798bba","repo":"github/copilot-sdk","slug":"invalid-hook-input-w","errorCode":null,"errorMessage":"invalid hook input: %w","messagePattern":"invalid hook input: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/session.go","lineNumber":764,"sourceCode":"func (s *Session) handleHooksInvoke(hookType string, rawInput json.RawMessage) (any, error) {\n\thooks := s.getHooks()\n\n\tif hooks == nil {\n\t\treturn nil, nil\n\t}\n\n\tinvocation := HookInvocation{\n\t\tSessionID: s.SessionID,\n\t}\n\n\tswitch hookType {\n\tcase \"preToolUse\":\n\t\tif hooks.OnPreToolUse == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\tvar input PreToolUseHookInput\n\t\tif err := json.Unmarshal(rawInput, &input); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid hook input: %w\", err)\n\t\t}\n\t\treturn hooks.OnPreToolUse(input, invocation)\n\n\tcase \"preMcpToolCall\":\n\t\tif hooks.OnPreMCPToolCall == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\tvar input PreMCPToolCallHookInput\n\t\tif err := json.Unmarshal(rawInput, &input); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid hook input: %w\", err)\n\t\t}\n\t\treturn hooks.OnPreMCPToolCall(input, invocation)\n\n\tcase \"postToolUse\":\n\t\tif hooks.OnPostToolUse == nil {\n\t\t\treturn nil, nil\n\t\t}\n\t\tvar input PostToolUseHookInput","sourceCodeStart":746,"sourceCodeEnd":782,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/session.go#L746-L782","documentation":"In handleHooksInvoke, when the CLI delivers a preToolUse hook callback, the raw JSON payload is unmarshalled into PreToolUseHookInput. If the JSON does not match the expected schema, the SDK returns this error wrapping the json.Unmarshal error instead of invoking the registered OnPreToolUse hook.","triggerScenarios":"A preToolUse hooksInvoke request whose req.Input JSON fails to decode into PreToolUseHookInput (wrong/missing fields, wrong types, malformed JSON).","commonSituations":"SDK and CLI versions disagree on the hook payload schema; CLI update adds/renames fields with different types; a custom/older CLI binary sending non-conformant input.","solutions":["Upgrade the Go SDK and the Copilot CLI to matching versions so the PreToolUseHookInput schema lines up.","Log the raw input payload (enable debug logging) and compare it to the PreToolUseHookInput struct fields.","Check that your hooks registration (OnPreToolUse) is configured for the correct hook type string."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := session.handleHooksInvoke(\"preToolUse\", raw)\nif err != nil && strings.HasPrefix(err.Error(), \"invalid hook input:\") {\n    // schema mismatch: log raw payload, check SDK/CLI versions\n}","preventionTips":["Keep SDK and CLI versions matched","Enable debug logging to capture raw hook payloads","Pin CLI versions in deployments and upgrade SDK with them"],"tags":["hooks","json","schema"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}