Agent tool: K.length crash on spawn at any context size
Description
The Agent tool crashes with undefined is not an object (evaluating 'K.length') during agent initialization. This is a JavaScript error in the CLI, not related to context window limits.
Reproduction
The crash occurs:
- At any transcript size (observed at 13KB through 2.3MB)
- On the first agent spawn in a fresh session (after
/clear) - More frequently after prior hook denials (PreToolUse deny → retry → crash)
Evidence
Analyzed 72 sessions across 2 projects with agent spawns:
| Transcript size | Sessions | Crashed | Rate |
|----------------|----------|---------|------|
| 100-500KB | 13 | 4 | 31% |
| 500KB-1MB | 21 | 2 | 10% |
| >1MB | 38 | 18 | 47% |
Key observations:
- The safest zone is 500KB-1MB (10% crash rate)
- Crashes happen at 13KB transcript (session
2fe1a50e) — first agent spawn after/clear - Sessions with prior hook denials (Agent PreToolUse → deny) show higher crash rates
- Once a K.length crash occurs, all subsequent Agent spawns in the same session crash
Workaround
Adding a systemMessage on hook denials saying "Do NOT retry Agent — execute directly via Bash" reduces crash frequency by preventing the retry loop.
Environment
- Claude Code CLI (latest)
- Linux (Kali 6.18.12+)
- Multiple agent types affected (linux-admin, Explore, backend-dev, etc.)
- Both
bypassPermissionsanddefaultpermission modes
Error
Error: undefined is not an object (evaluating 'K.length')
This appears to be an unhandled undefined in the agent initialization JavaScript code path, possibly related to message array handling or context construction.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗