[BUG] Agent tool spawn crashes with K.length on first invocation in v2.1.136
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code (2.1.136)
Note on the first checkbox: issue #43983 reported the sameK.lengthsymptom but was auto-closed as a duplicate of #30620 (which is a distinctT.input_tokenscrash on parallel spawn) and is now locked. The lock-bot's own closing message directs anyone seeing the same symptom to file a new issue and reference the locked one.
What's Wrong?
The Agent tool crashes during initialization with undefined is not an object (evaluating 'K.length') when spawned with subagent_type="Explore". The crash happens before the agent starts: there is no agent_start event in telemetry, no model invocation, and no output returned to the orchestrator.
Because the spawned subprocess receives the parent context before the crash, some input tokens are likely consumed even though no output is produced. The orchestrator surface is a single tool-error string; the user-visible artifact in telemetry is an "orphaned-tool-start" entry — initial context dispatched, no agent_start, no result.
In a single session, three consecutive Agent(subagent_type="Explore", ...) calls failed identically — including a deliberately minimal third call (a 50-word prompt asking the agent to read one file and report its line count). A fourth call in the same session, this time with subagent_type set to a custom plugin agent, succeeded immediately with the same surrounding context. This rules out general session corruption and points specifically at the shipped Explore agent's initialization path.
The reported behavior closely resembles #43983 (auto-closed as a duplicate of #30620, but mistakenly — the two issues describe distinct variables and distinct code paths, see Additional Information below). #43983's reporter saw the same K.length string with a different trigger profile. We see it on minimal prompts in v2.1.136, several months after #30620 was completed.
What Should Happen?
Agent(subagent_type="Explore", prompt="<any prompt>") should either:
- Succeed and return the agent's result, or
- Fail with a clear, actionable error returned through the normal tool-error channel — not by triggering an unhandled exception in the bundled CLI.
Specifically, an array-access on undefined (the apparent root cause of the K.length error) should be guarded against during agent initialization, and the failure should surface as a structured error so the orchestrator can decide whether to retry, switch to a different agent type, or escalate to the user. A silent JS crash with no recoverable error message is the worst variant of this failure family.
Error Messages/Logs
undefined is not an object (evaluating 'K.length')
This is the entire string returned to the orchestrator from the failed Agent tool call. No stack trace is surfaced to the model context. The error appears to originate from the bundled JavaScript CLI's agent-initialization code path — the same area implicated in #43983.
Steps to Reproduce
- Run
claude(v2.1.136) in a working directory where many plugins are loaded — i.e., a session with several skills, custom agents, MCP servers, and rules registered. This matches the trigger profile reported across #38868 / #43983 / #38928 / #45299 / #45999. - Issue an
Agenttool call withsubagent_type="Explore"and any prompt — including a deliberately minimal one such as:
````
Find the file <path>. Report its line count and the first three lines. That's all — under 50 words.
- The tool returns the error string above. There is no
agent_startevent in telemetry, and no output is returned. - Repeating the call with a different (shorter) prompt reproduces the same error string identically.
- Switching
subagent_typeto a custom plugin agent (loaded via the same plugin mechanism) succeeds immediately with the same surrounding context — confirming the failure is specific to the shippedExploreagent's initialization path, not to the session as a whole.
The failure was reproduced 3 of 3 times in our session, including with the minimal prompt above — i.e., it is not prompt-size dependent in our environment. The trigger appears to be the combination of the shipped Explore agent type and a session that has many plugin-provided skills, agents, and MCP servers loaded.
Claude Model
Opus
Is this a regression?
Yes, this worked in a previous version
The duplicate-resolution chain (#43983 → #30620, closed-COMPLETED 2026-03-05) implies the maintainers believed the K.length crash was fixed by the work that closed #30620. Reproduction in 2.1.136 (May 2026) is consistent with one of two readings: (a) a regression after the #30620 fix landed, or (b) #43983 was incorrectly closed as a duplicate, since #30620 was a T.input_tokens crash on parallel spawn — a distinct code path. We don't have enough information to distinguish the two readings.
Last Working Version
(Not on hand — happy to bisect against published 2.x tags if maintainers can suggest a starting point.)
Claude Code Version
2.1.136 (Claude Code)
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Other (terminal not recorded at submission time)
Additional Information
Related issues
- #43983 — "Agent tool: K.length crash on spawn at any context size" — same symptom and verbatim error string, reported 2026-04-05. Auto-closed as a duplicate of #30620 by
github-actions[bot]on 2026-04-09; subsequently auto-locked. The auto-close was algorithmic — the bot pattern-matched on the outer error shape (undefined is not an object (...)) — and the original reporter had no opportunity to dispute the verdict. The lock-bot's closing message says, verbatim: "please file a new issue and reference this one if it's relevant."
- #30620 — "Crash with
T.input_tokenswhen spawning parallel sub-agents via Agent tool" — closed-COMPLETED 2026-03-05. Same outer error shape but a different variable (T.input_tokensvsK.length), a different trigger (parallel spawn vs first spawn), and almost certainly a different code path. Our 2.1.136 reproduction strongly suggests the #30620 fix did not address theK.lengthvariant.
- #38868 — "Explore agent fails silently with context window overflow from multiple plugins/skills" — closed 2026-03-25 on 2.1.83. Same root-cause family (Explore subagent initialization fails in many-plugin sessions) but a different failure surface: #38868's reporter saw a
Prompt is too longerror or AxiosError timeouts. The bug reported here surfaces as a hard JavaScript crash with no recoverable error — strictly worse for the orchestrator, since there is no actionable signal to drive a fallback.
Environment context
The session has a custom plugin loaded with several dozen skills, around twenty custom agents, and roughly thirty rules registered. This matches the "many plugins / skills / MCPs" trigger profile reported across #38868, #43983, #38928, #45299, and #45999. Custom plugin agents loaded via the same plugin mechanism work correctly — the failure is specific to the shipped Explore agent type's initialization path.
A documented local workaround is in place: prefer a custom plugin's research-style agent for substantive code-survey work, and avoid invoking the shipped Explore agent in many-plugin sessions.
Offer
If maintainers can share guidance on which 2.x versions did or did not exhibit the K.length crash, we are happy to bisect against published tags to narrow the regression window and provide reproduction transcripts.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗