[Bug] Agent tool crashes with "undefined is not an object (evaluating 'K.length')" when PreToolUse hook returns partial updatedInput
Bug Description
Correction to my earlier K.length Agent dispatch bug report
The root cause was not the Opus 4.7 (1M context) + max effort model selection or any subscription entitlement issue.
After investigation, the trigger was a PreToolUse hook I had configured in ~/.claude/settings.json:
{
"matcher": "Agent",
"hooks": [{ "type": "command", "command": "~/.claude/hooks/force-agent-opus.sh" }]
}
The hook returns {"hookSpecificOutput":{"hookEventName":"PreToolUse","updatedInput":{"model":"opus"}}} — intending to
force every Agent invocation to use Opus per the documented updatedInput merge behavior. Removing the hook entry from
settings.json immediately restored Agent dispatch.
However, the harness-side issue still warrants a fix:
1. The dispatcher crashes with an uncaught minified runtime exception (undefined is not an object (evaluating
'K.length')) instead of returning an actionable error. Whatever array K references (looks like a subagent type lookup
or capability list) should either be guaranteed non-null at that point, or the read should be guarded.
2. updatedInput merge semantics for the Agent tool may have regressed — the hook is intended to overlay model on top
of the original tool_input (which contains subagent_type, prompt, description). If the harness is now replacing rather
than merging, required fields like subagent_type go missing and downstream code reads undefined. Either the docs
should clarify the replace-vs-merge semantics, or the merge behavior should be restored for the Agent tool.
3. Input validation should run after hook application, so a post-hook input missing subagent_type would fail with a
clear InputValidationError rather than a deep K.length crash.
Repro on my side:
- Config: a PreToolUse hook with matcher: "Agent" returning updatedInput: {"model": "opus"} (nothing else)
- Action: any Agent tool call
- Result: undefined is not an object (evaluating 'K.length') — reproducible across subagent_type values and explicit
model overrides in the call args
- Fix: remove the hook entry from settings.json
Apologies for the misdirected initial report blaming the 1M context model — the entitlement hypothesis was wrong.
Environment Info
- Platform: darwin
- Terminal: Apple_Terminal
- Version: 2.1.141
- Feedback ID: 44416cd1-9613-4dcb-98d8-e616a7d8f13d
Errors
[{"error":"ZodError\n at WO3 (/$bunfs/root/src/entrypoints/cli.js:5127:1759)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:5127:4530)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9417:37959)\n at new Promise (native:1:11)\n at A (/$bunfs/root/src/entrypoints/cli.js:9417:37851)\n at Z$6 (/$bunfs/root/src/entrypoints/cli.js:3481:3585)\n at eH3 (/$bunfs/root/src/entrypoints/cli.js:4128:4863)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-05-14T07:22:08.300Z"},{"error":"TypeError: undefined is not an object (evaluating 'K.length')\n at $T6 (/$bunfs/root/src/entrypoints/cli.js:3034:3352)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:3071:3146)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-05-14T07:22:11.058Z"},{"error":"ZodError\n at WO3 (/$bunfs/root/src/entrypoints/cli.js:5127:1759)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:5127:4530)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9417:37959)\n at new Promise (native:1:11)\n at A (/$bunfs/root/src/entrypoints/cli.js:9417:37851)\n at Z$6 (/$bunfs/root/src/entrypoints/cli.js:3481:3585)\n at eH3 (/$bunfs/root/src/entrypoints/cli.js:4128:4863)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-05-14T07:22:16.098Z"},{"error":"TypeError: undefined is not an object (evaluating 'K.length')\n at $T6 (/$bunfs/root/src/entrypoints/cli.js:3034:3352)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:3071:3146)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-05-14T07:22:18.872Z"},{"error":"ZodError\n at WO3 (/$bunfs/root/src/entrypoints/cli.js:5127:1759)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:5127:4530)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli.js:9417:37959)\n at new Promise (native:1:11)\n at A (/$bunfs/root/src/entrypoints/cli.js:9417:37851)\n at Z$6 (/$bunfs/root/src/entrypoints/cli.js:3481:3585)\n at eH3 (/$bunfs/root/src/entrypoints/cli.js:4128:4863)\n at processTicksAndRejections (native:7:39)","timestamp":"2026-05-14T07:22:24.332Z"},{"error":"TypeError: undefined is not an object (evaluating 'K.length')\n at $T6 (/$bunfs/root/src/entrypoints/cli.js:3034:3352)\n at <anonymous> (/$bunfs/root/src/entrypoints/cli…
Note: Content was truncated.
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗